Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make find_up use os.ReadDir #4599

Merged
merged 1 commit into from Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}