2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 12:55:18 +00:00

fixes #1251, race when writing indexes

This commit is contained in:
Felix Lee 2017-10-07 05:11:42 -07:00
parent 88fb60e0b5
commit cc5ada63a4

View File

@ -120,19 +120,16 @@ func (mi *MasterIndex) Remove(index *Index) {
// Store remembers the id and pack in the index.
func (mi *MasterIndex) Store(pb restic.PackedBlob) {
mi.idxMutex.RLock()
mi.idxMutex.Lock()
defer mi.idxMutex.Unlock()
for _, idx := range mi.idx {
if !idx.Final() {
mi.idxMutex.RUnlock()
idx.Store(pb)
return
}
}
mi.idxMutex.RUnlock()
mi.idxMutex.Lock()
defer mi.idxMutex.Unlock()
newIdx := NewIndex()
newIdx.Store(pb)
mi.idx = append(mi.idx, newIdx)