aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaokun Lee <nototon@gmail.com>2019-02-28 16:40:11 +0800
committerIan Lance Taylor <iant@golang.org>2019-03-01 05:09:48 +0000
commit162b3610e62f2e55e4048f2f72273a58e152236e (patch)
treef9d2650917b0cbfa7c491b1470ffa4b1c50fa6d6
parenta2884af3b6ebe64b884520cab7a7af85aa3b8e79 (diff)
downloadgo-162b3610e62f2e55e4048f2f72273a58e152236e.tar.gz
go-162b3610e62f2e55e4048f2f72273a58e152236e.zip
[release-branch.go1.12] cmd/go/internal/cache: disable builds if GOCACHE is not an absolute path
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 #30493 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> (cherry picked from commit 13d24b685a6d7b05a249f85be91c390f5595f745) Reviewed-on: https://go-review.googlesource.com/c/164717 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r--src/cmd/go/internal/cache/default.go7
-rw-r--r--src/cmd/go/testdata/script/build_nocache.txt5
2 files changed, 11 insertions, 1 deletions
diff --git a/src/cmd/go/internal/cache/default.go b/src/cmd/go/internal/cache/default.go
index f545c14700..7d389c3c1a 100644
--- a/src/cmd/go/internal/cache/default.go
+++ b/src/cmd/go/internal/cache/default.go
@@ -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
}
diff --git a/src/cmd/go/testdata/script/build_nocache.txt b/src/cmd/go/testdata/script/build_nocache.txt
index 5aa46e0b77..d1b12f4e36 100644
--- a/src/cmd/go/testdata/script/build_nocache.txt
+++ b/src/cmd/go/testdata/script/build_nocache.txt
@@ -10,6 +10,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