From 2ce4fd387af8523c70dfc8f46a6ef25451ed4286 Mon Sep 17 00:00:00 2001 From: zjubiology Date: Sat, 26 Sep 2026 19:09:42 +0800 Subject: [PATCH] fix(os): preserve close errors in CopyFile Signed-off-by: zjubiology --- pkg/os/os.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/os/os.go b/pkg/os/os.go index 5cd277a75d..3c0f53d51a 100644 --- a/pkg/os/os.go +++ b/pkg/os/os.go @@ -74,7 +74,9 @@ func MustWriteFile(filePath string, contents []byte, mode os.FileMode) { } // CopyFile copies a file. It truncates the destination file if it exists. -func CopyFile(src, dst string) error { +// The result is named so that the deferred Close calls below can surface a +// close error to the caller when the copy itself succeeded. +func CopyFile(src, dst string) (err error) { srcfile, err := os.Open(src) //nolint:gosec if err != nil { return err