Skip to content

Commit

Permalink
Avoid deadlock during initial scan (fixes syncthing#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Jul 2, 2014
1 parent 5353659 commit 0aa067a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,6 @@ func (m *Model) ReplaceLocal(repo string, fs []scanner.File) {
m.rmut.RUnlock()
}

func (m *Model) SeedLocal(repo string, fs []protocol.FileInfo) {
var sfs = make([]scanner.File, len(fs))
for i := 0; i < len(fs); i++ {
lamport.Default.Tick(fs[i].Version)
sfs[i] = fileFromFileInfo(fs[i])
sfs[i].Suppressed = false // we might have saved an index with files that were suppressed; the should not be on startup
}

m.rmut.RLock()
m.repoFiles[repo].Replace(cid.LocalID, sfs)
m.rmut.RUnlock()
}

func (m *Model) CurrentRepoFile(repo string, file string) scanner.File {
m.rmut.RLock()
f := m.repoFiles[repo].Get(cid.LocalID, file)
Expand Down Expand Up @@ -736,7 +723,15 @@ func (m *Model) LoadIndexes(dir string) {
m.rmut.RLock()
for repo := range m.repoCfgs {
fs := m.loadIndex(repo, dir)
m.SeedLocal(repo, fs)

var sfs = make([]scanner.File, len(fs))
for i := 0; i < len(fs); i++ {
lamport.Default.Tick(fs[i].Version)
sfs[i] = fileFromFileInfo(fs[i])
sfs[i].Suppressed = false // we might have saved an index with files that were suppressed; the should not be on startup
}

m.repoFiles[repo].Replace(cid.LocalID, sfs)
}
m.rmut.RUnlock()
}
Expand Down

0 comments on commit 0aa067a

Please sign in to comment.