lib/osutil: Preserve perms in AtomicWriter (fixes #tbd) (#6885)
This commit is contained in:
+12
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user