Merge pull request #5273 from wzshiming/fix/local-store-atomic-write
Rename atomicWrite to writeToCompletion
This commit is contained in:
commit
c8cbf7998b
@ -683,10 +683,10 @@ func writeTimestampFile(p string, t time.Time) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
tmp := fmt.Sprintf("%s.tmp", path)
|
||||||
f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode)
|
f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -695,7 +695,11 @@ func atomicWrite(path string, data []byte, mode os.FileMode) error {
|
|||||||
_, err = f.Write(data)
|
_, err = f.Write(data)
|
||||||
f.Close()
|
f.Close()
|
||||||
if err != nil {
|
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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user