From: Elias Naur Date: Wed, 8 Mar 2017 20:56:57 +0000 (+0100) Subject: os/user: fake Current on Android X-Git-Tag: go1.9beta1~1230 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=228438e0973b688829fdd601e31352920a5914f4;p=gostls13.git os/user: fake Current on Android On Android devices where the stub fallback for Current fails to extract a User from the environment, return a dummy fallback instead of failing. While we're here, use / instead of /home/nacl for the NaCL fallback. Hopefully fixes the Android builder. Change-Id: Ia29304fbc224ee5f9c0f4e706d1756f765a7eae5 Reviewed-on: https://go-review.googlesource.com/37960 Run-TryBot: Elias Naur Reviewed-by: Brad Fitzpatrick --- diff --git a/src/os/user/lookup_stubs.go b/src/os/user/lookup_stubs.go index 7279617248..d23870fda8 100644 --- a/src/os/user/lookup_stubs.go +++ b/src/os/user/lookup_stubs.go @@ -26,7 +26,9 @@ func current() (*User, error) { Name: "", // ignored HomeDir: os.Getenv("HOME"), } - if runtime.GOOS == "nacl" { + // On NaCL and Android, return a dummy user instead of failing. + switch runtime.GOOS { + case "nacl": if u.Uid == "" { u.Uid = "1" } @@ -34,7 +36,17 @@ func current() (*User, error) { u.Username = "nacl" } if u.HomeDir == "" { - u.HomeDir = "/home/nacl" + u.HomeDir = "/" + } + case "android": + if u.Uid == "" { + u.Uid = "1" + } + if u.Username == "" { + u.Username = "android" + } + if u.HomeDir == "" { + u.HomeDir = "/sdcard" } } // cgo isn't available, but if we found the minimum information diff --git a/src/os/user/user_test.go b/src/os/user/user_test.go index 8a12d62273..b3aeed883c 100644 --- a/src/os/user/user_test.go +++ b/src/os/user/user_test.go @@ -16,9 +16,6 @@ func checkUser(t *testing.T) { } func TestCurrent(t *testing.T) { - if runtime.GOOS == "android" { - t.Skipf("skipping on %s", runtime.GOOS) - } u, err := Current() if err != nil { t.Fatalf("Current: %v (got %#v)", err, u)