]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: if unable to initialize cache, just disable it
authorIan Lance Taylor <iant@golang.org>
Wed, 31 Jan 2018 18:02:01 +0000 (10:02 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 31 Jan 2018 19:35:00 +0000 (19:35 +0000)
Fixes #23638

Change-Id: I51967290448217f371fc7aba9259918ee9857143
Reviewed-on: https://go-review.googlesource.com/91097
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/go_test.go
src/cmd/go/internal/cache/default.go

index 08384825cac99edd4bf19390f3ecf8d62ecab2a7..b2053f553c7c7ec08067e42dd9a7bf614d15b501 100644 (file)
@@ -5373,6 +5373,26 @@ func TestTestCacheInputs(t *testing.T) {
        }
 }
 
+func TestNoCache(t *testing.T) {
+       switch runtime.GOOS {
+       case "windows":
+               t.Skipf("no unwritable directories on %s", runtime.GOOS)
+       }
+       if os.Getuid() == 0 {
+               t.Skip("skipping test because running as root")
+       }
+
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.tempFile("triv.go", `package main; func main() {}`)
+       tg.must(os.MkdirAll(tg.path("unwritable"), 0555))
+       tg.setenv("HOME", tg.path(filepath.Join("unwritable", "home")))
+       tg.unsetenv("GOCACHE")
+       tg.run("build", "-o", tg.path("triv"), tg.path("triv.go"))
+       tg.grepStderr("disabling cache", "did not disable cache")
+}
+
 func TestTestVet(t *testing.T) {
        tooSlow(t)
        tg := testgo(t)
index 8285f787d4c9cae46b178f6ecee94ae538fdcfbe..97283762258d659c0a6fcacc5d9c32fe80eebc88 100644 (file)
@@ -5,7 +5,7 @@
 package cache
 
 import (
-       "cmd/go/internal/base"
+       "fmt"
        "io/ioutil"
        "os"
        "path/filepath"
@@ -40,7 +40,8 @@ func initDefaultCache() {
                return
        }
        if err := os.MkdirAll(dir, 0777); err != nil {
-               base.Fatalf("initializing cache in $GOCACHE: %s", err)
+               fmt.Fprintf(os.Stderr, "go: disabling cache (%s) due to initialization failure: %s\n", dir, err)
+               return
        }
        if _, err := os.Stat(filepath.Join(dir, "README")); err != nil {
                // Best effort.
@@ -49,7 +50,8 @@ func initDefaultCache() {
 
        c, err := Open(dir)
        if err != nil {
-               base.Fatalf("initializing cache in $GOCACHE: %s", err)
+               fmt.Fprintf(os.Stderr, "go: disabling cache (%s) due to initialization failure: %s\n", dir, err)
+               return
        }
        defaultCache = c
 }