Rename atomicWrite to writeToCompletion

Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
This commit is contained in:
Shiming Zhang 2021-03-30 10:10:59 +08:00
parent 925ff5a21b
commit 9fcea1d3f0

View File

@ -683,10 +683,10 @@ func writeTimestampFile(p string, t time.Time) error {
if err != nil {
return err
}
return atomicWrite(p, b, 0666)
return writeToCompletion(p, b, 0666)
}
func atomicWrite(path string, data []byte, mode os.FileMode) error {
func writeToCompletion(path string, data []byte, mode os.FileMode) error {
tmp := fmt.Sprintf("%s.tmp", path)
f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode)
if err != nil {
@ -695,7 +695,11 @@ func atomicWrite(path string, data []byte, mode os.FileMode) error {
_, err = f.Write(data)
f.Close()
if err != nil {
return errors.Wrap(err, "write atomic data")
return errors.Wrap(err, "write tmp file")
}
return os.Rename(tmp, path)
err = os.Rename(tmp, path)
if err != nil {
return errors.Wrap(err, "rename tmp file")
}
return nil
}