diff --git a/pkg/os/os.go b/pkg/os/os.go index 5cd277a75d..3c0f53d51a 100644 --- a/pkg/os/os.go +++ b/pkg/os/os.go @@ -74,7 +74,9 @@ func MustWriteFile(filePath string, contents []byte, mode os.FileMode) { } // CopyFile copies a file. It truncates the destination file if it exists. -func CopyFile(src, dst string) error { +// The result is named so that the deferred Close calls below can surface a +// close error to the caller when the copy itself succeeded. +func CopyFile(src, dst string) (err error) { srcfile, err := os.Open(src) //nolint:gosec if err != nil { return err