I often create dummy files holding various data named things like 'z'.
If a file (not directory) GOROOT/src/z exists, it confuses cmd/go into
thinking z is a standard library package, which breaks the test
Script/mod_vendor.
This CL fixes internal/goroot to only report that something is a standard
library package when a directory with that name exists, not just a file.
Change-Id: I986c9a425e78d23c7e033aeadb8e9f71aab2b878
Reviewed-on: https://go-review.googlesource.com/c/go/+/461955
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
--- /dev/null
+# Files in src should not be treated as packages
+
+exists $GOROOT/src/regexp/testdata/README
+go list -f '{{.Dir}}' regexp/testdata/README
+
+-- go.mod --
+module regexp/testdata/README
+-- p.go --
+package p
switch compiler {
case "gc":
dir := filepath.Join(goroot, "src", path)
- _, err := os.Stat(dir)
- return err == nil
+ info, err := os.Stat(dir)
+ return err == nil && info.IsDir()
case "gccgo":
return gccgoSearch.isStandard(path)
default: