Skip to content

Commit c8cbf79

Browse files
authored
Merge pull request #5273 from wzshiming/fix/local-store-atomic-write
Rename atomicWrite to writeToCompletion
2 parents 925ff5a + 9fcea1d commit c8cbf79

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

content/local/store.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,10 @@ func writeTimestampFile(p string, t time.Time) error {
683683
if err != nil {
684684
return err
685685
}
686-
return atomicWrite(p, b, 0666)
686+
return writeToCompletion(p, b, 0666)
687687
}
688688

689-
func atomicWrite(path string, data []byte, mode os.FileMode) error {
689+
func writeToCompletion(path string, data []byte, mode os.FileMode) error {
690690
tmp := fmt.Sprintf("%s.tmp", path)
691691
f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode)
692692
if err != nil {
@@ -695,7 +695,11 @@ func atomicWrite(path string, data []byte, mode os.FileMode) error {
695695
_, err = f.Write(data)
696696
f.Close()
697697
if err != nil {
698-
return errors.Wrap(err, "write atomic data")
698+
return errors.Wrap(err, "write tmp file")
699699
}
700-
return os.Rename(tmp, path)
700+
err = os.Rename(tmp, path)
701+
if err != nil {
702+
return errors.Wrap(err, "rename tmp file")
703+
}
704+
return nil
701705
}

0 commit comments

Comments
 (0)