Merge pull request #5273 from wzshiming/fix/local-store-atomic-write

Rename atomicWrite to writeToCompletion
This commit is contained in:
Fu Wei 2021-05-27 22:36:09 +08:00 committed by GitHub
commit c8cbf7998b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}