]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd: ignore the directory named go.mod
authorLeonardo Comelli <leonardo.comelli@gmail.com>
Tue, 19 Mar 2019 03:53:04 +0000 (03:53 +0000)
committerBryan C. Mills <bcmills@google.com>
Thu, 28 Mar 2019 21:59:51 +0000 (21:59 +0000)
The existing implementation does not check in all cases whether go.mod is a regular file.

Fixes #30788

Change-Id: I6d140545c3cfada651612efd5bee2fbdcb747ca7
GitHub-Last-Rev: 4a9b251e378d9d7cc8768d395c360d3542fc9bc6
GitHub-Pull-Request: golang/go#30830
Reviewed-on: https://go-review.googlesource.com/c/go/+/167393
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/search.go
src/cmd/go/internal/search/search.go
src/cmd/go/testdata/script/mod_dir.txt [new file with mode: 0644]

index db3e1a9e5b394055cdc42ee6e7493ee89846b728..83ef0e0b4fd78b0ab5b1063e667c64a411618caa 100644 (file)
@@ -233,8 +233,8 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
        if isLocal {
                for d := dir; d != mdir && len(d) > len(mdir); {
                        haveGoMod := haveGoModCache.Do(d, func() interface{} {
-                               _, err := os.Stat(filepath.Join(d, "go.mod"))
-                               return err == nil
+                               fi, err := os.Stat(filepath.Join(d, "go.mod"))
+                               return err == nil && !fi.IsDir()
                        }).(bool)
 
                        if haveGoMod {
index 753b3be6de7d76866f8730e7c284b9965edbb8c5..3af39747c63815a84c505cbe3d4491936bd2cbd2 100644 (file)
@@ -76,7 +76,7 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
                        }
                        // Stop at module boundaries.
                        if path != root {
-                               if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil {
+                               if fi, err := os.Stat(filepath.Join(path, "go.mod")); err == nil && !fi.IsDir() {
                                        return filepath.SkipDir
                                }
                        }
index 0ca60e73497e2188a424dbb0fcbdfe8a0bb325ca..20e8f0ad1e48fc535e8a5ecd0d77209c60590ca7 100644 (file)
@@ -190,7 +190,7 @@ func MatchPackagesInFS(pattern string) *Match {
 
                if !top && cfg.ModulesEnabled {
                        // Ignore other modules found in subdirectories.
-                       if _, err := os.Stat(filepath.Join(path, "go.mod")); err == nil {
+                       if fi, err := os.Stat(filepath.Join(path, "go.mod")); err == nil && !fi.IsDir() {
                                return filepath.SkipDir
                        }
                }
diff --git a/src/cmd/go/testdata/script/mod_dir.txt b/src/cmd/go/testdata/script/mod_dir.txt
new file mode 100644 (file)
index 0000000..05548f6
--- /dev/null
@@ -0,0 +1,20 @@
+# The directory named go.mod should be ignored
+
+env GO111MODULE=on
+
+cd $WORK/sub
+
+go list .
+stdout 'x/sub'
+
+mkdir go.mod
+exists go.mod
+
+go list .
+stdout 'x/sub'
+
+-- $WORK/go.mod --
+module x
+
+-- $WORK/sub/x.go --
+package x
\ No newline at end of file