Skip to content

Commit

Permalink
copyFile: Don't ignore Close() errors on writable file
Browse files Browse the repository at this point in the history
This follows the advice from
https://www.joeshaw.org/dont-defer-close-on-writable-files/
Write() is not fully synchronous, so some errors writing the file may
only be reported at Close() time.
  • Loading branch information
cfergeau authored and guillaumerose committed May 18, 2021
1 parent c4e5728 commit 3a3cdbc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/libvirt/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ func copyFile(src, dst string) error {
return err
}

return os.Chmod(dst, fi.Mode())
if err = os.Chmod(dst, fi.Mode()); err != nil {
return err
}

return out.Close()
}

0 comments on commit 3a3cdbc

Please sign in to comment.