mirror of
https://github.com/octoleo/restic.git
synced 2024-12-28 21:02:47 +00:00
Merge pull request #1339 from felix9/fix_1251
fixes #1251, race when writing indexes
This commit is contained in:
commit
17d688afef
@ -120,19 +120,16 @@ func (mi *MasterIndex) Remove(index *Index) {
|
|||||||
|
|
||||||
// Store remembers the id and pack in the index.
|
// Store remembers the id and pack in the index.
|
||||||
func (mi *MasterIndex) Store(pb restic.PackedBlob) {
|
func (mi *MasterIndex) Store(pb restic.PackedBlob) {
|
||||||
mi.idxMutex.RLock()
|
mi.idxMutex.Lock()
|
||||||
|
defer mi.idxMutex.Unlock()
|
||||||
|
|
||||||
for _, idx := range mi.idx {
|
for _, idx := range mi.idx {
|
||||||
if !idx.Final() {
|
if !idx.Final() {
|
||||||
mi.idxMutex.RUnlock()
|
|
||||||
idx.Store(pb)
|
idx.Store(pb)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mi.idxMutex.RUnlock()
|
|
||||||
mi.idxMutex.Lock()
|
|
||||||
defer mi.idxMutex.Unlock()
|
|
||||||
|
|
||||||
newIdx := NewIndex()
|
newIdx := NewIndex()
|
||||||
newIdx.Store(pb)
|
newIdx.Store(pb)
|
||||||
mi.idx = append(mi.idx, newIdx)
|
mi.idx = append(mi.idx, newIdx)
|
||||||
|
Loading…
Reference in New Issue
Block a user