|
@@ -93,7 +93,12 @@ func (w *AtomicWriter) Close() error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- err := w.fs.Rename(w.next.Name(), w.path)
|
|
|
+ info, err := w.fs.Lstat(w.path)
|
|
|
+ if err != nil && !fs.IsNotExist(err) {
|
|
|
+ w.err = err
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = w.fs.Rename(w.next.Name(), w.path)
|
|
|
if runtime.GOOS == "windows" && fs.IsPermission(err) {
|
|
|
// On Windows, we might not be allowed to rename over the file
|
|
|
// because it's read-only. Get us some write permissions and try
|
|
@@ -105,6 +110,12 @@ func (w *AtomicWriter) Close() error {
|
|
|
w.err = err
|
|
|
return err
|
|
|
}
|
|
|
+ if info != nil {
|
|
|
+ if err := w.fs.Chmod(w.path, info.Mode()); err != nil {
|
|
|
+ w.err = err
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// fsync the directory too
|
|
|
if fd, err := w.fs.Open(filepath.Dir(w.next.Name())); err == nil {
|