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 21, 2023
1 parent 8a1a91f commit da98ad6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ require (
libvirt.org/go/libvirtxml v1.9004.0
)

require golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
Expand All @@ -76,6 +78,7 @@ require (
github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 // indirect
github.com/apcera/gssapi v0.0.0-00010101000000-000000000000 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/bi-zone/go-fileversion v1.0.0
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bi-zone/go-fileversion v1.0.0 h1:N/sorBKYfWDjT5ySlUOxSJvG3g9XiaBKxXgHGfH5Wf8=
github.com/bi-zone/go-fileversion v1.0.0/go.mod h1:evMpx4TA/iTAtufWYK271/Mbr5JAL24vlu1WNjVef6s=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
Expand Down Expand Up @@ -1102,6 +1104,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand Down
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
}
14 changes: 7 additions & 7 deletions pkg/crc/preflight/preflight_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ var daemonTaskChecks = []Check{
labels: labels{Os: Windows},
},
{
configKeySuffix: "check-daemon-task-posh-script-present",
checkDescription: "Checking if the daemon task powershell script is present",
check: checkDaemonPoshScript,
fixDescription: "Creating the daemon task powershell script",
fix: fixDaemonPoshScript,
cleanupDescription: "Removing the daemon task powershell script",
cleanup: removeDaemonPoshScript,
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},
},
Expand Down

0 comments on commit da98ad6

Please sign in to comment.