diff options
| author | Elias Naur <mail@eliasnaur.com> | 2019-03-17 16:01:27 +0100 |
|---|---|---|
| committer | Elias Naur <mail@eliasnaur.com> | 2019-03-17 19:13:01 +0000 |
| commit | bedb6a18d855d1968a685ccd90c81a43b3def9fa (patch) | |
| tree | 0c1ce671a93d5c3ab473e105893c354d257030e1 /src | |
| parent | a734601bdf8a3e26c76afc42ffdc918ced687b7a (diff) | |
| download | go-bedb6a18d855d1968a685ccd90c81a43b3def9fa.tar.xz | |
os: only fallback to root directory if $HOME fails for UserHomeDir
UserHomeDir always returns "/" for platforms where the home directory
is not always well defined. However, the user might set HOME before
running a Go program on those platforms and on at least iOS, HOME
is actually set to something useful (the root of the app specific
writable directory).
This CL changes UserHomeDir to use the root directory "/" only if
$HOME is empty.
Change-Id: Icaa01de53cd585d527d9a23b1629375d6b7f67e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/167802
Run-TryBot: Elias Naur <mail@eliasnaur.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/os/file.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/os/file.go b/src/os/file.go index d880a37569..5f715f4275 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") } |
