]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/cache: disable builds if GOCACHE is not an absolute path
authorBaokun Lee <nototon@gmail.com>
Thu, 28 Feb 2019 08:40:11 +0000 (16:40 +0800)
committerBryan C. Mills <bcmills@google.com>
Fri, 1 Mar 2019 02:23:02 +0000 (02:23 +0000)
If GOCACHE is set but is not an absolute path, we cannot build.
And GOCACHE=off also returns the error message "build cache is
disabled by GOCACHE=off".

Fixes #30447

Change-Id: I24f64bc886599ca0acd757acada4714aebe4d3ae
Reviewed-on: https://go-review.googlesource.com/c/164200
Run-TryBot: Baokun Lee <nototon@gmail.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/cache/default.go
src/cmd/go/testdata/script/build_nocache.txt

index f545c147009f247e3dbc25c76efe68940391bc11..7d389c3c1af9f13b16429480924f6d1709b9aa42 100644 (file)
@@ -37,7 +37,7 @@ See golang.org to learn more about Go.
 // the first time Default is called.
 func initDefaultCache() {
        dir := DefaultDir()
-       if dir == "off" || dir == "" {
+       if dir == "off" {
                if defaultDirErr != nil {
                        base.Fatalf("build cache is required, but could not be located: %v", defaultDirErr)
                }
@@ -74,7 +74,12 @@ func DefaultDir() string {
 
        defaultDirOnce.Do(func() {
                defaultDir = os.Getenv("GOCACHE")
+               if filepath.IsAbs(defaultDir) || defaultDir == "off" {
+                       return
+               }
                if defaultDir != "" {
+                       defaultDir = "off"
+                       defaultDirErr = fmt.Errorf("GOCACHE is not an absolute path")
                        return
                }
 
index 46e95fa89d0e23af8afc56f03f553682478bba33..1059cad45c7a2bbfeef28a56c69d70fc1a78bbfc 100644 (file)
@@ -12,6 +12,11 @@ env HOME=
 ! go build -o triv triv.go
 stderr 'build cache is required, but could not be located: GOCACHE is not defined and .*'
 
+# If GOCACHE is set but is not an absolute path, and we cannot build.
+env GOCACHE=test
+! go build -o triv triv.go
+stderr 'build cache is required, but could not be located: GOCACHE is not an absolute path'
+
 # An explicit GOCACHE=off also disables builds.
 env GOCACHE=off
 ! go build -o triv triv.go