Skip to content

Commit

Permalink
Make WalkDir Func a Closure
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Nov 17, 2024
1 parent 0b74dea commit 69e6055
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions script.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 69e6055

Please sign in to comment.