From a1ca5e15c4056d43e1e8ef4ddecf427dcee63115 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 10 May 2024 15:55:45 +0200 Subject: [PATCH] migrations: add temporary hack for s3_layout The migration will be removed after the next restic release anyways. Thus, there's no need for a clean implementation. --- internal/checker/checker.go | 6 ++++-- internal/migrations/s3_layout.go | 5 +++-- internal/repository/s3_backend.go | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 internal/repository/s3_backend.go diff --git a/internal/checker/checker.go b/internal/checker/checker.go index d6474f86e..f19439622 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -256,8 +256,10 @@ func isS3Legacy(b backend.Backend) bool { func (c *Checker) Packs(ctx context.Context, errChan chan<- error) { defer close(errChan) - if isS3Legacy(c.repo.Backend()) { - errChan <- ErrLegacyLayout + if r, ok := c.repo.(*repository.Repository); ok { + if isS3Legacy(repository.AsS3Backend(r)) { + errChan <- ErrLegacyLayout + } } debug.Log("checking for %d packs", len(c.packs)) diff --git a/internal/migrations/s3_layout.go b/internal/migrations/s3_layout.go index 6b40013ee..8b994b8fc 100644 --- a/internal/migrations/s3_layout.go +++ b/internal/migrations/s3_layout.go @@ -11,6 +11,7 @@ import ( "github.com/restic/restic/internal/backend/s3" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" ) @@ -24,7 +25,7 @@ type S3Layout struct{} // Check tests whether the migration can be applied. func (m *S3Layout) Check(_ context.Context, repo restic.Repository) (bool, string, error) { - be := backend.AsBackend[*s3.Backend](repo.Backend()) + be := repository.AsS3Backend(repo.(*repository.Repository)) if be == nil { debug.Log("backend is not s3") return false, "backend is not s3", nil @@ -76,7 +77,7 @@ func (m *S3Layout) moveFiles(ctx context.Context, be *s3.Backend, l layout.Layou // Apply runs the migration. func (m *S3Layout) Apply(ctx context.Context, repo restic.Repository) error { - be := backend.AsBackend[*s3.Backend](repo.Backend()) + be := repository.AsS3Backend(repo.(*repository.Repository)) if be == nil { debug.Log("backend is not s3") return errors.New("backend is not s3") diff --git a/internal/repository/s3_backend.go b/internal/repository/s3_backend.go new file mode 100644 index 000000000..4c77c69a2 --- /dev/null +++ b/internal/repository/s3_backend.go @@ -0,0 +1,12 @@ +package repository + +import ( + "github.com/restic/restic/internal/backend" + "github.com/restic/restic/internal/backend/s3" +) + +// AsS3Backend extracts the S3 backend from a repository +// TODO remove me once restic 0.17 was released +func AsS3Backend(repo *Repository) *s3.Backend { + return backend.AsBackend[*s3.Backend](repo.be) +}