From 4be10aefd5002ed9bddb03b7eade47ae589b6fb2 Mon Sep 17 00:00:00 2001 From: Daniel Theophanes Date: Thu, 21 May 2015 10:24:30 -0700 Subject: [PATCH] service: ensure user home directory is present. --- service_darwin.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/service_darwin.go b/service_darwin.go index 0560b29..9a338a8 100644 --- a/service_darwin.go +++ b/service_darwin.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" "os/user" + "path/filepath" "syscall" "text/template" "time" @@ -33,6 +34,8 @@ func (darwinSystem) New(i Interface, c *Config) (Service, error) { s := &darwinLaunchdService{ i: i, Config: c, + + userService: c.Option.bool(optionUserService, optionUserServiceDefault), } return s, nil @@ -60,6 +63,8 @@ func isInteractive() (bool, error) { type darwinLaunchdService struct { i Interface *Config + + userService bool } func (s *darwinLaunchdService) String() string { @@ -70,7 +75,7 @@ func (s *darwinLaunchdService) String() string { } func (s *darwinLaunchdService) getServiceFilePath() (string, error) { - if s.Option.bool(optionUserService, optionUserServiceDefault) { + if s.userService { u, err := user.Current() if err != nil { return "", err @@ -90,6 +95,14 @@ func (s *darwinLaunchdService) Install() error { return fmt.Errorf("Init already exists: %s", confPath) } + if s.userService { + // Ensure that ~/Library/LaunchAgents exists. + err = os.MkdirAll(filepath.Dir(confPath), 0700) + if err != nil { + return err + } + } + f, err := os.Create(confPath) if err != nil { return err