@@ -81,41 +81,47 @@ func (p *Path) ReadDirRecursive() (PathList, error) {
81
81
// - `filters` are the filters that are checked to determine if the entry should be
82
82
// added to the resulting PathList
83
83
func (p * Path ) ReadDirRecursiveFiltered (recursionFilter ReadDirFilter , filters ... ReadDirFilter ) (PathList , error ) {
84
- infos , err := os .ReadDir (p .path )
85
- if err != nil {
86
- return nil , err
87
- }
84
+ var search func (* Path ) (PathList , error )
88
85
89
- accept := func (p * Path ) bool {
90
- for _ , filter := range filters {
91
- if ! filter (p ) {
92
- return false
86
+ search = func (currPath * Path ) (PathList , error ) {
87
+ infos , err := os .ReadDir (currPath .path )
88
+ if err != nil {
89
+ return nil , err
90
+ }
91
+
92
+ accept := func (p * Path ) bool {
93
+ for _ , filter := range filters {
94
+ if ! filter (p ) {
95
+ return false
96
+ }
93
97
}
98
+ return true
94
99
}
95
- return true
96
- }
97
100
98
- paths := PathList {}
99
- for _ , info := range infos {
100
- path := p .Join (info .Name ())
101
+ paths := PathList {}
102
+ for _ , info := range infos {
103
+ path := currPath .Join (info .Name ())
101
104
102
- if accept (path ) {
103
- paths .Add (path )
104
- }
105
+ if accept (path ) {
106
+ paths .Add (path )
107
+ }
105
108
106
- if recursionFilter == nil || recursionFilter (path ) {
107
- if isDir , err := path .IsDirCheck (); err != nil {
108
- return nil , err
109
- } else if isDir {
110
- subPaths , err := path .ReadDirRecursiveFiltered (recursionFilter , filters ... )
111
- if err != nil {
109
+ if recursionFilter == nil || recursionFilter (path ) {
110
+ if isDir , err := path .IsDirCheck (); err != nil {
112
111
return nil , err
112
+ } else if isDir {
113
+ subPaths , err := search (path )
114
+ if err != nil {
115
+ return nil , err
116
+ }
117
+ paths .AddAll (subPaths )
113
118
}
114
- paths .AddAll (subPaths )
115
119
}
116
120
}
121
+ return paths , nil
117
122
}
118
- return paths , nil
123
+
124
+ return search (p )
119
125
}
120
126
121
127
// FilterDirectories is a ReadDirFilter that accepts only directories
0 commit comments