Repository navigation
du: match --exclude patterns after each '/', as GNU does - #16701
nishant9144 wants to merge 3 commits into
Conversation
An --exclude pattern was matched only against the whole path and the file name, so 'du --exclude=target/debug .' still counted ./target/debug, and './target' and 'target' gave different totals. Like GNU's exclude.c, also try the pattern on every part of the path that follows a '/', for the operands as well as the entries found while walking them. Fixes uutils#16691
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
| for pattern in &options.excludes { | ||
| if pattern.matches(&this_stat.path.to_string_lossy()) | ||
| if is_excluded(pattern, &this_stat.path.to_string_lossy()) | ||
| || pattern.matches(&entry_name.to_string_lossy()) |
There was a problem hiding this comment.
is_excluded already tries the part after the last '/', which is entry_name, so this check is redundant now, no?
There was a problem hiding this comment.
Yes, removed in both traversals. is_excluded now splits on std::path::is_separator, so on Windows the last part is still the file name in du_regular.
| /// Whether `path` matches an `--exclude` pattern. As in GNU, the pattern is | ||
| /// tried on the whole path and on every part of it that follows a `/`, so | ||
| /// `target/debug` also excludes `./target/debug` and `a/target/debug`. | ||
| fn is_excluded(pattern: &Pattern, path: &str) -> bool { |
There was a problem hiding this comment.
could take &[Pattern] and do the loop itself? we have the same for pattern in excludes 3 times
There was a problem hiding this comment.
Done, it takes all the patterns now and the three loops are gone.
| } | ||
| ts.ucmd() | ||
| .arg("--exclude=target/debug") | ||
| .arg(".") |
There was a problem hiding this comment.
could you please also cover a glob like t*t/debug and a nested a/target/debug? you have them in the PR description
There was a problem hiding this comment.
Added: both patterns, with ., ./target, .//target, a and ./a/target as operands, plus a check that a/target itself is still listed.
|
Binary size comparison: |
is_excluded now takes every pattern, so the three call sites no longer loop over them, and drops the separate file-name check: the part after the last separator is the file name. Splitting on any path separator keeps that true on Windows. Test a glob and a nested directory as well.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
GNU testsuite comparison: |
Merging this PR will regress 2 benchmarks3 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Fixes #16691
dumatched an--excludepattern only against the whole path and the file name. With.as the operand the paths start with./, so--exclude=target/debugnever matched./target/debug, andtargetand./targetgave different totals.GNU (
exclude.c, used withoutEXCLUDE_ANCHORED) also tries the pattern on every part of the path that follows a/. This does the same, in a smallis_excludedhelper used for the operands and for the entries found while walking them, in both theopenatand the regular traversal.Compared with GNU du 9.4 on the issue's tree plus a nested
a/target/debug(du -bs, bytes):--exclude=target/debug .--exclude=target/debug ./target--exclude=target/debug a/target--exclude=t*t/debug .--exclude=target ./target--exclude=/target .A pattern starting with
/still only matches a whole path, as in GNU.I left the separate file-name check as it is, since #12771 is changing that line.
Tests
test_du_exclude_matches_after_slash: fails on main, passes with the change.cargo fmt,cargo clippy -p uu_du --all-targets -D warnings, and thedutests pass on Linux.