MCPcopy Index your code
hub / github.com/go-task/task / SearchNPathRecursively

Function SearchNPathRecursively

internal/fsext/fs.go:173–208  ·  view source on GitHub ↗

SearchNPathRecursively walks up the directory tree starting at the given path, calling the Search function in each directory and adding each matching file that it finds to a list until it reaches the root directory or the length of the list exceeds n. On supported operating systems, it will also che

(path string, possibleFilenames []string, n int)

Source from the content-addressed store, hash-verified

171// length of the list exceeds n. On supported operating systems, it will also
172// check if the user ID of the directory changes and abort if it does.
173func SearchNPathRecursively(path string, possibleFilenames []string, n int) ([]string, error) {
174 var paths []string
175
176 owner, err := sysinfo.Owner(path)
177 if err != nil {
178 return nil, err
179 }
180
181 for n == -1 || len(paths) < n {
182 fpath, err := SearchPath(path, possibleFilenames)
183 if err == nil {
184 paths = append(paths, fpath)
185 }
186
187 // Get the parent path/user id
188 parentPath := filepath.Dir(path)
189 parentOwner, err := sysinfo.Owner(parentPath)
190 if err != nil {
191 return nil, err
192 }
193
194 // If the user id of the directory changes indicate a permission error, otherwise
195 // the calling code will infer an error condition based on the accumulated
196 // contents of paths.
197 if path == parentPath {
198 return paths, nil
199 } else if parentOwner != owner {
200 return paths, os.ErrPermission
201 }
202
203 owner = parentOwner
204 path = parentPath
205 }
206
207 return paths, nil
208}

Callers 2

SearchAllFunction · 0.85
SearchPathRecursivelyFunction · 0.85

Calls 3

OwnerFunction · 0.92
SearchPathFunction · 0.85
DirMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…