From 5a6f2f9fa059fea1b7de697f2dcb88781d80f23e Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 1 May 2022 14:52:00 +0200 Subject: [PATCH] Fix S3 legacy layout migration --- internal/migrations/s3_layout.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/migrations/s3_layout.go b/internal/migrations/s3_layout.go index 0cfd40e60..afb14b848 100644 --- a/internal/migrations/s3_layout.go +++ b/internal/migrations/s3_layout.go @@ -8,6 +8,7 @@ import ( "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/backend/s3" + "github.com/restic/restic/internal/cache" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" @@ -21,10 +22,25 @@ func init() { // "default" layout. type S3Layout struct{} +func toS3Backend(repo restic.Repository) *s3.Backend { + b := repo.Backend() + // unwrap cache + if be, ok := b.(*cache.Backend); ok { + b = be.Backend + } + + be, ok := b.(*s3.Backend) + if !ok { + debug.Log("backend is not s3") + return nil + } + return be +} + // Check tests whether the migration can be applied. func (m *S3Layout) Check(ctx context.Context, repo restic.Repository) (bool, error) { - be, ok := repo.Backend().(*s3.Backend) - if !ok { + be := toS3Backend(repo) + if be == nil { debug.Log("backend is not s3") return false, nil } @@ -75,8 +91,8 @@ func (m *S3Layout) moveFiles(ctx context.Context, be *s3.Backend, l backend.Layo // Apply runs the migration. func (m *S3Layout) Apply(ctx context.Context, repo restic.Repository) error { - be, ok := repo.Backend().(*s3.Backend) - if !ok { + be := toS3Backend(repo) + if be == nil { debug.Log("backend is not s3") return errors.New("backend is not s3") }