mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-10-30 01:26:32 +00:00
31 lines
528 B
Go
31 lines
528 B
Go
package utils
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func copyFile(src, dst string) error {
|
|
sourceFile, err := os.Open(src)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer sourceFile.Close()
|
|
|
|
// Create the directory for the destination file if it doesn't exist
|
|
destDir := filepath.Dir(dst)
|
|
err = os.MkdirAll(destDir, os.ModePerm)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
destinationFile, err := os.Create(dst)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer destinationFile.Close()
|
|
|
|
_, err = io.Copy(destinationFile, sourceFile)
|
|
return err
|
|
} |