Commit f961272e authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: reject relative tmpdir

Fixes #23264

Change-Id: Ib6c343dc8e32949c6de72cb628cace2e8fabc302
Reviewed-on: https://go-review.googlesource.com/103236
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent c53ff281
...@@ -5991,3 +5991,26 @@ func TestDontReportRemoveOfEmptyDir(t *testing.T) { ...@@ -5991,3 +5991,26 @@ func TestDontReportRemoveOfEmptyDir(t *testing.T) {
t.Error("unnecessary output when installing installed package") t.Error("unnecessary output when installing installed package")
} }
} }
// Issue 23264.
func TestNoRelativeTmpdir(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.tempFile("src/a/a.go", `package a`)
tg.cd(tg.path("."))
tg.must(os.Mkdir("tmp", 0777))
tg.setenv("GOCACHE", "off")
tg.setenv("GOPATH", tg.path("."))
tg.setenv("GOTMPDIR", "tmp")
tg.runFail("build", "a")
tg.grepStderr("relative tmpdir", "wrong error")
if runtime.GOOS != "windows" && runtime.GOOS != "plan9" {
tg.unsetenv("GOTMPDIR")
tg.setenv("TMPDIR", "tmp")
tg.runFail("build", "a")
tg.grepStderr("relative tmpdir", "wrong error")
}
}
...@@ -223,6 +223,10 @@ func (b *Builder) Init() { ...@@ -223,6 +223,10 @@ func (b *Builder) Init() {
if err != nil { if err != nil {
base.Fatalf("%s", err) base.Fatalf("%s", err)
} }
if !filepath.IsAbs(b.WorkDir) {
os.RemoveAll(b.WorkDir)
base.Fatalf("cmd/go: relative tmpdir not supported")
}
if cfg.BuildX || cfg.BuildWork { if cfg.BuildX || cfg.BuildWork {
fmt.Fprintf(os.Stderr, "WORK=%s\n", b.WorkDir) fmt.Fprintf(os.Stderr, "WORK=%s\n", b.WorkDir)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment