diff --git a/internal/repository/master_index.go b/internal/repository/master_index.go index 0902dcfac..ad458774d 100644 --- a/internal/repository/master_index.go +++ b/internal/repository/master_index.go @@ -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)