Skip excluded paths before looking at their errors (closes #16)
check / check (push) Successful in 2m36s
check / check (push) Successful in 2m36s
filepath.Walk hands its callback the error for a path it could not read, such as a directory it cannot list. Both callbacks, in walkAndProcess and countFiles, returned that error before they checked the exclusions, so a directory that --exclude or --exclude-dotfiles excluded still failed the run when it could not be listed. Given an error, each callback now checks the exclusions first and skips an excluded path. The new test excludes a directory that cannot be listed and runs sum add and check over its parent. Model: opus-5-5
This commit is contained in:
+12
-1
@@ -613,6 +613,12 @@ func countFiles(opts *options, root string, cont bool) (int64, error) {
|
||||
root = filepath.Clean(root)
|
||||
|
||||
err := filepath.Walk(root, func(p string, info os.FileInfo, err error) error {
|
||||
// An excluded path is skipped whatever went wrong reading it.
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
if err != nil && shouldExclude(opts, rel) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil && cont {
|
||||
return nil
|
||||
}
|
||||
@@ -627,7 +633,6 @@ func countFiles(opts *options, root string, cont bool) (int64, error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
if shouldExclude(opts, rel) {
|
||||
if info.IsDir() {
|
||||
return filepath.SkipDir
|
||||
@@ -699,6 +704,12 @@ func walkAndProcess(
|
||||
root = filepath.Clean(root)
|
||||
|
||||
return filepath.Walk(root, func(p string, info os.FileInfo, err error) error {
|
||||
// An excluded path is skipped whatever went wrong reading it.
|
||||
rel, _ := filepath.Rel(root, p)
|
||||
if err != nil && shouldExclude(opts, rel) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return unreadable(cont, stats, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user