Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

35 lines
615 B
Go

// Package fileutil provides file operation utilities.
package fileutil
import (
"io"
"os"
)
// CopyFile copies the file at src to dst. If dst already exists it is
// overwritten. Partial files are cleaned up on error.
func CopyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
_, copyErr := io.Copy(out, in)
closeErr := out.Close()
if copyErr != nil {
os.Remove(dst) // clean up partial file
return copyErr
}
if closeErr != nil {
os.Remove(dst)
return closeErr
}
return nil
}