Skip to content

Commit

Permalink
feat: fail if launch daemon already exists when installing
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie0129 committed Apr 5, 2023
1 parent d76d3b3 commit b8d11be
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func installDaemon() error {
return fmt.Errorf("failed to create /Library/LaunchDaemons: %w", err)
}

// warn if the file already exists
_, err = os.Stat("/Library/LaunchDaemons/cc.chlc.batt.plist")
if err == nil {
logrus.Errorf("/Library/LaunchDaemons/cc.chlc.batt.plist already exists")
return fmt.Errorf("/Library/LaunchDaemons/cc.chlc.batt.plist already exists. To avoid overwriting it, please remove it manually and try again")
}

err = os.WriteFile("/Library/LaunchDaemons/cc.chlc.batt.plist", []byte(tmpl), 0644)
if err != nil {
return fmt.Errorf("failed to write /Library/LaunchDaemons/cc.chlc.batt.plist: %w", err)
Expand Down

0 comments on commit b8d11be

Please sign in to comment.