From 307aeb6849a79748349a661f3318b9907506623d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jul 2023 22:42:39 +0200 Subject: [PATCH 1/3] rest: Don't return error if listing non-existent directory When transferring a repository from S3 to, for example, a local disk then all empty folders will be missing. When saving files, the missing intermediate folders are created automatically. Therefore, missing directories can be ignored by the `List()` operation. --- internal/backend/rest/rest.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 8391df681..378d12c9d 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -327,6 +327,11 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi return errors.Wrap(err, "List") } + if resp.StatusCode == http.StatusNotFound { + // ignore missing directories + return nil + } + if resp.StatusCode != 200 { return errors.Errorf("List failed, server response: %v (%v)", resp.Status, resp.StatusCode) } From 978ebaac498ae6f1abf396f1d234d7ce95d3b66b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jul 2023 22:45:53 +0200 Subject: [PATCH 2/3] rest: use http status code constants --- internal/backend/rest/rest.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 378d12c9d..f8670280d 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -147,7 +147,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea return errors.WithStack(err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return errors.Errorf("server response unexpected: %v (%v)", resp.Status, resp.StatusCode) } @@ -229,7 +229,7 @@ func (b *Backend) openReader(ctx context.Context, h restic.Handle, length int, o return nil, ¬ExistError{h} } - if resp.StatusCode != 200 && resp.StatusCode != 206 { + if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent { _ = resp.Body.Close() return nil, errors.Errorf("unexpected HTTP response (%v): %v", resp.StatusCode, resp.Status) } @@ -260,7 +260,7 @@ func (b *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, e return restic.FileInfo{}, ¬ExistError{h} } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return restic.FileInfo{}, errors.Errorf("unexpected HTTP response (%v): %v", resp.StatusCode, resp.Status) } @@ -295,7 +295,7 @@ func (b *Backend) Remove(ctx context.Context, h restic.Handle) error { return ¬ExistError{h} } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return errors.Errorf("blob not removed, server response: %v (%v)", resp.Status, resp.StatusCode) } @@ -332,7 +332,7 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi return nil } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return errors.Errorf("List failed, server response: %v (%v)", resp.Status, resp.StatusCode) } From 5705326bb8df5f0e167b77d7a6a0704e13800692 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jul 2023 22:54:31 +0200 Subject: [PATCH 3/3] add changelog --- changelog/unreleased/pull-4400 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/pull-4400 diff --git a/changelog/unreleased/pull-4400 b/changelog/unreleased/pull-4400 new file mode 100644 index 000000000..a9aaf6284 --- /dev/null +++ b/changelog/unreleased/pull-4400 @@ -0,0 +1,8 @@ +Bugfix: Ignore missing folders in REST backend + +If a repository accessed via the REST backend was missing folders, then restic +would fail with an error while trying to list the data in the repository. This +has been fixed. + +https://github.com/restic/restic/pull/4400 +https://github.com/restic/rest-server/issues/235