forked from TrueCloudLab/restic
Harmonize naming
This commit is contained in:
parent
92bd448691
commit
e3013271a6
2 changed files with 31 additions and 31 deletions
|
@ -124,7 +124,7 @@ var IndexFull = func(idx *Index) bool {
|
|||
}
|
||||
|
||||
// Store remembers the id and pack in the index.
|
||||
func (idx *Index) Store(blob restic.PackedBlob) {
|
||||
func (idx *Index) Store(pb restic.PackedBlob) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
|
@ -132,16 +132,16 @@ func (idx *Index) Store(blob restic.PackedBlob) {
|
|||
panic("store new item in finalized index")
|
||||
}
|
||||
|
||||
debug.Log("%v", blob)
|
||||
debug.Log("%v", pb)
|
||||
|
||||
// get packIndex and save if new packID
|
||||
packIndex, ok := idx.packIDToIndex[blob.PackID]
|
||||
packIndex, ok := idx.packIDToIndex[pb.PackID]
|
||||
if !ok {
|
||||
packIndex = idx.addToPacks(blob.PackID)
|
||||
idx.packIDToIndex[blob.PackID] = packIndex
|
||||
packIndex = idx.addToPacks(pb.PackID)
|
||||
idx.packIDToIndex[pb.PackID] = packIndex
|
||||
}
|
||||
|
||||
idx.store(packIndex, blob.Blob)
|
||||
idx.store(packIndex, pb.Blob)
|
||||
}
|
||||
|
||||
// StorePack remembers the ids of all blobs of a given pack
|
||||
|
@ -162,11 +162,11 @@ func (idx *Index) StorePack(id restic.ID, blobs []restic.Blob) {
|
|||
}
|
||||
}
|
||||
|
||||
func (idx *Index) toPackedBlob(e *indexEntry, typ restic.BlobType) restic.PackedBlob {
|
||||
func (idx *Index) toPackedBlob(e *indexEntry, t restic.BlobType) restic.PackedBlob {
|
||||
return restic.PackedBlob{
|
||||
Blob: restic.Blob{
|
||||
BlobHandle: restic.BlobHandle{ID: e.id,
|
||||
Type: typ},
|
||||
Type: t},
|
||||
Length: uint(e.length),
|
||||
Offset: uint(e.offset),
|
||||
},
|
||||
|
@ -176,19 +176,19 @@ func (idx *Index) toPackedBlob(e *indexEntry, typ restic.BlobType) restic.Packed
|
|||
|
||||
// Lookup queries the index for the blob ID and returns all entries including
|
||||
// duplicates. Adds found entries to blobs and returns the result.
|
||||
func (idx *Index) Lookup(id restic.ID, tpe restic.BlobType, blobs []restic.PackedBlob) []restic.PackedBlob {
|
||||
func (idx *Index) Lookup(id restic.ID, t restic.BlobType, pbs []restic.PackedBlob) []restic.PackedBlob {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
idx.byType[tpe].foreachWithID(id, func(e *indexEntry) {
|
||||
blobs = append(blobs, idx.toPackedBlob(e, tpe))
|
||||
idx.byType[t].foreachWithID(id, func(e *indexEntry) {
|
||||
pbs = append(pbs, idx.toPackedBlob(e, t))
|
||||
})
|
||||
|
||||
return blobs
|
||||
return pbs
|
||||
}
|
||||
|
||||
// ListPack returns a list of blobs contained in a pack.
|
||||
func (idx *Index) ListPack(id restic.ID) (list []restic.PackedBlob) {
|
||||
func (idx *Index) ListPack(id restic.ID) (pbs []restic.PackedBlob) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
|
@ -196,30 +196,30 @@ func (idx *Index) ListPack(id restic.ID) (list []restic.PackedBlob) {
|
|||
m := &idx.byType[typ]
|
||||
m.foreach(func(e *indexEntry) bool {
|
||||
if idx.packs[e.packIndex] == id {
|
||||
list = append(list, idx.toPackedBlob(e, restic.BlobType(typ)))
|
||||
pbs = append(pbs, idx.toPackedBlob(e, restic.BlobType(typ)))
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return list
|
||||
return pbs
|
||||
}
|
||||
|
||||
// Has returns true iff the id is listed in the index.
|
||||
func (idx *Index) Has(id restic.ID, tpe restic.BlobType) bool {
|
||||
func (idx *Index) Has(id restic.ID, t restic.BlobType) bool {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
return idx.byType[tpe].get(id) != nil
|
||||
return idx.byType[t].get(id) != nil
|
||||
}
|
||||
|
||||
// LookupSize returns the length of the plaintext content of the blob with the
|
||||
// given id.
|
||||
func (idx *Index) LookupSize(id restic.ID, tpe restic.BlobType) (plaintextLength uint, found bool) {
|
||||
func (idx *Index) LookupSize(id restic.ID, t restic.BlobType) (plaintextLength uint, found bool) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
e := idx.byType[tpe].get(id)
|
||||
e := idx.byType[t].get(id)
|
||||
if e == nil {
|
||||
return 0, false
|
||||
}
|
||||
|
|
|
@ -29,24 +29,24 @@ func NewMasterIndex() *MasterIndex {
|
|||
}
|
||||
|
||||
// Lookup queries all known Indexes for the ID and returns all matches.
|
||||
func (mi *MasterIndex) Lookup(id restic.ID, tpe restic.BlobType) (blobs []restic.PackedBlob) {
|
||||
func (mi *MasterIndex) Lookup(id restic.ID, t restic.BlobType) (pbs []restic.PackedBlob) {
|
||||
mi.idxMutex.RLock()
|
||||
defer mi.idxMutex.RUnlock()
|
||||
|
||||
for _, idx := range mi.idx {
|
||||
blobs = idx.Lookup(id, tpe, blobs)
|
||||
pbs = idx.Lookup(id, t, pbs)
|
||||
}
|
||||
|
||||
return blobs
|
||||
return pbs
|
||||
}
|
||||
|
||||
// LookupSize queries all known Indexes for the ID and returns the first match.
|
||||
func (mi *MasterIndex) LookupSize(id restic.ID, tpe restic.BlobType) (uint, bool) {
|
||||
func (mi *MasterIndex) LookupSize(id restic.ID, t restic.BlobType) (uint, bool) {
|
||||
mi.idxMutex.RLock()
|
||||
defer mi.idxMutex.RUnlock()
|
||||
|
||||
for _, idx := range mi.idx {
|
||||
if size, found := idx.LookupSize(id, tpe); found {
|
||||
if size, found := idx.LookupSize(id, t); found {
|
||||
return size, found
|
||||
}
|
||||
}
|
||||
|
@ -58,40 +58,40 @@ func (mi *MasterIndex) LookupSize(id restic.ID, tpe restic.BlobType) (uint, bool
|
|||
// Before doing so it checks if this blob is already known.
|
||||
// Returns true if adding was successful and false if the blob
|
||||
// was already known
|
||||
func (mi *MasterIndex) addPending(id restic.ID, tpe restic.BlobType) bool {
|
||||
func (mi *MasterIndex) addPending(id restic.ID, t restic.BlobType) bool {
|
||||
|
||||
mi.idxMutex.Lock()
|
||||
defer mi.idxMutex.Unlock()
|
||||
|
||||
// Check if blob is pending or in index
|
||||
if mi.pendingBlobs.Has(restic.BlobHandle{ID: id, Type: tpe}) {
|
||||
if mi.pendingBlobs.Has(restic.BlobHandle{ID: id, Type: t}) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, idx := range mi.idx {
|
||||
if idx.Has(id, tpe) {
|
||||
if idx.Has(id, t) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// really not known -> insert
|
||||
mi.pendingBlobs.Insert(restic.BlobHandle{ID: id, Type: tpe})
|
||||
mi.pendingBlobs.Insert(restic.BlobHandle{ID: id, Type: t})
|
||||
return true
|
||||
}
|
||||
|
||||
// Has queries all known Indexes for the ID and returns the first match.
|
||||
// Also returns true if the ID is pending.
|
||||
func (mi *MasterIndex) Has(id restic.ID, tpe restic.BlobType) bool {
|
||||
func (mi *MasterIndex) Has(id restic.ID, t restic.BlobType) bool {
|
||||
mi.idxMutex.RLock()
|
||||
defer mi.idxMutex.RUnlock()
|
||||
|
||||
// also return true if blob is pending
|
||||
if mi.pendingBlobs.Has(restic.BlobHandle{ID: id, Type: tpe}) {
|
||||
if mi.pendingBlobs.Has(restic.BlobHandle{ID: id, Type: t}) {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, idx := range mi.idx {
|
||||
if idx.Has(id, tpe) {
|
||||
if idx.Has(id, t) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue