mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 03:18:59 +00:00
Atomically replace local index cache
This commit is contained in:
parent
d4c5786a14
commit
a2a2e1d466
6
main.go
6
main.go
@ -304,13 +304,15 @@ func updateLocalModel(m *Model) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveIndex(m *Model) {
|
func saveIndex(m *Model) {
|
||||||
fname := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
|
name := fmt.Sprintf("%x.idx", sha1.Sum([]byte(m.Dir())))
|
||||||
idxf, err := os.Create(path.Join(ConfDir, fname))
|
fullName := path.Join(ConfDir, name)
|
||||||
|
idxf, err := os.Create(fullName + ".tmp")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
protocol.WriteIndex(idxf, m.ProtocolIndex())
|
protocol.WriteIndex(idxf, m.ProtocolIndex())
|
||||||
idxf.Close()
|
idxf.Close()
|
||||||
|
os.Rename(fullName+".tmp", fullName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadIndex(m *Model) {
|
func loadIndex(m *Model) {
|
||||||
|
Loading…
Reference in New Issue
Block a user