mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix: check Close() error after io.Copy to writable files
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user