Merge pull request #60 from posener/fix-59

install: create file directory before file is created
This commit is contained in:
Eyal Posener 2018-03-09 08:24:32 +02:00 committed by GitHub
commit 98eb9847f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -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
}