Skip to content

Commit 6100917

Browse files
committed
cmd/go: fix go get with ... fails in module mode
1 parent 5a0743b commit 6100917

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/cmd/go/internal/modload/import.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,27 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile
252252
// We don't care about build tags, not even "+build ignore".
253253
// We're just looking for a plausible directory.
254254
haveGoFiles = haveGoFilesCache.Do(dir, func() interface{} {
255-
f, err := os.Open(dir)
255+
var pattern string
256+
if strings.HasSuffix(dir, "/...") {
257+
dir = strings.TrimSuffix(dir, "/...")
258+
pattern = filepath.Join(dir, "**", "*.go")
259+
} else {
260+
pattern = filepath.Join(dir, "*.go")
261+
}
262+
goSourceFiles, err := filepath.Glob(pattern)
256263
if err != nil {
257264
return false
258265
}
259-
defer f.Close()
260-
names, _ := f.Readdirnames(-1)
261-
for _, name := range names {
262-
if strings.HasSuffix(name, ".go") {
263-
info, err := os.Stat(filepath.Join(dir, name))
264-
if err == nil && info.Mode().IsRegular() {
265-
return true
266-
}
266+
// no go source file
267+
if len(goSourceFiles) == 0 {
268+
return false
269+
}
270+
// regular file
271+
for _, fullPath := range goSourceFiles {
272+
info, err := os.Stat(fullPath)
273+
// once one success, we are done
274+
if err == nil && info.Mode().IsRegular() {
275+
return true
267276
}
268277
}
269278
return false

0 commit comments

Comments
 (0)