Skip to content

Commit

Permalink
Make find_up use os.ReadDir (vercel#4599)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhammond authored and NicholasLYang committed Apr 21, 2023
1 parent 6849dc5 commit a1bb470
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions cli/internal/turbopath/find_up.go
@@ -1,17 +1,12 @@
package turbopath

import (
"io/ioutil"
"os"
"path/filepath"
)

type readDir func(string) ([]os.FileInfo, error)

var defaultReadDir readDir = ioutil.ReadDir

func hasFile(name, dir string, readdir readDir) (bool, error) {
files, err := readdir(dir)
func hasFile(name, dir string) (bool, error) {
files, err := os.ReadDir(dir)

if err != nil {
return false, err
Expand All @@ -26,9 +21,9 @@ func hasFile(name, dir string, readdir readDir) (bool, error) {
return false, nil
}

func findupFrom(name, dir string, readdir readDir) (string, error) {
func findupFrom(name, dir string) (string, error) {
for {
found, err := hasFile(name, dir, readdir)
found, err := hasFile(name, dir)

if err != nil {
return "", err
Expand All @@ -48,8 +43,8 @@ func findupFrom(name, dir string, readdir readDir) (string, error) {
}
}

// Recursively find a file by walking up parents in the file tree
// FindupFrom Recursively finds a file by walking up parents in the file tree
// starting from a specific directory.
func FindupFrom(name, dir string) (string, error) {
return findupFrom(name, dir, defaultReadDir)
return findupFrom(name, dir)
}

0 comments on commit a1bb470

Please sign in to comment.