Skip to content

Commit

Permalink
Shift up the preference of the USERPROFILE variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrancato committed Jun 23, 2018
1 parent 3864e76 commit 32e698a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions homedir.go
Expand Up @@ -141,14 +141,16 @@ func dirWindows() (string, error) {
return home, nil
}

// Prefer standard environment variable USERPROFILE
if home := os.Getenv("USERPROFILE"); home != "" {
return home, nil
}

drive := os.Getenv("HOMEDRIVE")
path := os.Getenv("HOMEPATH")
home := drive + path
if drive == "" || path == "" {
home = os.Getenv("USERPROFILE")
}
if home == "" {
return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank")
return "", errors.New("HOMEDRIVE, HOMEPATH, or USERPROFILE are blank")
}

return home, nil
Expand Down

0 comments on commit 32e698a

Please sign in to comment.