@@ -10,6 +10,7 @@ import (
10
10
"fmt"
11
11
"hash"
12
12
"io"
13
+ "io/fs"
13
14
"math"
14
15
"net/http"
15
16
"os"
@@ -76,8 +77,9 @@ func File(path string) *Pipe {
76
77
}
77
78
78
79
// FindFiles creates a pipe listing all the files in the directory dir and its
79
- // subdirectories recursively, one per line, like Unix find(1). If dir doesn't
80
- // exist or can't be read, the pipe's error status will be set.
80
+ // subdirectories recursively, one per line, like Unix find(1).
81
+ // Errors are ignored unless no files are found (in which case the pipe's error
82
+ // status will be set to the last error encountered).
81
83
//
82
84
// Each line of the output consists of a slash-separated path, starting with
83
85
// the initial directory. For example, if the directory looks like this:
@@ -92,17 +94,19 @@ func File(path string) *Pipe {
92
94
// test/2.txt
93
95
func FindFiles (dir string ) * Pipe {
94
96
var paths []string
95
- err := filepath .Walk (dir , func (path string , info os.FileInfo , err error ) error {
97
+ var innerErr error
98
+ fs .WalkDir (os .DirFS (dir ), "." , func (path string , d fs.DirEntry , err error ) error {
96
99
if err != nil {
97
- return err
100
+ innerErr = err
101
+ return fs .SkipDir
98
102
}
99
- if ! info .IsDir () {
100
- paths = append (paths , path )
103
+ if ! d .IsDir () {
104
+ paths = append (paths , filepath . Join ( dir , path ) )
101
105
}
102
106
return nil
103
107
})
104
- if err != nil {
105
- return NewPipe ().WithError (err )
108
+ if innerErr != nil && len ( paths ) == 0 {
109
+ return NewPipe ().WithError (innerErr )
106
110
}
107
111
return Slice (paths )
108
112
}
0 commit comments