lib/osutil: Check returned error instead of info (ref #6885) (#6887)

This commit is contained in:
Simon Frei 2020-08-12 11:33:56 +02:00 committed by GitHub
parent fa9bc08afb
commit 9c2117f08e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,12 +93,12 @@ func (w *AtomicWriter) Close() error {
return err return err
} }
info, err := w.fs.Lstat(w.path) info, infoErr := w.fs.Lstat(w.path)
if err != nil && !fs.IsNotExist(err) { if infoErr != nil && !fs.IsNotExist(infoErr) {
w.err = err w.err = infoErr
return err return infoErr
} }
err = w.fs.Rename(w.next.Name(), w.path) err := w.fs.Rename(w.next.Name(), w.path)
if runtime.GOOS == "windows" && fs.IsPermission(err) { if runtime.GOOS == "windows" && fs.IsPermission(err) {
// On Windows, we might not be allowed to rename over the file // On Windows, we might not be allowed to rename over the file
// because it's read-only. Get us some write permissions and try // because it's read-only. Get us some write permissions and try
@ -110,7 +110,7 @@ func (w *AtomicWriter) Close() error {
w.err = err w.err = err
return err return err
} }
if info != nil { if infoErr == nil {
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 w.err = err
return err return err