mirror of
https://github.com/restic/restic.git
synced 2025-12-04 03:38:25 +00:00
repository: Properly set id for finalized index
As MergeFinalIndex and index uploads can occur concurrently, it is necessary for MergeFinalIndex to check whether the IDs for an index were already set before merging it. Otherwise, we'd loose the ID of an index which is set _after_ uploading it.
This commit is contained in:
@@ -287,7 +287,9 @@ func (mi *MasterIndex) MergeFinalIndexes() error {
|
||||
idx := mi.idx[i]
|
||||
// clear reference in masterindex as it may become stale
|
||||
mi.idx[i] = nil
|
||||
if !idx.Final() {
|
||||
// do not merge indexes that have no id set
|
||||
ids, _ := idx.IDs()
|
||||
if !idx.Final() || len(ids) == 0 {
|
||||
newIdx = append(newIdx, idx)
|
||||
} else {
|
||||
err := mi.idx[0].merge(idx)
|
||||
@@ -404,7 +406,13 @@ func SaveIndex(ctx context.Context, repo restic.SaverUnpacked, index *Index) (re
|
||||
return restic.ID{}, err
|
||||
}
|
||||
|
||||
return repo.SaveUnpacked(ctx, restic.IndexFile, buf.Bytes())
|
||||
id, err := repo.SaveUnpacked(ctx, restic.IndexFile, buf.Bytes())
|
||||
ierr := index.SetID(id)
|
||||
if ierr != nil {
|
||||
// logic bug
|
||||
panic(ierr)
|
||||
}
|
||||
return id, err
|
||||
}
|
||||
|
||||
// saveIndex saves all indexes in the backend.
|
||||
|
||||
Reference in New Issue
Block a user