From fcb3ddf181b684142fd43a67e2b35c38056d2f33 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 10 Apr 2022 14:11:48 +0200 Subject: [PATCH] check: Complain about usage of s3 legacy layout --- cmd/restic/cmd_check.go | 8 +++++--- internal/checker/checker.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 093a1ac99..e32a4a4d0 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -260,10 +260,12 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error { if checker.IsOrphanedPack(err) { orphanedPacks++ Verbosef("%v\n", err) - continue + } else if _, ok := err.(*checker.ErrLegacyLayout); ok { + Verbosef("repository still uses the S3 legacy layout\nPlease run `restic migrate s3legacy` to correct this.\n") + } else { + errorsFound = true + Warnf("%v\n", err) } - errorsFound = true - Warnf("error: %v\n", err) } if orphanedPacks > 0 { diff --git a/internal/checker/checker.go b/internal/checker/checker.go index e479f0aff..0c4d84f94 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -13,6 +13,7 @@ import ( "github.com/minio/sha256-simd" "github.com/restic/restic/internal/backend" + "github.com/restic/restic/internal/backend/s3" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/hashing" @@ -56,6 +57,13 @@ func New(repo restic.Repository, trackUnused bool) *Checker { return c } +// ErrLegacyLayout is returned when the repository uses the S3 legacy layout. +type ErrLegacyLayout struct{} + +func (e *ErrLegacyLayout) Error() string { + return "repository uses S3 legacy layout" +} + // ErrDuplicatePacks is returned when a pack is found in more than one index. type ErrDuplicatePacks struct { PackID restic.ID @@ -184,12 +192,25 @@ func IsOrphanedPack(err error) bool { return errors.As(err, &e) && e.Orphaned } +func isS3Legacy(b restic.Backend) bool { + be, ok := b.(*s3.Backend) + if !ok { + return false + } + + return be.Layout.Name() == "s3legacy" +} + // Packs checks that all packs referenced in the index are still available and // there are no packs that aren't in an index. errChan is closed after all // packs have been checked. func (c *Checker) Packs(ctx context.Context, errChan chan<- error) { defer close(errChan) + if isS3Legacy(c.repo.Backend()) { + errChan <- &ErrLegacyLayout{} + } + debug.Log("checking for %d packs", len(c.packs)) debug.Log("listing repository packs")