mirror of https://github.com/restic/restic.git
Add Index.Packs() and IDSet.Equals()
This commit is contained in:
parent
4b1a2caea7
commit
d9f9b77d68
|
@ -39,6 +39,27 @@ func (s IDSet) List() IDs {
|
|||
return list
|
||||
}
|
||||
|
||||
// Equals returns true iff s equals other.
|
||||
func (s IDSet) Equals(other IDSet) bool {
|
||||
if len(s) != len(other) {
|
||||
return false
|
||||
}
|
||||
|
||||
for id := range s {
|
||||
if _, ok := other[id]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for id := range other {
|
||||
if _, ok := s[id]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s IDSet) String() string {
|
||||
str := s.List().String()
|
||||
if len(str) < 2 {
|
||||
|
|
|
@ -205,6 +205,19 @@ func (idx *Index) Each(done chan struct{}) <-chan PackedBlob {
|
|||
return ch
|
||||
}
|
||||
|
||||
// Packs returns all packs in this index
|
||||
func (idx *Index) Packs() backend.IDSet {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
packs := backend.NewIDSet()
|
||||
for _, entry := range idx.pack {
|
||||
packs.Insert(entry.packID)
|
||||
}
|
||||
|
||||
return packs
|
||||
}
|
||||
|
||||
// Count returns the number of blobs of type t in the index.
|
||||
func (idx *Index) Count(t pack.BlobType) (n uint) {
|
||||
debug.Log("Index.Count", "counting blobs of type %v", t)
|
||||
|
|
|
@ -325,3 +325,18 @@ func TestConvertIndex(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestIndexPacks(t *testing.T) {
|
||||
idx := repository.NewIndex()
|
||||
packs := backend.NewIDSet()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
packID := randomID()
|
||||
idx.Store(pack.Data, randomID(), packID, 0, 23)
|
||||
|
||||
packs.Insert(packID)
|
||||
}
|
||||
|
||||
idxPacks := idx.Packs()
|
||||
Assert(t, packs.Equals(idxPacks), "packs in index do not match packs added to index")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue