Skip to content

Commit

Permalink
preflight: macos: Use preexisting launchd helpers
Browse files Browse the repository at this point in the history
The preflight code to remove the daemon/tray launchd configuration
duplicate code which already exists in pkg/os/launchd.
  • Loading branch information
cfergeau authored and praveenkumar committed Mar 18, 2022
1 parent f0fcd50 commit 323dc8b
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions pkg/crc/preflight/preflight_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package preflight

import (
"fmt"
"os"
"path/filepath"

"github.com/code-ready/crc/pkg/crc/constants"
"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"
"github.com/code-ready/crc/pkg/os/launchd"
)

// SetupHost performs the prerequisite checks and setups the host to run the cluster
Expand Down Expand Up @@ -72,21 +70,16 @@ var trayLaunchdCleanupChecks = []Check{
configKeySuffix: "check-old-autostart",
checkDescription: "Checking if old launchd config for tray autostart exists",
check: func() error {
if crcos.FileExists(filepath.Join(constants.GetHomeDir(), "Library", "LaunchAgents", "crc.tray.plist")) {
if launchd.PlistExists("crc.tray") {
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
_ = launchd.RemovePlist("crc.tray")
_ = launchd.RemovePlist("crc.daemon")
return nil
},

labels: labels{Os: Darwin},
Expand Down

0 comments on commit 323dc8b

Please sign in to comment.