mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Use unique name and O_EXCL for temporary indexes (fixes #332)
This commit is contained in:
parent
d87051ca99
commit
bec5c76631
@ -716,11 +716,12 @@ func (m *Model) saveIndex(repo string, dir string, fs []protocol.FileInfo) error
|
||||
id := fmt.Sprintf("%x", sha1.Sum([]byte(m.repoCfgs[repo].Directory)))
|
||||
name := id + ".idx.gz"
|
||||
name = filepath.Join(dir, name)
|
||||
|
||||
idxf, err := os.Create(name + ".tmp")
|
||||
tmp := fmt.Sprintf("%s.tmp.%d", name, time.Now().UnixNano())
|
||||
idxf, err := os.OpenFile(tmp, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(tmp)
|
||||
|
||||
gzw := gzip.NewWriter(idxf)
|
||||
|
||||
@ -748,7 +749,7 @@ func (m *Model) saveIndex(repo string, dir string, fs []protocol.FileInfo) error
|
||||
l.Debugln("wrote index,", n, "bytes uncompressed")
|
||||
}
|
||||
|
||||
return osutil.Rename(name+".tmp", name)
|
||||
return osutil.Rename(tmp, name)
|
||||
}
|
||||
|
||||
func (m *Model) loadIndex(repo string, dir string) []protocol.FileInfo {
|
||||
|
Loading…
Reference in New Issue
Block a user