diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 3b26b1f90..9abdaeec2 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -787,6 +787,22 @@ func (r *Repository) createIndexFromPacks(ctx context.Context, packsize map[rest return invalid, nil } +func (r *Repository) NewAssociatedBlobSet() restic.AssociatedBlobSet { + return &associatedBlobSet{*index.NewAssociatedSet[struct{}](r.idx)} +} + +// associatedBlobSet is a wrapper around index.AssociatedSet to implement the restic.AssociatedBlobSet interface. +type associatedBlobSet struct { + index.AssociatedSet[struct{}] +} + +func (s *associatedBlobSet) Intersect(other restic.AssociatedBlobSet) restic.AssociatedBlobSet { + return &associatedBlobSet{*s.AssociatedSet.Intersect(other)} +} +func (s *associatedBlobSet) Sub(other restic.AssociatedBlobSet) restic.AssociatedBlobSet { + return &associatedBlobSet{*s.AssociatedSet.Sub(other)} +} + // prepareCache initializes the local cache. indexIDs is the list of IDs of // index files still present in the repo. func (r *Repository) prepareCache() error { diff --git a/internal/restic/repository.go b/internal/restic/repository.go index 2f1373641..ed0c64cf0 100644 --- a/internal/restic/repository.go +++ b/internal/restic/repository.go @@ -2,6 +2,7 @@ package restic import ( "context" + "iter" "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/crypto" @@ -26,6 +27,7 @@ type Repository interface { LookupBlob(t BlobType, id ID) []PackedBlob LookupBlobSize(t BlobType, id ID) (size uint, exists bool) + NewAssociatedBlobSet() AssociatedBlobSet // ListBlobs runs fn on all blobs known to the index. When the context is cancelled, // the index iteration returns immediately with ctx.Err(). This blocks any modification of the index. ListBlobs(ctx context.Context, fn func(PackedBlob)) error @@ -186,3 +188,13 @@ type FindBlobSet interface { Has(bh BlobHandle) bool Insert(bh BlobHandle) } + +type AssociatedBlobSet interface { + Has(bh BlobHandle) bool + Insert(bh BlobHandle) + Delete(bh BlobHandle) + Len() int + Keys() iter.Seq[BlobHandle] + Intersect(other AssociatedBlobSet) AssociatedBlobSet + Sub(other AssociatedBlobSet) AssociatedBlobSet +}