aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/import.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2020-01-24 17:21:48 -0500
committerMichael Matloob <matloob@golang.org>2020-02-25 22:42:00 +0000
commit0652c80e2afa14d62067be567c498c83a6485fd8 (patch)
tree84cc4c05a84c2dc2ca84d93430898c79c6311eca /src/cmd/go/internal/modload/import.go
parentf0ee49b5bcde39ac6c36d3837666aa9a36383066 (diff)
downloadgo-0652c80e2afa14d62067be567c498c83a6485fd8.tar.gz
go-0652c80e2afa14d62067be567c498c83a6485fd8.zip
cmd/go: emit an error for extraneous files in GOROOT/src in module mode
If there's a go file immediately in GOROOT/src, it was probably accidentally added by the user. Since that package shouldn't exist, return an error if a user tries to list it. We're only making this change for GOPATH mode because we don't want to break cases where users have been doing this historically, but want to fix this case for the future. This also leaves open the weird cases where files are placed directly in vendor directories. Fixes #36587 Change-Id: I9738e47b1e89fd5048cbb8dd28e44648834b8ea7 Reviewed-on: https://go-review.googlesource.com/c/go/+/216381 Run-TryBot: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/import.go')
-rw-r--r--src/cmd/go/internal/modload/import.go2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index d7fca8fd2c..309d654987 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -126,6 +126,8 @@ func Import(path string) (m module.Version, dir string, err error) {
}
dir := filepath.Join(cfg.GOROOT, "src", path)
return module.Version{}, dir, nil
+ } else if pathIsStd && path == cfg.GOROOTsrc {
+ return module.Version{}, dir, errors.New("directory should not directly contain source files")
}
// -mod=vendor is special.