mitchellh/go-homedir

Prefer USERPROFILE over HOMEDRIVE/HOMEPATH

mbrancato opened this issue · 1 comments

I originally opened this in a downstream terraform provider including go-homedir as a dependency. The main issue is that HOMEDRIVE/HOMEPATH are relics of NT4 and not standard environment variables post Windows Vista. They appear to exist sometimes in environments with a history of roaming profiles.

You may read the explanation in the original issue: hashicorp/terraform-provider-azurerm#1395

This document has a table of standard environment variables on Windows: https://msdn.microsoft.com/en-us/library/dd378457(v=vs.85).aspx

go-homedir/homedir.go

Lines 138 to 155 in 3864e76

func dirWindows() (string, error) {
// First prefer the HOME environmental variable
if home := os.Getenv("HOME"); 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 home, nil
}

This makes sense to me! Thanks for pointing it out.