diff --git a/content/local/store.go b/content/local/store.go index cb6aae829..60527209c 100644 --- a/content/local/store.go +++ b/content/local/store.go @@ -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 }