Commit 63044c41 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #35745 from rodcloutier/Support_Home_env_windows

Automatic merge from submit-queue Added support for HOME environment variable on Windows **What this PR does / why we need it**: On Windows the HOME environment variable should be taken in account when trying to find the home directory. Several tools already support the HOME environment variable, notably git-bash. It would be very convenient to have the kubernete tools (including minikube) to also support the environment variable. The current situation **Special notes for your reviewer**: **Release note**: ``` ```
parents b650149e 1027f358
...@@ -24,6 +24,13 @@ import ( ...@@ -24,6 +24,13 @@ import (
// HomeDir returns the home directory for the current user // HomeDir returns the home directory for the current user
func HomeDir() string { func HomeDir() string {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); len(home) > 0 {
if _, err := os.Stat(home); err == nil {
return home
}
}
if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 { if homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH"); len(homeDrive) > 0 && len(homePath) > 0 {
homeDir := homeDrive + homePath homeDir := homeDrive + homePath
if _, err := os.Stat(homeDir); err == nil { if _, err := os.Stat(homeDir); err == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment