mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +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.
|
// 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) {
|
func (idx *Index) Lookup(id restic.ID, tpe restic.BlobType) (blobs []restic.PackedBlob, found bool) {
|
||||||
idx.m.Lock()
|
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))
|
blobs = make([]restic.PackedBlob, 0, len(packs))
|
||||||
|
|
||||||
for _, p := range packs {
|
for _, p := range packs {
|
||||||
blob := restic.PackedBlob{
|
blobs = append(blobs, indexEntryToPackedBlob(h, p))
|
||||||
Blob: restic.Blob{
|
|
||||||
Type: tpe,
|
|
||||||
Length: p.length,
|
|
||||||
ID: id,
|
|
||||||
Offset: p.offset,
|
|
||||||
},
|
|
||||||
PackID: p.packID,
|
|
||||||
}
|
|
||||||
|
|
||||||
blobs = append(blobs, blob)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return blobs, true
|
return blobs, true
|
||||||
@ -178,15 +181,7 @@ func (idx *Index) ListPack(id restic.ID) (list []restic.PackedBlob) {
|
|||||||
for h, packList := range idx.pack {
|
for h, packList := range idx.pack {
|
||||||
for _, entry := range packList {
|
for _, entry := range packList {
|
||||||
if entry.packID == id {
|
if entry.packID == id {
|
||||||
list = append(list, restic.PackedBlob{
|
list = append(list, indexEntryToPackedBlob(h, entry))
|
||||||
Blob: restic.Blob{
|
|
||||||
ID: h.ID,
|
|
||||||
Type: h.Type,
|
|
||||||
Length: entry.length,
|
|
||||||
Offset: entry.offset,
|
|
||||||
},
|
|
||||||
PackID: entry.packID,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,15 +249,7 @@ func (idx *Index) Each(ctx context.Context) <-chan restic.PackedBlob {
|
|||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case ch <- restic.PackedBlob{
|
case ch <- indexEntryToPackedBlob(h, blob):
|
||||||
Blob: restic.Blob{
|
|
||||||
ID: h.ID,
|
|
||||||
Type: h.Type,
|
|
||||||
Offset: blob.offset,
|
|
||||||
Length: blob.length,
|
|
||||||
},
|
|
||||||
PackID: blob.packID,
|
|
||||||
}:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,19 +132,6 @@ func (mi *MasterIndex) Insert(idx *Index) {
|
|||||||
mi.idx = append(mi.idx, idx)
|
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.
|
// Store remembers the id and pack in the index.
|
||||||
func (mi *MasterIndex) StorePack(id restic.ID, blobs []restic.Blob) {
|
func (mi *MasterIndex) StorePack(id restic.ID, blobs []restic.Blob) {
|
||||||
mi.idxMutex.Lock()
|
mi.idxMutex.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user