Ensure service install directories are created before writing file
This commit is contained in:
parent
2e2718b7e3
commit
efd4556546
|
@ -8,6 +8,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
homedir "github.com/mitchellh/go-homedir"
|
homedir "github.com/mitchellh/go-homedir"
|
||||||
|
@ -52,10 +53,17 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error generating %s: %v", st.Path, err)
|
return fmt.Errorf("error generating %s: %v", st.Path, err)
|
||||||
}
|
}
|
||||||
fileMode := os.FileMode(0644)
|
fileMode := os.FileMode(0o644)
|
||||||
if st.FileMode != 0 {
|
if st.FileMode != 0 {
|
||||||
fileMode = st.FileMode
|
fileMode = st.FileMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plistFolder := path.Dir(resolvedPath)
|
||||||
|
err = os.MkdirAll(plistFolder, 0o755)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error creating %s: %v", plistFolder, err)
|
||||||
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(resolvedPath, buffer.Bytes(), fileMode)
|
err = ioutil.WriteFile(resolvedPath, buffer.Bytes(), fileMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing %s: %v", resolvedPath, err)
|
return fmt.Errorf("error writing %s: %v", resolvedPath, err)
|
||||||
|
|
Loading…
Reference in New Issue