Skip to content

Commit

Permalink
Fix app directory selection when many files exist
Browse files Browse the repository at this point in the history
  • Loading branch information
akalipetis committed Oct 26, 2023
1 parent fb88123 commit 453709a
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
Expand All @@ -28,31 +27,17 @@ func FileExists(searchPath, name string) bool {

// FindFile searches for the file inside the path recursively
// and returns the full path of the file if found
// If multiple files exist, tries to return the one closest to root
func FindFile(searchPath, name string) string {
var found string
//nolint:errcheck
filepath.WalkDir(searchPath, func(p string, d os.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
// Skip vendor directories
if slices.Contains(skipDirs, d.Name()) {
return filepath.SkipDir
}
return nil
}

if d.Name() == name {
found = p
return errors.New("found")
}
files := FindAllFiles(searchPath, name)
if len(files) == 0 {
return ""
}

return nil
slices.SortFunc(files, func(a, b string) bool {
return len(strings.Split(a, string(os.PathSeparator))) < len(strings.Split(b, string(os.PathSeparator)))
})

return found
return files[0]
}

// FindAllFiles searches for the file inside the path recursively and returns all matches
Expand Down

0 comments on commit 453709a

Please sign in to comment.