Skip to content

Commit

Permalink
cache: add win32-background-launcher to the cached binaries
Browse files Browse the repository at this point in the history
on a released crc version the win32-background-laucher will be installed
in the install location of crc by the msi, but while using a non
installer version this'll help to download the win32-background-launcher
binary by running `crc setup`

this is also helpful for testing different versions of the background
launcher during development
  • Loading branch information
anjannath committed Nov 28, 2023
1 parent 96bd4c8 commit 89aeb34
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
26 changes: 26 additions & 0 deletions pkg/crc/cache/cache_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cache

import (
"fmt"
"strings"

"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/version"
"github.com/crc-org/crc/v2/pkg/os/windows/powershell"
)

func NewWin32BackgroundLauncherCache() *Cache {
url := constants.GetCRCWindowsBackgroundLauncherDownloadURL()
version := version.GetWin32BackgroundLauncherVersion()
return newCache(constants.Win32BackgroundLauncherPath(),
url,
version,
func(executable string) (string, error) {
stdOut, stdErr, err := powershell.Execute(fmt.Sprintf(`(Get-Item '%s').VersionInfo.FileVersion`, executable))
if err != nil {
return "", fmt.Errorf("unable to get version: %s: %w", stdErr, err)
}
return strings.TrimSpace(stdOut), nil
},
)
}
20 changes: 17 additions & 3 deletions pkg/crc/preflight/preflight_daemon_task_check_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/user"
"strings"

"github.com/crc-org/crc/v2/pkg/crc/cache"
"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/version"
Expand Down Expand Up @@ -188,9 +189,22 @@ func killDaemonProcessIfRunning() error {
return nil
}

func removeDaemonPoshScript() error {
if crcos.FileExists(daemonPoshScriptPath) {
return os.Remove(daemonPoshScriptPath)
func checkWin32BackgroundLauncherInstalled() error {
c := cache.NewWin32BackgroundLauncherCache()
return c.CheckVersion()
}

func fixWin32BackgroundLauncherInstalled() error {
c := cache.NewWin32BackgroundLauncherCache()
return c.EnsureIsCached()
}

func removeWin32BackgroundLauncher() error {
if version.IsInstaller() {
return nil
}
if crcos.FileExists(constants.Win32BackgroundLauncherPath()) {
return os.Remove(constants.Win32BackgroundLauncherPath())
}
return nil
}
11 changes: 11 additions & 0 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ var daemonTaskChecks = []Check{

labels: labels{Os: Windows},
},
{
configKeySuffix: "check-background-launcher-install",
checkDescription: "Checking if the win32 background launcher is installed",
check: checkWin32BackgroundLauncherInstalled,
fixDescription: "Installing the win32 background launcher",
fix: fixWin32BackgroundLauncherInstalled,
cleanupDescription: "Removing the win32 background launcher",
cleanup: removeWin32BackgroundLauncher,

labels: labels{Os: Windows},
},
{
configKeySuffix: "check-daemon-task-install",
checkDescription: "Checking if the daemon task is installed",
Expand Down

0 comments on commit 89aeb34

Please sign in to comment.