You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
595 B
31 lines
595 B
4 years ago
|
package util
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// opens given files, copies one into another
|
||
|
func CopyFile(src, dst string) error {
|
||
|
srcFile, err := os.Open(src)
|
||
|
if err != nil {
|
||
|
return errors.New(fmt.Sprintf("Could not open src file : %s", err))
|
||
|
}
|
||
|
defer srcFile.Close()
|
||
|
|
||
|
dstFile, err := os.OpenFile(dst, os.O_WRONLY, os.ModePerm)
|
||
|
if err != nil {
|
||
|
return errors.New(fmt.Sprintf("Could not open dst file : %s", err))
|
||
|
}
|
||
|
defer dstFile.Close()
|
||
|
|
||
|
_, err = io.Copy(dstFile, srcFile)
|
||
|
if err != nil {
|
||
|
return errors.New(fmt.Sprintf("Could not copy file : %s", err))
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|