]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: show warnings about symlinks only for patterns containing ...
authorRay Wu <ray@liftoff.io>
Tue, 20 Apr 2021 17:41:37 +0000 (10:41 -0700)
committerBryan C. Mills <bcmills@google.com>
Tue, 27 Apr 2021 18:17:01 +0000 (18:17 +0000)
Go commands show a warning message any time a pattern is expanded and a
symlink to a directory is encountered. For monorepo with non Go projects
using symlinks underneath, the output of go commands could be spammed by
this warning.

This commit includes the behavior change to only print this warning when
there's a pattern containing ... .

Fixes #35941

Change-Id: I094da2628bcd47b86fee8c6529d1066aa013a43b
Reviewed-on: https://go-review.googlesource.com/c/go/+/311890
Run-TryBot: Caleb Spare <cespare@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Michael Matloob <matloob@golang.org>

src/cmd/go/internal/modload/search.go
src/cmd/go/internal/search/search.go
src/cmd/go/testdata/script/list_symlink_issue35941.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt [new file with mode: 0644]

index c34f745a24dd3084422b9bbc7d8ec90d7e4cad30..658fc6f55a9c9bb127e600f3d5ef51ffeb8c9773 100644 (file)
@@ -86,7 +86,7 @@ func matchPackages(ctx context.Context, m *search.Match, tags map[string]bool, f
                        }
 
                        if !fi.IsDir() {
-                               if fi.Mode()&fs.ModeSymlink != 0 && want {
+                               if fi.Mode()&fs.ModeSymlink != 0 && want && strings.Contains(m.Pattern(), "...") {
                                        if target, err := fsys.Stat(path); err == nil && target.IsDir() {
                                                fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
                                        }
index faf3a321dd17090f80caff927b7069eaa687b43b..f1152080a7e7293a4999e42fc182c05bdf6adbb1 100644 (file)
@@ -155,7 +155,7 @@ func (m *Match) MatchPackages() {
                        }
 
                        if !fi.IsDir() {
-                               if fi.Mode()&fs.ModeSymlink != 0 && want {
+                               if fi.Mode()&fs.ModeSymlink != 0 && want && strings.Contains(m.pattern, "...") {
                                        if target, err := fsys.Stat(path); err == nil && target.IsDir() {
                                                fmt.Fprintf(os.Stderr, "warning: ignoring symlink %s\n", path)
                                        }
diff --git a/src/cmd/go/testdata/script/list_symlink_issue35941.txt b/src/cmd/go/testdata/script/list_symlink_issue35941.txt
new file mode 100644 (file)
index 0000000..eb12bde
--- /dev/null
@@ -0,0 +1,18 @@
+[!symlink] skip
+env GO111MODULE=off
+
+# Issue 35941: suppress symlink warnings when running 'go list all'.
+symlink goproj/css -> $GOPATH/src/css
+
+go list all
+! stderr 'warning: ignoring symlink'
+
+# Show symlink warnings when patterns contain '...'.
+go list goproj/...
+stderr 'warning: ignoring symlink'
+
+-- goproj/a.go --
+package a
+
+-- css/index.css --
+body {}
diff --git a/src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt b/src/cmd/go/testdata/script/mod_tidy_symlink_issue35941.txt
new file mode 100644 (file)
index 0000000..d4658c6
--- /dev/null
@@ -0,0 +1,36 @@
+env GO111MODULE=on
+[!symlink] skip
+
+cd m
+symlink symlink -> ../outside
+
+cp go.mod go.mod.orig
+
+# Issue 35941: suppress symlink warnings when running 'go mod tidy'.
+# 'go mod tidy' should not scan packages in symlinked subdirectories.
+go mod tidy
+! stderr 'warning: ignoring symlink'
+cmp go.mod go.mod.orig
+
+! go build ./symlink
+stderr '^symlink[\\/]symlink.go:3:8: module example.net/unresolved provides package example.net/unresolved and is replaced but not required; to add it:\n\tgo get example.net/unresolved@v0.1.0$'
+
+-- m/go.mod --
+module example.net/m
+
+go 1.16
+
+replace example.net/unresolved v0.1.0 => ../unresolved
+-- m/a.go --
+package a
+-- outside/symlink.go --
+package symlink
+
+import _ "example.net/unresolved"
+-- unresolved/go.mod --
+module example.net/unresolved
+
+go 1.16
+-- unresolved/unresolved.go --
+// Package unresolved exists, but 'go mod tidy' won't add it.
+package unresolved