fix(external): Ensure findGoDirs "finds" top-level directory
Due to the lexical walk order of `filepath.Walk` the previous directory identification logic failed under certain conditions if the top-level directory contained Go files that showed up *after* the first subdirectories. To simplify the logic a set of directories is now gathered instead on a file-level.
This commit is contained in:
parent
a5473293e7
commit
b20e46d60b
1 changed files with 10 additions and 20 deletions
30
external/main.go
vendored
30
external/main.go
vendored
|
@ -38,33 +38,18 @@ type pkg struct {
|
|||
// findGoDirs returns a filepath.WalkFunc that identifies all
|
||||
// directories that contain Go source code in a certain tree.
|
||||
func findGoDirs(at string) ([]string, error) {
|
||||
var goDirs []string
|
||||
dir := ""
|
||||
dirSet := make(map[string]bool)
|
||||
|
||||
err := filepath.Walk(at, func(path string, info os.FileInfo, err error) error {
|
||||
// Skip testdata
|
||||
if info.IsDir() && info.Name() == "testdata" {
|
||||
// Skip folders that are guaranteed to not be relevant
|
||||
if info.IsDir() && (info.Name() == "testdata" || info.Name() == ".git") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
// Keep track of the last seen directory.
|
||||
if info.IsDir() {
|
||||
dir = path
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the directory has already been "popped", nothing else needs
|
||||
// to happen.
|
||||
if dir == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// If the current file is a Go file, then the directory is popped
|
||||
// (i.e. marked as a Go directory).
|
||||
if strings.HasSuffix(info.Name(), ".go") && !strings.HasSuffix(info.Name(), "_test.go") {
|
||||
goDirs = append(goDirs, dir)
|
||||
dir = ""
|
||||
return nil
|
||||
if !info.IsDir() && strings.HasSuffix(info.Name(), ".go") && !strings.HasSuffix(info.Name(), "_test.go") {
|
||||
dirSet[filepath.Dir(path)] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -74,6 +59,11 @@ func findGoDirs(at string) ([]string, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
goDirs := []string{}
|
||||
for k, _ := range dirSet {
|
||||
goDirs = append(goDirs, k)
|
||||
}
|
||||
|
||||
return goDirs, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue