Merge pull request #3035 from chengzhichao-xydt/codex/file-copy-close-errors

fix: check Close() error after io.Copy to writable files
This commit is contained in:
Mauro
2026-06-07 14:06:57 +02:00
committed by GitHub
2 changed files with 11 additions and 6 deletions
+5 -3
View File
@@ -345,9 +345,11 @@ func copyDirectory(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", dstPath, closeErr)
}
return copyErr
})
}
+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
}