Merge pull request #575 from heckler1/fix-macos-service

Ensure service install directories are created before writing file
This commit is contained in:
Silver 2022-06-29 10:56:14 -05:00 committed by GitHub
commit d2cb803336
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

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