Repository navigation
find: fix -printf %h for single-component paths with trailing slash (#1071) - #1074
yunusarda-sudo wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1074 +/- ##
==========================================
+ Coverage 92.43% 92.45% +0.01%
==========================================
Files 38 38
Lines 8887 8901 +14
Branches 440 443 +3
==========================================
+ Hits 8215 8229 +14
Misses 532 532
Partials 140 140 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance1 warning
Comparing |
| // cut at its last slash, keeping the others. | ||
| if bytes.len() > 2 && bytes[1..].iter().all(|&b| b == b'/') { | ||
| return String::from_utf8_lossy(&bytes[..bytes.len() - 1]); | ||
| if bytes.is_empty() { |
There was a problem hiding this comment.
this is dead code, no?
with an empty path rposition already returns None and the else branch gives ""
There was a problem hiding this comment.
Yes, it's dead. I won't keep this rewrite; #1076 already landed the correct fix on main.
| // the last one ("/" has none -> "", "//" -> "/", "///" -> "//"). | ||
| let Some(last) = bytes.iter().rposition(|&b| b != b'/') else { | ||
| return "".into(); | ||
| return if bytes.len() <= 1 { |
There was a problem hiding this comment.
could be just String::from_utf8_lossy(&bytes[..bytes.len().saturating_sub(1)]), no?
bytes[..0] is already "" for "/"
There was a problem hiding this comment.
Yes. I won't pursue this rewrite though; #1076 already covers // on main.
| if bytes.len() == last + 1 { | ||
| ".".into() | ||
| } else { | ||
| String::from_utf8_lossy(&bytes[..bytes.len() - 1]) |
There was a problem hiding this comment.
same bytes[..bytes.len() - 1] as in the slash-only branch, could be dedup
There was a problem hiding this comment.
Agreed, but I won't land this version: it also changes foo/ and ab/, which GNU find 4.10.0 still expands to ..
| None => ".".into(), | ||
| None => { | ||
| // Single-component path ("d", "d/", "d//", ".//"). If it has no | ||
| // slashes at all, GNU find expands %h to ".". If it ends with |
There was a problem hiding this comment.
the description says this matches GNU's find/print.c
did you read the GNU source? we can't accept code derived from it, only the manual or the observed behavior
There was a problem hiding this comment.
The description shouldn't mention print.c. I only compared observed GNU find 4.10.0, which still expands foo/ and ab/ to ., so this over-generalizes; #1076 already matches that.
| ("a", "."), | ||
| ("a/", "."), | ||
| ("a/", "a"), | ||
| ("d/", "d"), |
There was a problem hiding this comment.
d/ and foo/ test the same thing as a/, do we need them?
There was a problem hiding this comment.
d/ is the same as a/, but foo/ is not: GNU find 4.10.0 expands foo/ to .. #1076 already has ab/ for that case.
Superseded by #1076, which already landed the #1071 fix on main.
The change here was incorrect: it also treated multi-character names like
foo/asfoo, but observed GNU find 4.10.0 still expandsfoo/andab/to.. Only a one-character name followed by slashes is cut at the last slash (d/→d,//→/).