diff --git a/src/os/file.go b/src/os/file.go index d880a37569d..5f715f42752 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -445,6 +445,12 @@ func UserHomeDir() (string, error) { env, enverr = "USERPROFILE", "%userprofile%" case "plan9": env, enverr = "home", "$home" + } + if v := Getenv(env); v != "" { + return v, nil + } + // On some geese the home directory is not always defined. + switch runtime.GOOS { case "nacl", "android": return "/", nil case "darwin": @@ -452,9 +458,6 @@ func UserHomeDir() (string, error) { return "/", nil } } - if v := Getenv(env); v != "" { - return v, nil - } return "", errors.New(enverr + " is not defined") }