fix: check Close() error after io.Copy to writable files

This commit is contained in:
程智超0668000959
2026-06-07 12:05:09 +08:00
parent 7d2b0c2a4d
commit 2d1fb953fc
2 changed files with 11 additions and 6 deletions
+6 -3
View File
@@ -1,6 +1,7 @@
package internal
import (
"fmt"
"io"
"os"
"path/filepath"
@@ -149,8 +150,10 @@ func CopyFile(src, dst string) error {
if err != nil {
return err
}
defer dstFile.Close()
_, err = io.Copy(dstFile, srcFile)
return err
_, copyErr := io.Copy(dstFile, srcFile)
if closeErr := dstFile.Close(); closeErr != nil && copyErr == nil {
return fmt.Errorf("close destination file %s: %w", dst, closeErr)
}
return copyErr
}