summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2018-03-09 08:24:32 +0200
committerGitHub <[email protected]>2018-03-09 08:24:32 +0200
commit98eb9847f27ba2008d380a32c98be474dea55bdf (patch)
tree026be229c487263c2d437ff4f486e9c841b81a9c
parentcdc49b71388c2ab059f57997ef2575c9e8b4f146 (diff)
parentd22b38ff2e294e484e57665bebc7107d0f6f643e (diff)
Merge pull request #60 from posener/fix-59
install: create file directory before file is created
-rw-r--r--cmd/install/utils.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/cmd/install/utils.go b/cmd/install/utils.go
index 8bcf4e1..bb709bc 100644
--- a/cmd/install/utils.go
+++ b/cmd/install/utils.go
@@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
+ "path/filepath"
)
func lineInFile(name string, lookFor string) bool {
@@ -37,11 +38,19 @@ func lineInFile(name string, lookFor string) bool {
}
func createFile(name string, content string) error {
+ // make sure file directory exists
+ if err := os.MkdirAll(filepath.Dir(name), 0775); err != nil {
+ return err
+ }
+
+ // create the file
f, err := os.Create(name)
if err != nil {
return err
}
defer f.Close()
+
+ // write file content
_, err = f.WriteString(fmt.Sprintf("%s\n", content))
return err
}