mirror of
https://github.com/golang/go
synced 2024-11-23 06:40:05 -07:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
c53ff2818a
commit
f961272e59
@ -5991,3 +5991,26 @@ func TestDontReportRemoveOfEmptyDir(t *testing.T) {
|
||||
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() {
|
||||
if err != nil {
|
||||
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 {
|
||||
fmt.Fprintf(os.Stderr, "WORK=%s\n", b.WorkDir)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user