From a992650c317e6032e2d301a25899be2797b9c74d Mon Sep 17 00:00:00 2001 From: Nathan Hammond Date: Mon, 17 Apr 2023 16:27:35 +0800 Subject: [PATCH] Make find_up use os.ReadDir --- cli/internal/turbopath/find_up.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/cli/internal/turbopath/find_up.go b/cli/internal/turbopath/find_up.go index 4787a2a97bf55..bf7c39c9e43b8 100644 --- a/cli/internal/turbopath/find_up.go +++ b/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 @@ -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 @@ -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) }