grain/relay/utils/copyFile.go

31 lines
528 B
Go
Raw Normal View History

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
}