build, internal/build: drop own file/folder copier
This commit is contained in:
@ -118,51 +118,6 @@ func render(tpl *template.Template, outputFile string, outputPerm os.FileMode, x
|
||||
}
|
||||
}
|
||||
|
||||
// CopyFile copies a file.
|
||||
func CopyFile(dst, src string, mode os.FileMode) {
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
destFile, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer destFile.Close()
|
||||
|
||||
srcFile, err := os.Open(src)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
if _, err := io.Copy(destFile, srcFile); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// CopyFolder copies a folder.
|
||||
func CopyFolder(dst, src string, mode os.FileMode) {
|
||||
if err := os.MkdirAll(dst, mode); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
dir, _ := os.Open(src)
|
||||
|
||||
objects, err := dir.Readdir(-1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, obj := range objects {
|
||||
srcPath := filepath.Join(src, obj.Name())
|
||||
dstPath := filepath.Join(dst, obj.Name())
|
||||
|
||||
if obj.IsDir() {
|
||||
CopyFolder(dstPath, srcPath, mode)
|
||||
} else {
|
||||
CopyFile(dstPath, srcPath, mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GoTool returns the command that runs a go tool. This uses go from GOROOT instead of PATH
|
||||
// so that go commands executed by build use the same version of Go as the 'host' that runs
|
||||
// build code. e.g.
|
||||
|
Reference in New Issue
Block a user