diff --git a/internal/index/index.go b/internal/index/index.go index 6c6294b21..75a6a53fc 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -312,36 +312,6 @@ func (idx *Index) PacksForBlobs(blobs restic.BlobSet) (packs restic.IDSet) { return packs } -// Location describes the location of a blob in a pack. -type Location struct { - PackID restic.ID - restic.Blob -} - -// ErrBlobNotFound is return by FindBlob when the blob could not be found in -// the index. -var ErrBlobNotFound = errors.New("blob not found in index") - -// FindBlob returns a list of packs and positions the blob can be found in. -func (idx *Index) FindBlob(h restic.BlobHandle) (result []Location, err error) { - for id, p := range idx.Packs { - for _, entry := range p.Entries { - if entry.ID.Equal(h.ID) && entry.Type == h.Type { - result = append(result, Location{ - PackID: id, - Blob: entry, - }) - } - } - } - - if len(result) == 0 { - return nil, ErrBlobNotFound - } - - return result, nil -} - const maxEntries = 3000 // Saver saves structures as JSON. diff --git a/internal/index/index_test.go b/internal/index/index_test.go index 43198cf68..ca9a9f899 100644 --- a/internal/index/index_test.go +++ b/internal/index/index_test.go @@ -363,6 +363,28 @@ func TestIndexSave(t *testing.T) { } } +// Location describes the location of a blob in a pack. +type location struct { + PackID restic.ID + restic.Blob +} + +// FindBlob returns a list of packs and positions the blob can be found in. +func (idx *Index) findBlob(h restic.BlobHandle) (result []location) { + for id, p := range idx.Packs { + for _, entry := range p.Entries { + if entry.ID.Equal(h.ID) && entry.Type == h.Type { + result = append(result, location{ + PackID: id, + Blob: entry, + }) + } + } + } + + return result +} + func TestIndexAddRemovePack(t *testing.T) { repo, cleanup := createFilledRepo(t, 3, 0) defer cleanup() @@ -393,8 +415,8 @@ func TestIndexAddRemovePack(t *testing.T) { for _, blob := range blobs { h := restic.BlobHandle{ID: blob.ID, Type: blob.Type} - _, err := idx.FindBlob(h) - if err == nil { + locs := idx.findBlob(h) + if len(locs) != 0 { t.Errorf("removed blob %v found in index", h) } } @@ -447,9 +469,9 @@ func TestIndexLoadDocReference(t *testing.T) { idx := loadIndex(t, repo) blobID := restic.TestParseID("d3dc577b4ffd38cc4b32122cabf8655a0223ed22edfd93b353dc0c3f2b0fdf66") - locs, err := idx.FindBlob(restic.BlobHandle{ID: blobID, Type: restic.DataBlob}) - if err != nil { - t.Errorf("FindBlob() returned error %v", err) + locs := idx.findBlob(restic.BlobHandle{ID: blobID, Type: restic.DataBlob}) + if len(locs) == 0 { + t.Error("blob not found in index") } if len(locs) != 1 {