Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

http: fix backend with --files-from and non-existent files

Nick Craig-Woodfc654a4ceca6
diff --git a/backend/http/http.go b/backend/http/http.go
index cb28f25b9..743219b40 100644
--- a/backend/http/http.go
+++ b/backend/http/http.go
@@ -193,7 +193,7 @@ func (f *Fs) NewObject(remote string) (fs.Object, error) {
}
err := o.stat()
if err != nil {
- return nil, errors.Wrap(err, "Stat failed")
+ return nil, err
}
return o, nil
}
@@ -416,6 +416,9 @@ func (o *Object) url() string {
func (o *Object) stat() error {
url := o.url()
res, err := o.fs.httpClient.Head(url)
+ if err == nil && res.StatusCode == http.StatusNotFound {
+ return fs.ErrorObjectNotFound
+ }
err = statusError(res, err)
if err != nil {
return errors.Wrap(err, "failed to stat")
diff --git a/backend/http/http_internal_test.go b/backend/http/http_internal_test.go
index bb062ca78..4c1436895 100644
--- a/backend/http/http_internal_test.go
+++ b/backend/http/http_internal_test.go
@@ -144,6 +144,11 @@ func TestNewObject(t *testing.T) {
dt, ok := fstest.CheckTimeEqualWithPrecision(tObj, tFile, time.Second)
assert.True(t, ok, fmt.Sprintf("%s: Modification time difference too big |%s| > %s (%s vs %s) (precision %s)", o.Remote(), dt, time.Second, tObj, tFile, time.Second))
+
+ // check object not found
+ o, err = f.NewObject("not found.txt")
+ assert.Nil(t, o)
+ assert.Equal(t, fs.ErrorObjectNotFound, err)
}
func TestOpen(t *testing.T) {