[go] cmd/go: do not turn list ./nonexist into a network lookup

28 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
Aug 10, 2018, 5:02:51 PM8/10/18
to Alan Donovan, Ian Lance Taylor, goph...@pubsubhelper.golang.org, Russ Cox, golang-co...@googlegroups.com

Russ Cox would like Alan Donovan to review this change.

View Change

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
---
M src/cmd/go/internal/modload/load.go
M src/cmd/go/testdata/script/mod_fs_patterns.txt
M src/cmd/go/testdata/script/mod_list_dir.txt
3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index d64f490..414fb05 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -116,10 +116,24 @@
} 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
}
diff --git a/src/cmd/go/testdata/script/mod_fs_patterns.txt b/src/cmd/go/testdata/script/mod_fs_patterns.txt
index b5350c3..d7d3e03 100644
--- a/src/cmd/go/testdata/script/mod_fs_patterns.txt
+++ b/src/cmd/go/testdata/script/mod_fs_patterns.txt
@@ -28,6 +28,18 @@
stdout ^m/y$
! stdout ^m/y/z

+# non-existent directory should not prompt lookups
+! go build -mod=readonly example.com/nonexist
+stderr 'import lookup disabled'
+
+! go build -mod=readonly ./nonexist
+! stderr 'import lookup disabled'
+stderr '^go: no such directory ./nonexist'
+
+! go build -mod=readonly ./go.mod
+! stderr 'import lookup disabled'
+stderr '^go: ./go.mod is not a directory'
+
-- x/go.mod --
module m

diff --git a/src/cmd/go/testdata/script/mod_list_dir.txt b/src/cmd/go/testdata/script/mod_list_dir.txt
index 29cde71..800f277 100644
--- a/src/cmd/go/testdata/script/mod_list_dir.txt
+++ b/src/cmd/go/testdata/script/mod_list_dir.txt
@@ -9,11 +9,14 @@
stdout ^math$
go list -f '{{.ImportPath}}' .
stdout ^x$
+! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/qu...@v1.5.2
+stderr '^go: no such directory.*qu...@v1.5.2'
+go mod download rsc.io/qu...@v1.5.2
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/qu...@v1.5.2
stdout '^rsc.io/quote$'
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sam...@v1.3.0
stdout '^rsc.io/sampler$'
-go get rsc.io/sam...@v1.3.1
+go get -d rsc.io/sam...@v1.3.1
go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sam...@v1.3.1
stdout '^rsc.io/sampler$'
! go list -f '{{.ImportPath}}' $GOPATH/pkg/mod/rsc.io/sam...@v1.3.0

To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
Gerrit-Change-Number: 129061
Gerrit-PatchSet: 1
Gerrit-Owner: Russ Cox <r...@golang.org>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-MessageType: newchange

Gobot Gobot (Gerrit)

unread,
Aug 10, 2018, 5:03:00 PM8/10/18
to Russ Cox, goph...@pubsubhelper.golang.org, Alan Donovan, golang-co...@googlegroups.com

TryBots beginning. Status page: https://farmer.golang.org/try?commit=70c6b00f

View Change

    To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
    Gerrit-Change-Number: 129061
    Gerrit-PatchSet: 1
    Gerrit-Owner: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-CC: Gobot Gobot <go...@golang.org>
    Gerrit-Comment-Date: Fri, 10 Aug 2018 21:02:58 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Gobot Gobot (Gerrit)

    unread,
    Aug 10, 2018, 5:13:03 PM8/10/18
    to Russ Cox, goph...@pubsubhelper.golang.org, Alan Donovan, golang-co...@googlegroups.com

    TryBots are happy.

    Patch set 1:TryBot-Result +1

    View Change

      To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
      Gerrit-Change-Number: 129061
      Gerrit-PatchSet: 1
      Gerrit-Owner: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Fri, 10 Aug 2018 21:13:01 +0000
      Gerrit-HasComments: No
      Gerrit-Has-Labels: Yes
      Gerrit-MessageType: comment

      Russ Cox (Gerrit)

      unread,
      Aug 17, 2018, 10:55:16 AM8/17/18
      to Russ Cox, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Gobot Gobot, Alan Donovan, golang-co...@googlegroups.com

      Uploaded patch set 2: Patch Set 1 was rebased.

      View Change

        To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
        Gerrit-Change-Number: 129061
        Gerrit-PatchSet: 2
        Gerrit-Owner: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: Alan Donovan <adon...@google.com>
        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Fri, 17 Aug 2018 14:55:11 +0000

        Gobot Gobot (Gerrit)

        unread,
        Aug 17, 2018, 10:55:28 AM8/17/18
        to Russ Cox, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Alan Donovan, golang-co...@googlegroups.com

        TryBots beginning. Status page: https://farmer.golang.org/try?commit=0678631a

        View Change

          To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
          Gerrit-Change-Number: 129061
          Gerrit-PatchSet: 2
          Gerrit-Owner: Russ Cox <r...@golang.org>
          Gerrit-Reviewer: Alan Donovan <adon...@google.com>
          Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Reviewer: Russ Cox <r...@golang.org>
          Gerrit-Comment-Date: Fri, 17 Aug 2018 14:55:25 +0000

          Gobot Gobot (Gerrit)

          unread,
          Aug 17, 2018, 11:08:46 AM8/17/18
          to Russ Cox, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Alan Donovan, golang-co...@googlegroups.com

          TryBots are happy.

          Patch set 2:TryBot-Result +1

          View Change

            To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
            Gerrit-Change-Number: 129061
            Gerrit-PatchSet: 2
            Gerrit-Owner: Russ Cox <r...@golang.org>
            Gerrit-Reviewer: Alan Donovan <adon...@google.com>
            Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
            Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Reviewer: Russ Cox <r...@golang.org>
            Gerrit-Comment-Date: Fri, 17 Aug 2018 15:08:44 +0000

            Russ Cox (Gerrit)

            unread,
            Aug 17, 2018, 12:41:37 PM8/17/18
            to Russ Cox, goph...@pubsubhelper.golang.org, Gobot Gobot, Ian Lance Taylor, Alan Donovan, golang-co...@googlegroups.com

            Uploaded patch set 3: Patch Set 2 was rebased.

            View Change

              To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
              Gerrit-Change-Number: 129061
              Gerrit-PatchSet: 3
              Gerrit-Owner: Russ Cox <r...@golang.org>
              Gerrit-Reviewer: Alan Donovan <adon...@google.com>
              Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
              Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
              Gerrit-Reviewer: Russ Cox <r...@golang.org>
              Gerrit-Comment-Date: Fri, 17 Aug 2018 16:41:33 +0000

              Gobot Gobot (Gerrit)

              unread,
              Aug 17, 2018, 12:41:48 PM8/17/18
              to Russ Cox, goph...@pubsubhelper.golang.org, Ian Lance Taylor, Alan Donovan, golang-co...@googlegroups.com

              TryBots beginning. Status page: https://farmer.golang.org/try?commit=6ace043d

              View Change

                To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                Gerrit-Project: go
                Gerrit-Branch: master
                Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                Gerrit-Change-Number: 129061
                Gerrit-PatchSet: 3
                Gerrit-Owner: Russ Cox <r...@golang.org>
                Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                Gerrit-Reviewer: Russ Cox <r...@golang.org>
                Gerrit-Comment-Date: Fri, 17 Aug 2018 16:41:45 +0000

                Alan Donovan (Gerrit)

                unread,
                Aug 17, 2018, 12:46:12 PM8/17/18
                to Russ Cox, goph...@pubsubhelper.golang.org, Gobot Gobot, Ian Lance Taylor, golang-co...@googlegroups.com

                Patch set 3:Code-Review +2

                View Change

                  To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                  Gerrit-Project: go
                  Gerrit-Branch: master
                  Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                  Gerrit-Change-Number: 129061
                  Gerrit-PatchSet: 3
                  Gerrit-Owner: Russ Cox <r...@golang.org>
                  Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                  Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                  Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                  Gerrit-Reviewer: Russ Cox <r...@golang.org>
                  Gerrit-Comment-Date: Fri, 17 Aug 2018 16:46:10 +0000

                  Gobot Gobot (Gerrit)

                  unread,
                  Aug 17, 2018, 12:56:28 PM8/17/18
                  to Russ Cox, goph...@pubsubhelper.golang.org, Alan Donovan, Ian Lance Taylor, golang-co...@googlegroups.com

                  TryBots are happy.

                  Patch set 3:TryBot-Result +1

                  View Change

                    To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                    Gerrit-Project: go
                    Gerrit-Branch: master
                    Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                    Gerrit-Change-Number: 129061
                    Gerrit-PatchSet: 3
                    Gerrit-Owner: Russ Cox <r...@golang.org>
                    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                    Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                    Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                    Gerrit-Reviewer: Russ Cox <r...@golang.org>
                    Gerrit-Comment-Date: Fri, 17 Aug 2018 16:56:26 +0000

                    Russ Cox (Gerrit)

                    unread,
                    Aug 17, 2018, 2:57:14 PM8/17/18
                    to Russ Cox, goph...@pubsubhelper.golang.org, Gobot Gobot, Alan Donovan, Ian Lance Taylor, golang-co...@googlegroups.com

                    Uploaded patch set 4: Patch Set 3 was rebased.

                    View Change

                      To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                      Gerrit-Project: go
                      Gerrit-Branch: master
                      Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                      Gerrit-Change-Number: 129061
                      Gerrit-PatchSet: 4
                      Gerrit-Owner: Russ Cox <r...@golang.org>
                      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                      Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                      Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                      Gerrit-Reviewer: Russ Cox <r...@golang.org>
                      Gerrit-Comment-Date: Fri, 17 Aug 2018 18:57:10 +0000
                      Gerrit-HasComments: No
                      Gerrit-Has-Labels: No
                      Gerrit-MessageType: comment

                      Gobot Gobot (Gerrit)

                      unread,
                      Aug 17, 2018, 2:57:27 PM8/17/18
                      to Russ Cox, goph...@pubsubhelper.golang.org, Alan Donovan, Ian Lance Taylor, golang-co...@googlegroups.com

                      TryBots beginning. Status page: https://farmer.golang.org/try?commit=a44078be

                      View Change

                        To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                        Gerrit-Project: go
                        Gerrit-Branch: master
                        Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                        Gerrit-Change-Number: 129061
                        Gerrit-PatchSet: 4
                        Gerrit-Owner: Russ Cox <r...@golang.org>
                        Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                        Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                        Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                        Gerrit-Reviewer: Russ Cox <r...@golang.org>
                        Gerrit-Comment-Date: Fri, 17 Aug 2018 18:57:24 +0000

                        Gobot Gobot (Gerrit)

                        unread,
                        Aug 17, 2018, 3:09:50 PM8/17/18
                        to Russ Cox, goph...@pubsubhelper.golang.org, Alan Donovan, Ian Lance Taylor, golang-co...@googlegroups.com

                        TryBots are happy.

                        Patch set 4:TryBot-Result +1

                        View Change

                          To view, visit change 129061. To unsubscribe, or for help writing mail filters, visit settings.

                          Gerrit-Project: go
                          Gerrit-Branch: master
                          Gerrit-Change-Id: Iec15fa7b359af11b6a4fc6cb082e593658fb6e41
                          Gerrit-Change-Number: 129061
                          Gerrit-PatchSet: 4
                          Gerrit-Owner: Russ Cox <r...@golang.org>
                          Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                          Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                          Gerrit-Reviewer: Russ Cox <r...@golang.org>
                          Gerrit-Comment-Date: Fri, 17 Aug 2018 19:09:48 +0000

                          Russ Cox (Gerrit)

                          unread,
                          Aug 17, 2018, 3:22:05 PM8/17/18
                          to Russ Cox, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Gobot Gobot, Alan Donovan, Ian Lance Taylor, golang-co...@googlegroups.com

                          Russ Cox merged this change.

                          View Change

                          Approvals: Alan Donovan: Looks good to me, approved Russ Cox: Run TryBots Gobot Gobot: TryBots succeeded
                          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 <r...@golang.org>
                          TryBot-Result: Gobot Gobot <go...@golang.org>
                          Reviewed-by: Alan Donovan <adon...@google.com>

                          ---
                          M src/cmd/go/internal/modload/load.go
                          M src/cmd/go/testdata/script/mod_fs_patterns.txt
                          M src/cmd/go/testdata/script/mod_list_dir.txt
                          3 files changed, 30 insertions(+), 1 deletion(-)

                          diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
                          index b00f814..5ca2ed2 100644
                          Gerrit-PatchSet: 5
                          Gerrit-Owner: Russ Cox <r...@golang.org>
                          Gerrit-Reviewer: Alan Donovan <adon...@google.com>
                          Gerrit-Reviewer: Gobot Gobot <go...@golang.org>
                          Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
                          Gerrit-Reviewer: Russ Cox <r...@golang.org>
                          Gerrit-MessageType: merged
                          Reply all
                          Reply to author
                          Forward
                          0 new messages