Skip to content

Commit

Permalink
Merge pull request #2 from brasic/mkdirall
Browse files Browse the repository at this point in the history
Always mkdir -p the LaunchAgents directory
  • Loading branch information
brasic authored Mar 16, 2023
2 parents 5335064 + 9e7206b commit 521cb61
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions service.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package launchd

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
)
Expand Down Expand Up @@ -64,14 +62,9 @@ func launchAgentsDir() (dir string, err error) {
}

dir = filepath.Join(home, "Library", "LaunchAgents")

stat, err := os.Stat(dir)
if errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("Unexpected missing directory %s (%v)", dir, err)
}

if !stat.IsDir() {
return "", fmt.Errorf("Uh, %s exists but is not a directory somehow?", dir)
mkdirErr := os.MkdirAll(dir, 0700)
if mkdirErr != nil {
return "", fmt.Errorf("'%s' couldn't be created: %w", dir, err)
}
return
}

0 comments on commit 521cb61

Please sign in to comment.