]> Cypherpunks repositories - gostls13.git/commitdiff
os/user: fake Current on Android
authorElias Naur <elias.naur@gmail.com>
Wed, 8 Mar 2017 20:56:57 +0000 (21:56 +0100)
committerElias Naur <elias.naur@gmail.com>
Wed, 8 Mar 2017 21:34:32 +0000 (21:34 +0000)
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 <elias.naur@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/os/user/lookup_stubs.go
src/os/user/user_test.go

index 7279617248cf9e33efa7831e3357cfc1a1c7c5a1..d23870fda883b73948c1529322990fe0bf3e3635 100644 (file)
@@ -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
index 8a12d622739b4e0b876bf3413b552ea1a33d6844..b3aeed883cdeb7fc471dea3233fafa6fcaa996a6 100644 (file)
@@ -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)