]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: ignore symlinks to directories when matching source files
authorBryan C. Mills <bcmills@google.com>
Fri, 26 Jun 2020 15:48:37 +0000 (11:48 -0400)
committerBryan C. Mills <bcmills@google.com>
Tue, 25 Aug 2020 03:29:25 +0000 (03:29 +0000)
Fixes #39841

Change-Id: Icbdc37d40e9c10179d6eb704d04482175b139f57
Reviewed-on: https://go-review.googlesource.com/c/go/+/240120
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/testdata/script/mod_symlink_dotgo.txt [new file with mode: 0644]
src/go/build/build.go

diff --git a/src/cmd/go/testdata/script/mod_symlink_dotgo.txt b/src/cmd/go/testdata/script/mod_symlink_dotgo.txt
new file mode 100644 (file)
index 0000000..d4cc143
--- /dev/null
@@ -0,0 +1,17 @@
+env GO111MODULE=on
+[!symlink] skip
+
+symlink dir.go -> dir
+
+# Issue #39841: symlinks to directories should be ignored, not treated as source files.
+go list -f '{{range .GoFiles}}{{.}}{{"\n"}}{{end}}' .
+stdout 'p\.go$'
+! stdout 'dir\.go$'
+
+-- go.mod --
+module example.com
+go 1.15
+-- p.go --
+package p
+-- dir/README.txt --
+This file exists to ensure that dir is a directory.
index 4a5da308a0c584ebe511ec7b5a1c1fc4661dcaee..39bc3591a7b0f74d1b5d1fa57768449c0f766747 100644 (file)
@@ -793,6 +793,12 @@ Found:
                if d.IsDir() {
                        continue
                }
+               if (d.Mode() & os.ModeSymlink) != 0 {
+                       if fi, err := os.Stat(filepath.Join(p.Dir, d.Name())); err == nil && fi.IsDir() {
+                               // Symlinks to directories are not source files.
+                               continue
+                       }
+               }
 
                name := d.Name()
                ext := nameExt(name)