From efd455654627516d2bf133f55a462a101f233019 Mon Sep 17 00:00:00 2001 From: Stephen Heckler Date: Fri, 18 Feb 2022 11:06:49 -0600 Subject: [PATCH] Ensure service install directories are created before writing file --- cmd/cloudflared/service_template.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/cloudflared/service_template.go b/cmd/cloudflared/service_template.go index 3040766f..feaf86cc 100644 --- a/cmd/cloudflared/service_template.go +++ b/cmd/cloudflared/service_template.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "os/exec" + "path" "text/template" homedir "github.com/mitchellh/go-homedir" @@ -52,10 +53,17 @@ func (st *ServiceTemplate) Generate(args *ServiceTemplateArgs) error { if err != nil { return fmt.Errorf("error generating %s: %v", st.Path, err) } - fileMode := os.FileMode(0644) + fileMode := os.FileMode(0o644) if st.FileMode != 0 { 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) if err != nil { return fmt.Errorf("error writing %s: %v", resolvedPath, err)