Skip to content

Commit

Permalink
preflight: accept lower case drive letter in daemon posh script check
Browse files Browse the repository at this point in the history
in the preflight check for existence of the powershell script used for
starting the daemon, we check that the current crc executable path  is
present

when crc is executed by the extension, the current executable path   is
returned with a small case drive letter whereas crc directly invoked by
a user returns a path with upper case drive letter and fails this check

with this commit we are not matching the whole content of the file but
only checking if either lower case or upper case varient of the   path
exists in the script
  • Loading branch information
anjannath committed Sep 25, 2023
1 parent 7e6b566 commit 5ede7d3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/crc/preflight/preflight_daemon_task_check_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/user"
"path/filepath"
"regexp"
"strings"

"github.com/crc-org/crc/v2/pkg/crc/constants"
Expand Down Expand Up @@ -217,9 +218,25 @@ func getDaemonPoshScriptContent() []byte {
func checkDaemonPoshScript() error {
if exists := crcos.FileExists(daemonPoshScriptPath); exists {
// check the script contains the path to the current executable
if err := crcos.FileContentMatches(daemonPoshScriptPath, getDaemonPoshScriptContent()); err == nil {
return nil
binPath, err := os.Executable()
if err != nil {
return fmt.Errorf("Unable to find the crc executable: %w", err)
}
binPath = strings.ReplaceAll(binPath, `\`, `\\`)
regx, err := regexp.Compile(fmt.Sprintf("[a-zA-Z]:\\%s", binPath[3:]))
if err != nil {
return fmt.Errorf("Error while compiling regex for crc exe path: %w", err)
}
f, err := os.ReadFile(daemonPoshScriptPath)
if err != nil {
return fmt.Errorf("Unable to read script file: %w", err)
}
match := regx.Find(f)
if len(match) == 0 {
return fmt.Errorf("crc executable path is not present in script")
}
logging.Debugf("Found crc executable path in script: %s", string(match))
return nil
}
return fmt.Errorf("Powershell script for running the daemon does not exist")
}
Expand Down

0 comments on commit 5ede7d3

Please sign in to comment.