restic: change ListBlobs to return PackBlob

PackBlob is a limited interface that only exposes a part of the
information provided by PackedBlob. Most of the changes are switches
from direct value lookups to the interface methods, with a few larger
changes to let the tests still work.
This commit is contained in:
Michael Eischer
2026-06-05 11:21:02 +02:00
parent 784b52bdea
commit 10fc70668c
15 changed files with 102 additions and 73 deletions
+6 -5
View File
@@ -525,22 +525,23 @@ func (f *Finder) indexPacksToBlobs(ctx context.Context, packIDs map[string]struc
// remember which packs were found in the index
indexPackIDs := make(map[string]struct{})
err := f.repo.ListBlobs(wctx, func(pb restic.PackedBlob) {
idStr := pb.PackID.String()
err := f.repo.ListBlobs(wctx, func(pb restic.PackBlob) {
packID := pb.PackID()
idStr := packID.String()
// keep entry in packIDs as Each() returns individual index entries
matchingID := false
if _, ok := packIDs[idStr]; ok {
matchingID = true
} else {
if _, ok := packIDs[pb.PackID.Str()]; ok {
if _, ok := packIDs[packID.Str()]; ok {
// expand id
delete(packIDs, pb.PackID.Str())
delete(packIDs, packID.Str())
packIDs[idStr] = struct{}{}
matchingID = true
}
}
if matchingID {
f.blobIDs[pb.ID.String()] = struct{}{}
f.blobIDs[pb.Handle().ID.String()] = struct{}{}
indexPackIDs[idStr] = struct{}{}
}
})
+8 -7
View File
@@ -179,9 +179,10 @@ func TestFindPackfile(t *testing.T) {
packID := restic.ID{}
done := false
err = repo.ListBlobs(ctx, func(pb restic.PackedBlob) {
if !done && pb.Type == restic.TreeBlob {
packID = pb.PackID
err = repo.ListBlobs(ctx, func(pb restic.PackBlob) {
h := pb.Handle()
if !done && h.Type == restic.TreeBlob {
packID = pb.PackID()
done = true
}
})
@@ -236,12 +237,12 @@ func TestFindPackID(t *testing.T) {
// load Index
rtest.OK(t, repo.LoadIndex(ctx, nil))
// go through all index entries and collect data and tree packfile(s)
rtest.OK(t, repo.ListBlobs(ctx, func(blob restic.PackedBlob) {
switch blob.Type {
rtest.OK(t, repo.ListBlobs(ctx, func(blob restic.PackBlob) {
switch blob.Handle().Type {
case restic.DataBlob:
dataPackID = blob.PackID
dataPackID = blob.PackID()
case restic.TreeBlob:
treePackID = blob.PackID
treePackID = blob.PackID()
}
}))
return nil
+2 -2
View File
@@ -71,8 +71,8 @@ func testListBlobs(t testing.TB, gopts global.Options) (blobSetFromIndex restic.
// get blobs from index
blobSetFromIndex = restic.NewIDSet()
rtest.OK(t, repo.ListBlobs(ctx, func(blob restic.PackedBlob) {
blobSetFromIndex.Insert(blob.ID)
rtest.OK(t, repo.ListBlobs(ctx, func(blob restic.PackBlob) {
blobSetFromIndex.Insert(blob.Handle().ID)
}))
return nil
})
+4 -3
View File
@@ -75,9 +75,10 @@ func runRecover(ctx context.Context, gopts global.Options, term ui.Terminal) err
// tree. If it is not referenced, we have a root tree.
trees := make(map[restic.ID]bool)
err = repo.ListBlobs(ctx, func(blob restic.PackedBlob) {
if blob.Type == restic.TreeBlob {
trees[blob.Blob.ID] = false
err = repo.ListBlobs(ctx, func(blob restic.PackBlob) {
h := blob.Handle()
if h.Type == restic.TreeBlob {
trees[h.ID] = false
}
})
if err != nil {
+2 -2
View File
@@ -483,8 +483,8 @@ func statsDebugBlobs(ctx context.Context, repo restic.Repository) ([restic.NumBl
hist[i] = newSizeHistogram(2 * chunker.MaxSize)
}
err := repo.ListBlobs(ctx, func(pb restic.PackedBlob) {
hist[pb.Type].Add(uint64(pb.Length))
err := repo.ListBlobs(ctx, func(pb restic.PackBlob) {
hist[pb.Handle().Type].Add(uint64(pb.CiphertextLength()))
})
return hist, err
+6 -6
View File
@@ -270,9 +270,9 @@ func listTreePacks(gopts global.Options, t *testing.T) restic.IDSet {
rtest.OK(t, r.LoadIndex(ctx, nil))
treePacks = restic.NewIDSet()
return r.ListBlobs(ctx, func(pb restic.PackedBlob) {
if pb.Type == restic.TreeBlob {
treePacks.Insert(pb.PackID)
return r.ListBlobs(ctx, func(pb restic.PackBlob) {
if pb.Handle().Type == restic.TreeBlob {
treePacks.Insert(pb.PackID())
}
})
})
@@ -319,9 +319,9 @@ func removePacksExcept(gopts global.Options, t testing.TB, keep restic.IDSet, re
rtest.OK(t, r.LoadIndex(ctx, nil))
treePacks := restic.NewIDSet()
rtest.OK(t, r.ListBlobs(ctx, func(pb restic.PackedBlob) {
if pb.Type == restic.TreeBlob {
treePacks.Insert(pb.PackID)
rtest.OK(t, r.ListBlobs(ctx, func(pb restic.PackBlob) {
if pb.Handle().Type == restic.TreeBlob {
treePacks.Insert(pb.PackID())
}
}))