diff options
author | Russ Cox <rsc@golang.org> | 2018-08-10 16:28:48 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2018-08-17 19:22:03 +0000 |
commit | 64fae252868fe6ab97f743cfadcb54cee8ccca02 (patch) | |
tree | 566984e073a5c5a7984a328d7c39d18ab1405c1c /src/cmd/go/internal/modload/load.go | |
parent | 8dd27b1864f334fa82e0ead5bd8b9448e295e316 (diff) | |
download | go-64fae252868fe6ab97f743cfadcb54cee8ccca02.tar.gz go-64fae252868fe6ab97f743cfadcb54cee8ccca02.zip |
cmd/go: do not turn list ./nonexist into a network lookup
If you're in a directory corresponding to x/y
and you run go list ./z, we do at some point
want to turn that into x/y/z. But if ./z does
not exist that will make the go command
check the network to see if it can find x/y/z.
That's clearly wrong: ./z means that directory,
nothing else. And it turns a typo into a long delay,
which is even worse.
Fixes #26874.
Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
Reviewed-on: https://go-review.googlesource.com/129061
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index b00f81458f..5ca2ed2d10 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -116,10 +116,24 @@ func ImportPaths(patterns []string) []*search.Match { } else if path := pathInModuleCache(dir); path != "" { pkg = path } else { + pkg = "" if !iterating { base.Errorf("go: directory %s outside available modules", base.ShortPath(dir)) } + } + info, err := os.Stat(dir) + if err != nil || !info.IsDir() { + // If the directory does not exist, + // don't turn it into an import path + // that will trigger a lookup. pkg = "" + if !iterating { + if err != nil { + base.Errorf("go: no such directory %v", m.Pattern) + } else { + base.Errorf("go: %s is not a directory", m.Pattern) + } + } } m.Pkgs[i] = pkg } |