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