aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2018-11-28 16:33:23 -0500
committerJay Conrod <jayconrod@google.com>2018-12-04 00:19:55 +0000
commitc2412a7681d5beaeb5a4ceef3b2b7886361282ce (patch)
treeb0aff60ecdbff2ab7874173940c70a8a657d8d55 /src/cmd/go/internal/modload/load.go
parent58ffe5059fa73b1f35aa354bb4d0ca97601606fb (diff)
downloadgo-c2412a7681d5beaeb5a4ceef3b2b7886361282ce.tar.gz
go-c2412a7681d5beaeb5a4ceef3b2b7886361282ce.zip
cmd/go: emit go list error for local non-existant packages
In CL 129061, a check was added for patterns that reference nonexistent local directories. While this prevented unnecessary network lookups (fixing #26874), it caused "go list -e" to exit with an error instead of listing packages with error messages. This change avoids the network lookup and does not exit for these kinds of packages. Errors are still reported by internal/load.LoadImport for packages that don't exist. Fixes #28023 Change-Id: I0a648269e437aed3a95bfb05461a397264f3793f Reviewed-on: https://go-review.googlesource.com/c/151800 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r--src/cmd/go/internal/modload/load.go20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index dd1a370825..5bb943dd6d 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -90,7 +90,7 @@ func ImportPaths(patterns []string) []*search.Match {
// the exact version of a particular module increases during
// the loader iterations.
m.Pkgs = str.StringList(fsDirs[i])
- for i, pkg := range m.Pkgs {
+ for j, pkg := range m.Pkgs {
dir := pkg
if !filepath.IsAbs(dir) {
dir = filepath.Join(cwd, pkg)
@@ -124,19 +124,15 @@ func ImportPaths(patterns []string) []*search.Match {
}
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)
- }
+ // If the directory is local but does not exist, don't return it
+ // while loader is iterating, since this would trigger a fetch.
+ // After loader is done iterating, we still need to return the
+ // path, so that "go list -e" produces valid output.
+ if iterating {
+ pkg = ""
}
}
- m.Pkgs[i] = pkg
+ m.Pkgs[j] = pkg
}
case strings.Contains(m.Pattern, "..."):