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:
commit
10115f941c
2 changed files with 11 additions and 6 deletions
|
|
@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue