mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
don't save duplicate packIDs when using internal/repository/Index.Store
This commit is contained in:
parent
ce4a2f4ca6
commit
1361341c58
@ -53,6 +53,8 @@ type Index struct {
|
|||||||
duplicates map[restic.BlobHandle][]indexEntry
|
duplicates map[restic.BlobHandle][]indexEntry
|
||||||
packs restic.IDs
|
packs restic.IDs
|
||||||
treePacks restic.IDs
|
treePacks restic.IDs
|
||||||
|
// only used by Store, StorePacks does not check for already saved packIDs
|
||||||
|
packIDToIndex map[restic.ID]int
|
||||||
|
|
||||||
final bool // set to true for all indexes read from the backend ("finalized")
|
final bool // set to true for all indexes read from the backend ("finalized")
|
||||||
id restic.ID // set to the ID of the index when it's finalized
|
id restic.ID // set to the ID of the index when it's finalized
|
||||||
@ -70,9 +72,10 @@ type indexEntry struct {
|
|||||||
// NewIndex returns a new index.
|
// NewIndex returns a new index.
|
||||||
func NewIndex() *Index {
|
func NewIndex() *Index {
|
||||||
return &Index{
|
return &Index{
|
||||||
blob: make(map[restic.BlobHandle]indexEntry),
|
blob: make(map[restic.BlobHandle]indexEntry),
|
||||||
duplicates: make(map[restic.BlobHandle][]indexEntry),
|
duplicates: make(map[restic.BlobHandle][]indexEntry),
|
||||||
created: time.Now(),
|
packIDToIndex: make(map[restic.ID]int),
|
||||||
|
created: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +168,14 @@ func (idx *Index) Store(blob restic.PackedBlob) {
|
|||||||
|
|
||||||
debug.Log("%v", blob)
|
debug.Log("%v", blob)
|
||||||
|
|
||||||
idx.store(idx.addToPacks(blob.PackID), blob.Blob)
|
// get packIndex and save if new packID
|
||||||
|
packIndex, ok := idx.packIDToIndex[blob.PackID]
|
||||||
|
if !ok {
|
||||||
|
packIndex = idx.addToPacks(blob.PackID)
|
||||||
|
idx.packIDToIndex[blob.PackID] = packIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
idx.store(packIndex, blob.Blob)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StorePack remembers the ids of all blobs of a given pack
|
// StorePack remembers the ids of all blobs of a given pack
|
||||||
@ -431,6 +441,8 @@ func (idx *Index) Finalize() {
|
|||||||
defer idx.m.Unlock()
|
defer idx.m.Unlock()
|
||||||
|
|
||||||
idx.final = true
|
idx.final = true
|
||||||
|
// clear packIDToIndex as no more elements will be added
|
||||||
|
idx.packIDToIndex = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ID returns the ID of the index, if available. If the index is not yet
|
// ID returns the ID of the index, if available. If the index is not yet
|
||||||
|
Loading…
Reference in New Issue
Block a user