From 864995271ec7413594ce8a186385b6b61cdb310d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 19 May 2024 14:56:17 +0200 Subject: [PATCH] repository: unwrap BlobHandle parameters of LookupBlob The method now uses the same parameters as LookupBlobSize. --- cmd/restic/cmd_copy.go | 2 +- cmd/restic/cmd_find.go | 2 +- cmd/restic/cmd_stats.go | 2 +- internal/repository/check.go | 2 +- internal/repository/repack_test.go | 6 +++--- internal/repository/repository.go | 4 ++-- internal/repository/repository_test.go | 4 ++-- internal/restic/repository.go | 2 +- internal/restorer/filerestorer.go | 8 ++++---- internal/restorer/filerestorer_test.go | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 4b2f95bf2..d12501dd9 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -187,7 +187,7 @@ func copyTree(ctx context.Context, srcRepo restic.Repository, dstRepo restic.Rep packList := restic.NewIDSet() enqueue := func(h restic.BlobHandle) { - pb := srcRepo.LookupBlob(h) + pb := srcRepo.LookupBlob(h.Type, h.ID) copyBlobs.Insert(h) for _, p := range pb { packList.Insert(p.PackID) diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index 7ad8886c8..59e34c468 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -509,7 +509,7 @@ func (f *Finder) findObjectPack(id string, t restic.BlobType) { return } - blobs := f.repo.LookupBlob(restic.BlobHandle{ID: rid, Type: t}) + blobs := f.repo.LookupBlob(t, rid) if len(blobs) == 0 { Printf("Object %s not found in the index\n", rid.Str()) return diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index 0926a54ef..0f8e45f36 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -124,7 +124,7 @@ func runStats(ctx context.Context, opts StatsOptions, gopts GlobalOptions, args if opts.countMode == countModeRawData { // the blob handles have been collected, but not yet counted for blobHandle := range stats.blobs { - pbs := repo.LookupBlob(blobHandle) + pbs := repo.LookupBlob(blobHandle.Type, blobHandle.ID) if len(pbs) == 0 { return fmt.Errorf("blob %v not found", blobHandle) } diff --git a/internal/repository/check.go b/internal/repository/check.go index 05605db86..f16cd7492 100644 --- a/internal/repository/check.go +++ b/internal/repository/check.go @@ -161,7 +161,7 @@ func checkPackInner(ctx context.Context, r *Repository, id restic.ID, blobs []re for _, blob := range blobs { // Check if blob is contained in index and position is correct idxHas := false - for _, pb := range r.LookupBlob(blob.BlobHandle) { + for _, pb := range r.LookupBlob(blob.BlobHandle.Type, blob.BlobHandle.ID) { if pb.PackID == id && pb.Blob == blob { idxHas = true break diff --git a/internal/repository/repack_test.go b/internal/repository/repack_test.go index 524ab6485..96b75ca46 100644 --- a/internal/repository/repack_test.go +++ b/internal/repository/repack_test.go @@ -146,7 +146,7 @@ func findPacksForBlobs(t *testing.T, repo restic.Repository, blobs restic.BlobSe packs := restic.NewIDSet() for h := range blobs { - list := repo.LookupBlob(h) + list := repo.LookupBlob(h.Type, h.ID) if len(list) == 0 { t.Fatal("Failed to find blob", h.ID.Str(), "with type", h.Type) } @@ -247,7 +247,7 @@ func testRepack(t *testing.T, version uint) { } for h := range keepBlobs { - list := repo.LookupBlob(h) + list := repo.LookupBlob(h.Type, h.ID) if len(list) == 0 { t.Errorf("unable to find blob %v in repo", h.ID.Str()) continue @@ -311,7 +311,7 @@ func testRepackCopy(t *testing.T, version uint) { reloadIndex(t, dstRepo) for h := range keepBlobs { - list := dstRepo.LookupBlob(h) + list := dstRepo.LookupBlob(h.Type, h.ID) if len(list) == 0 { t.Errorf("unable to find blob %v in repo", h.ID.Str()) continue diff --git a/internal/repository/repository.go b/internal/repository/repository.go index d68ed8837..73d05fe7b 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -578,8 +578,8 @@ func (r *Repository) Connections() uint { return r.be.Connections() } -func (r *Repository) LookupBlob(bh restic.BlobHandle) []restic.PackedBlob { - return r.idx.Lookup(bh) +func (r *Repository) LookupBlob(tpe restic.BlobType, id restic.ID) []restic.PackedBlob { + return r.idx.Lookup(restic.BlobHandle{Type: tpe, ID: id}) } // LookupBlobSize returns the size of blob id. diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 31a588f62..bc950d0b0 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -161,7 +161,7 @@ func TestLoadBlobBroken(t *testing.T) { data, err := repo.LoadBlob(context.TODO(), restic.TreeBlob, id, nil) rtest.OK(t, err) rtest.Assert(t, bytes.Equal(buf, data), "data mismatch") - pack := repo.LookupBlob(restic.BlobHandle{Type: restic.TreeBlob, ID: id})[0].PackID + pack := repo.LookupBlob(restic.TreeBlob, id)[0].PackID rtest.Assert(t, c.Has(backend.Handle{Type: restic.PackFile, Name: pack.String()}), "expected tree pack to be cached") } @@ -439,7 +439,7 @@ func TestListPack(t *testing.T) { repo.UseCache(c) // Forcibly cache pack file - packID := repo.LookupBlob(restic.BlobHandle{Type: restic.TreeBlob, ID: id})[0].PackID + packID := repo.LookupBlob(restic.TreeBlob, id)[0].PackID rtest.OK(t, be.Load(context.TODO(), backend.Handle{Type: restic.PackFile, IsMetadata: true, Name: packID.String()}, 0, 0, func(rd io.Reader) error { return nil })) // Get size to list pack diff --git a/internal/restic/repository.go b/internal/restic/repository.go index 3d5bccec0..9e6d6b99b 100644 --- a/internal/restic/repository.go +++ b/internal/restic/repository.go @@ -25,7 +25,7 @@ type Repository interface { SetIndex(mi MasterIndex) error SaveIndex(ctx context.Context, excludePacks IDSet, extraObsolete IDs, opts MasterIndexSaveOpts) error - LookupBlob(bh BlobHandle) []PackedBlob + LookupBlob(t BlobType, id ID) []PackedBlob LookupBlobSize(t BlobType, id ID) (size uint, exists bool) // ListBlobs runs fn on all blobs known to the index. When the context is cancelled, diff --git a/internal/restorer/filerestorer.go b/internal/restorer/filerestorer.go index f2c134ea9..3551857dd 100644 --- a/internal/restorer/filerestorer.go +++ b/internal/restorer/filerestorer.go @@ -48,7 +48,7 @@ type blobsLoaderFn func(ctx context.Context, packID restic.ID, blobs []restic.Bl // fileRestorer restores set of files type fileRestorer struct { - idx func(restic.BlobHandle) []restic.PackedBlob + idx func(restic.BlobType, restic.ID) []restic.PackedBlob blobsLoader blobsLoaderFn workerCount int @@ -64,7 +64,7 @@ type fileRestorer struct { func newFileRestorer(dst string, blobsLoader blobsLoaderFn, - idx func(restic.BlobHandle) []restic.PackedBlob, + idx func(restic.BlobType, restic.ID) []restic.PackedBlob, connections uint, sparse bool, progress *restore.Progress) *fileRestorer { @@ -99,7 +99,7 @@ func (r *fileRestorer) forEachBlob(blobIDs []restic.ID, fn func(packID restic.ID } for _, blobID := range blobIDs { - packs := r.idx(restic.BlobHandle{ID: blobID, Type: restic.DataBlob}) + packs := r.idx(restic.DataBlob, blobID) if len(packs) == 0 { return errors.Errorf("Unknown blob %s", blobID.String()) } @@ -227,7 +227,7 @@ func (r *fileRestorer) downloadPack(ctx context.Context, pack *packInfo) error { } } else if packsMap, ok := file.blobs.(map[restic.ID][]fileBlobInfo); ok { for _, blob := range packsMap[pack.id] { - idxPacks := r.idx(restic.BlobHandle{ID: blob.id, Type: restic.DataBlob}) + idxPacks := r.idx(restic.DataBlob, blob.id) for _, idxPack := range idxPacks { if idxPack.PackID.Equal(pack.id) { addBlob(idxPack.Blob, blob.offset) diff --git a/internal/restorer/filerestorer_test.go b/internal/restorer/filerestorer_test.go index befeb5d2c..03797e0c8 100644 --- a/internal/restorer/filerestorer_test.go +++ b/internal/restorer/filerestorer_test.go @@ -35,8 +35,8 @@ type TestRepo struct { loader blobsLoaderFn } -func (i *TestRepo) Lookup(bh restic.BlobHandle) []restic.PackedBlob { - packs := i.blobs[bh.ID] +func (i *TestRepo) Lookup(tpe restic.BlobType, id restic.ID) []restic.PackedBlob { + packs := i.blobs[id] return packs }