mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 03:18:55 +00:00
Index: Add DuplicateBlobs()
This commit is contained in:
parent
f5daf33322
commit
4bdd59b4ad
@ -147,3 +147,22 @@ func Load(repo *repository.Repository) (*Index, error) {
|
||||
|
||||
return idx, nil
|
||||
}
|
||||
|
||||
// DuplicateBlobs returns a list of blobs that are stored more than once in the
|
||||
// repo.
|
||||
func (idx *Index) DuplicateBlobs() (dups map[pack.Handle]int) {
|
||||
dups = make(map[pack.Handle]int)
|
||||
seen := pack.NewBlobSet()
|
||||
|
||||
for _, p := range idx.Packs {
|
||||
for _, entry := range p.Entries {
|
||||
h := pack.Handle{ID: entry.ID, Type: entry.Type}
|
||||
if seen.Has(h) {
|
||||
dups[h]++
|
||||
}
|
||||
seen.Insert(h)
|
||||
}
|
||||
}
|
||||
|
||||
return dups
|
||||
}
|
||||
|
@ -154,3 +154,18 @@ func BenchmarkIndexNew(b *testing.B) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexDuplicateBlobs(t *testing.T) {
|
||||
repo, cleanup := createFilledRepo(t, 3, 0.05)
|
||||
defer cleanup()
|
||||
|
||||
idx, err := New(repo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dups := idx.DuplicateBlobs()
|
||||
if len(dups) == 0 {
|
||||
t.Errorf("no duplicate blobs found")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user