Only fail after chmod error if permissions differ (e.g. on config file) (#8771)

This commit is contained in:
Andreas Sommer 2023-02-20 15:41:10 +01:00 committed by GitHub
parent 2321d0db08
commit 2f88dafa56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,9 +109,15 @@ func (w *AtomicWriter) Close() error {
return err return err
} }
if infoErr == nil { if infoErr == nil {
// Restore chmod setting for final file to what it was
if err := w.fs.Chmod(w.path, info.Mode()); err != nil { if err := w.fs.Chmod(w.path, info.Mode()); err != nil {
w.err = err // Only fail if permissions differ, since some filesystems are expected to not allow chmod (e.g. error
return err // `operation not permitted`).
infoAfterRename, infoAfterRenameErr := w.fs.Lstat(w.path)
if infoAfterRenameErr != nil || infoAfterRename.Mode() != info.Mode() {
w.err = err
return err
}
} }
} }