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
commit 10115f941c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 6 deletions

View file

@ -345,9 +345,11 @@ func copyDirectory(src, dst string) error {
if err != nil { if err != nil {
return err return err
} }
defer dstFile.Close()
_, err = io.Copy(dstFile, srcFile) _, copyErr := io.Copy(dstFile, srcFile)
return err if closeErr := dstFile.Close(); closeErr != nil && copyErr == nil {
return fmt.Errorf("close destination file %s: %w", dstPath, closeErr)
}
return copyErr
}) })
} }

View file

@ -1,6 +1,7 @@
package internal package internal
import ( import (
"fmt"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
@ -149,8 +150,10 @@ func CopyFile(src, dst string) error {
if err != nil { if err != nil {
return err return err
} }
defer dstFile.Close()
_, err = io.Copy(dstFile, srcFile) _, copyErr := io.Copy(dstFile, srcFile)
return err if closeErr := dstFile.Close(); closeErr != nil && copyErr == nil {
return fmt.Errorf("close destination file %s: %w", dst, closeErr)
}
return copyErr
} }