Skip to content

Commit

Permalink
Merge pull request #24 from mbrancato/master
Browse files Browse the repository at this point in the history
Shift up the preference of the USERPROFILE variable
  • Loading branch information
mitchellh committed Aug 1, 2018
2 parents 3864e76 + 32e698a commit d26f376
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 d26f376

Please sign in to comment.