Skip to content

Commit

Permalink
Mac Preflight: Check if plist file exist before removing it
Browse files Browse the repository at this point in the history
This patch will first check if the plist file exist before error out
for check function and also remove it in fix function. This will fix
following error for preflight on mac.
```
INFO Checking if old launchd config for tray autostart exists
DEBU force trigger cleanup to remove old launchd config for tray
force trigger cleanup to remove old launchd config for tray
```
  • Loading branch information
praveenkumar authored and anjannath committed Mar 14, 2022
1 parent 3fa893b commit 48be4d4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/code-ready/crc/pkg/crc/network"
"github.com/code-ready/crc/pkg/crc/preset"
crcpreset "github.com/code-ready/crc/pkg/crc/preset"
crcos "github.com/code-ready/crc/pkg/os"
)

// SetupHost performs the prerequisite checks and setups the host to run the cluster
Expand Down Expand Up @@ -70,13 +71,23 @@ var trayLaunchdCleanupChecks = []Check{
{
configKeySuffix: "check-old-autostart",
checkDescription: "Checking if old launchd config for tray autostart exists",
check: func() error { return fmt.Errorf("force trigger cleanup to remove old launchd config for tray") },
fixDescription: "Removing old launchd config for tray autostart",
fix: func() error {
_ = os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist"))
_ = os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.daemon.plist"))
check: func() error {
if crcos.FileExists(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist")) {
return fmt.Errorf("force trigger cleanup to remove old launchd config for tray")
}
return nil
},
fixDescription: "Removing old launchd config for tray autostart",
fix: func() error {
var err error
if crcos.FileExists(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist")) {
err = os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist"))
}
if crcos.FileExists(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.daemon.plist")) {
err = os.Remove(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.daemon.plist"))
}
return err
},

labels: labels{Os: Darwin},
},
Expand Down

0 comments on commit 48be4d4

Please sign in to comment.