1
0
mirror of https://github.com/golang/go synced 2024-11-17 22:14:43 -07:00

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
This commit is contained in:
Leonardo Comelli 2019-03-14 01:39:47 -03:00
parent 1024b25d0c
commit 871f35980e
3 changed files with 4 additions and 4 deletions

View 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 {

View 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
}
}

View 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
}
}