Skip to content

Commit

Permalink
constants: Use os.UserHomeDir()
Browse files Browse the repository at this point in the history
constants.GetHomeDir() is duplicating what os.UserHomeDir() provides.
One difference is that it favours HOMEDRIVE/HOMEPATH over USERPROFILE,
but these are deprecated, see
mitchellh/go-homedir#23 for example.
  • Loading branch information
cfergeau authored and praveenkumar committed Jul 14, 2021
1 parent d7a73b6 commit fb92b11
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions pkg/crc/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,9 @@ func BinDir() string {

// GetHomeDir returns the home directory for the current user
func GetHomeDir() string {
if runtime.GOOS == "windows" {
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 {
homeDir := filepath.Join(homeDrive, homePath)
if _, err := os.Stat(homeDir); err == nil {
return homeDir
}
}
if userProfile := os.Getenv("USERPROFILE"); len(userProfile) > 0 {
if _, err := os.Stat(userProfile); err == nil {
return userProfile
}
}
}
return os.Getenv("HOME")
homeDir, _ := os.UserHomeDir()

return homeDir
}

// EnsureBaseDirectoryExists create the ~/.crc directory if it is not present
Expand Down

0 comments on commit fb92b11

Please sign in to comment.