mirror of
https://github.com/restic/restic.git
synced 2025-11-14 15:02:47 +00:00
Fix non-intuitive repository behavior
- The SaveBlob method now checks for duplicates. - Moves handling of pending blobs to MasterIndex. -> also cleans up pending index entries when they are saved in the index -> when using SaveBlob no need to care about index any longer - Always check for full index and save it when storing packs. -> removes the need of an index uploader -> also removes the verbose "uploaded intermediate index" messages - The Flush method now also saves the index - Fix race condition when checking and saving full/non-finalized indexes
This commit is contained in:
@@ -94,8 +94,7 @@ var IndexFull = func(idx *Index) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Store remembers the id and pack in the index. An existing entry will be
|
||||
// silently overwritten.
|
||||
// Store remembers the id and pack in the index.
|
||||
func (idx *Index) Store(blob restic.PackedBlob) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
@@ -109,6 +108,23 @@ func (idx *Index) Store(blob restic.PackedBlob) {
|
||||
idx.store(blob)
|
||||
}
|
||||
|
||||
// StorePack remembers the ids of all blobs of a given pack
|
||||
// in the index
|
||||
func (idx *Index) StorePack(id restic.ID, blobs []restic.Blob) {
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
if idx.final {
|
||||
panic("store new item in finalized index")
|
||||
}
|
||||
|
||||
debug.Log("%v", blobs)
|
||||
|
||||
for _, blob := range blobs {
|
||||
idx.store(restic.PackedBlob{Blob: blob, PackID: id})
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
@@ -360,15 +376,13 @@ func (idx *Index) encode(w io.Writer) error {
|
||||
return enc.Encode(idxJSON)
|
||||
}
|
||||
|
||||
// Finalize sets the index to final and writes the JSON serialization to w.
|
||||
func (idx *Index) Finalize(w io.Writer) error {
|
||||
debug.Log("encoding index")
|
||||
// Finalize sets the index to final.
|
||||
func (idx *Index) Finalize() {
|
||||
debug.Log("finalizing index")
|
||||
idx.m.Lock()
|
||||
defer idx.m.Unlock()
|
||||
|
||||
idx.final = true
|
||||
|
||||
return idx.encode(w)
|
||||
}
|
||||
|
||||
// ID returns the ID of the index, if available. If the index is not yet
|
||||
|
||||
Reference in New Issue
Block a user