From 69e60551db8c93ae9b454e0191b630a0269e7795 Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Sun, 17 Nov 2024 15:12:10 -0500 Subject: [PATCH] Make WalkDir Func a Closure Signed-off-by: Mahad Zaryab --- script.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/script.go b/script.go index 6c03ed7..96aacf5 100644 --- a/script.go +++ b/script.go @@ -93,20 +93,19 @@ func File(path string) *Pipe { // test/2.txt func FindFiles(dir string) *Pipe { var paths []string - err := fs.WalkDir(os.DirFS(dir), ".", func(path string, d fs.DirEntry, err error) error { + var innerErr error + fs.WalkDir(os.DirFS(dir), ".", func(path string, d fs.DirEntry, err error) error { if err != nil { - if os.IsPermission(err) { - return fs.SkipDir - } - return err + innerErr = err + return fs.SkipDir } if !d.IsDir() { paths = append(paths, filepath.Join(dir, path)) } return nil }) - if err != nil && len(paths) == 0 { - return NewPipe().WithError(err) + if innerErr != nil && len(paths) == 0 { + return NewPipe().WithError(innerErr) } return Slice(paths) }