Atomically replace local index cache

This commit is contained in:
Jakob Borg 2013-12-30 22:04:30 -05:00
parent d4c5786a14
commit a2a2e1d466

View File

@ -304,13 +304,15 @@ func updateLocalModel(m *Model) {
}
func saveIndex(m *Model) {
fname := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
idxf, err := os.Create(path.Join(ConfDir, fname))
name := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
fullName := path.Join(ConfDir, name)
idxf, err := os.Create(fullName + ".tmp")
if err != nil {
return
}
protocol.WriteIndex(idxf, m.ProtocolIndex())
idxf.Close()
os.Rename(fullName+".tmp", fullName)
}
func loadIndex(m *Model) {