mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 12:55:18 +00:00
simplify index code
This commit is contained in:
parent
7419844885
commit
d92e2c5769
@ -140,6 +140,19 @@ func (idx *Index) StorePack(id restic.ID, blobs []restic.Blob) {
|
||||
}
|
||||
}
|
||||
|
||||
// ListPack returns a list of blobs contained in a pack.
|
||||
func indexEntryToPackedBlob(h restic.BlobHandle, entry indexEntry) restic.PackedBlob {
|
||||
return restic.PackedBlob{
|
||||
Blob: restic.Blob{
|
||||
ID: h.ID,
|
||||
Type: h.Type,
|
||||
Length: entry.length,
|
||||
Offset: entry.offset,
|
||||
},
|
||||
PackID: entry.packID,
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup queries the index for the blob ID and returns a restic.PackedBlob.
|
||||
func (idx *Index) Lookup(id restic.ID, tpe restic.BlobType) (blobs []restic.PackedBlob, found bool) {
|
||||
idx.m.Lock()
|
||||
@ -151,17 +164,7 @@ func (idx *Index) Lookup(id restic.ID, tpe restic.BlobType) (blobs []restic.Pack
|
||||
blobs = make([]restic.PackedBlob, 0, len(packs))
|
||||
|
||||
for _, p := range packs {
|
||||
blob := restic.PackedBlob{
|
||||
Blob: restic.Blob{
|
||||
Type: tpe,
|
||||
Length: p.length,
|
||||
ID: id,
|
||||
Offset: p.offset,
|
||||
},
|
||||
PackID: p.packID,
|
||||
}
|
||||
|
||||
blobs = append(blobs, blob)
|
||||
blobs = append(blobs, indexEntryToPackedBlob(h, p))
|
||||
}
|
||||
|
||||
return blobs, true
|
||||
@ -178,15 +181,7 @@ func (idx *Index) ListPack(id restic.ID) (list []restic.PackedBlob) {
|
||||
for h, packList := range idx.pack {
|
||||
for _, entry := range packList {
|
||||
if entry.packID == id {
|
||||
list = append(list, restic.PackedBlob{
|
||||
Blob: restic.Blob{
|
||||
ID: h.ID,
|
||||
Type: h.Type,
|
||||
Length: entry.length,
|
||||
Offset: entry.offset,
|
||||
},
|
||||
PackID: entry.packID,
|
||||
})
|
||||
list = append(list, indexEntryToPackedBlob(h, entry))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -254,15 +249,7 @@ func (idx *Index) Each(ctx context.Context) <-chan restic.PackedBlob {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case ch <- restic.PackedBlob{
|
||||
Blob: restic.Blob{
|
||||
ID: h.ID,
|
||||
Type: h.Type,
|
||||
Offset: blob.offset,
|
||||
Length: blob.length,
|
||||
},
|
||||
PackID: blob.packID,
|
||||
}:
|
||||
case ch <- indexEntryToPackedBlob(h, blob):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,19 +132,6 @@ func (mi *MasterIndex) Insert(idx *Index) {
|
||||
mi.idx = append(mi.idx, idx)
|
||||
}
|
||||
|
||||
// Remove deletes an index from the MasterIndex.
|
||||
func (mi *MasterIndex) Remove(index *Index) {
|
||||
mi.idxMutex.Lock()
|
||||
defer mi.idxMutex.Unlock()
|
||||
|
||||
for i, idx := range mi.idx {
|
||||
if idx == index {
|
||||
mi.idx = append(mi.idx[:i], mi.idx[i+1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store remembers the id and pack in the index.
|
||||
func (mi *MasterIndex) StorePack(id restic.ID, blobs []restic.Blob) {
|
||||
mi.idxMutex.Lock()
|
||||
|
Loading…
Reference in New Issue
Block a user