mirror of https://github.com/golang/go.git
cmd: ignore the directory named go.mod
The existing implementation does not check in all cases whether go.mod is a regular file.
Fixes #30788
Change-Id: I6d140545c3cfada651612efd5bee2fbdcb747ca7
GitHub-Last-Rev: 4a9b251e37
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>
This commit is contained in:
parent
93af677837
commit
fa5dbd06e5
|
|
@ -233,8 +233,8 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
|
||||||
if isLocal {
|
if isLocal {
|
||||||
for d := dir; d != mdir && len(d) > len(mdir); {
|
for d := dir; d != mdir && len(d) > len(mdir); {
|
||||||
haveGoMod := haveGoModCache.Do(d, func() interface{} {
|
haveGoMod := haveGoModCache.Do(d, func() interface{} {
|
||||||
_, err := os.Stat(filepath.Join(d, "go.mod"))
|
fi, err := os.Stat(filepath.Join(d, "go.mod"))
|
||||||
return err == nil
|
return err == nil && !fi.IsDir()
|
||||||
}).(bool)
|
}).(bool)
|
||||||
|
|
||||||
if haveGoMod {
|
if haveGoMod {
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules []
|
||||||
}
|
}
|
||||||
// Stop at module boundaries.
|
// Stop at module boundaries.
|
||||||
if path != root {
|
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
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ func MatchPackagesInFS(pattern string) *Match {
|
||||||
|
|
||||||
if !top && cfg.ModulesEnabled {
|
if !top && cfg.ModulesEnabled {
|
||||||
// Ignore other modules found in subdirectories.
|
// 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
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue