Skip to content

Commit

Permalink
check value pf CRC_HOME_DIR environment variable while setting base d…
Browse files Browse the repository at this point in the history
…irectory
  • Loading branch information
vyasgun committed Apr 1, 2024
1 parent b379594 commit 7ff8f41
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const (
DefaultSSHUser = "core"
DefaultSSHPort = 22

CrcEnvPrefix = "CRC"
CrcEnvPrefix = "CRC"
CrcHomeDirEnvKey = "CRC_HOME_DIR"

ConfigFile = "crc.json"
LogFile = "crc.log"
Expand Down Expand Up @@ -103,7 +104,7 @@ func GetDefaultBundle(preset crcpreset.Preset) string {
}

var (
CrcBaseDir = filepath.Join(GetHomeDir(), ".crc")
CrcBaseDir = getBaseDir(filepath.Join(GetHomeDir(), ".crc"))
CrcBinDir = filepath.Join(CrcBaseDir, "bin")
CrcOcBinDir = filepath.Join(CrcBinDir, "oc")
CrcPodmanBinDir = filepath.Join(CrcBinDir, "podman")
Expand All @@ -119,6 +120,17 @@ var (
PasswdFilePath = filepath.Join(MachineInstanceDir, DefaultName, "passwd")
)

func getBaseDir(defaultDir string) string {
path := os.Getenv(CrcHomeDirEnvKey)
if path == "" {
return defaultDir
}
if _, err := os.Stat(path); err != nil {
return defaultDir
}
return path
}

func GetDefaultBundlePath(preset crcpreset.Preset) string {
return filepath.Join(MachineCacheDir, GetDefaultBundle(preset))
}
Expand Down

0 comments on commit 7ff8f41

Please sign in to comment.