aboutsummaryrefslogtreecommitdiffstats
path: root/internal/build/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/build/util.go')
-rw-r--r--internal/build/util.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/build/util.go b/internal/build/util.go
index a821cd7f2..ce17ce220 100644
--- a/internal/build/util.go
+++ b/internal/build/util.go
@@ -20,6 +20,7 @@ import (
"bytes"
"flag"
"fmt"
+ "io"
"io/ioutil"
"log"
"os"
@@ -117,3 +118,25 @@ func render(tpl *template.Template, outputFile string, outputPerm os.FileMode, x
log.Fatal(err)
}
}
+
+// 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)
+ }
+}