Skip to content

find: fix -printf %h for single-component paths with trailing slash (#1071) - #1074

Open
yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:fix/find-printf-h-single-component
Open

yunusarda-sudo wants to merge 1 commit into
uutils:mainfrom
yunusarda-sudo:fix/find-printf-h-single-component

Conversation

@yunusarda-sudo

@yunusarda-sudo yunusarda-sudo commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #1076, which already landed the #1071 fix on main.

The change here was incorrect: it also treated multi-character names like foo/ as foo, but observed GNU find 4.10.0 still expands foo/ and ab/ to .. Only a one-character name followed by slashes is cut at the last slash (d/ → d, // → /).

@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.45%. Comparing base (4c49ccd) to head (bf766dd).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 15 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 20 untouched benchmarks


Comparing yunusarda-sudo:fix/find-printf-h-single-component (bf766dd) with main (0c8ef51)

Open in CodSpeed

// 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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is dead code, no?
with an empty path rposition already returns None and the else branch gives ""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just String::from_utf8_lossy(&bytes[..bytes.len().saturating_sub(1)]), no?
bytes[..0] is already "" for "/"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same bytes[..bytes.len() - 1] as in the slash-only branch, could be dedup

@yunusarda-sudo yunusarda-sudo Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d/ and foo/ test the same thing as a/, do we need them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yunusarda-sudo

Copy link
Copy Markdown
Contributor Author

#1071 was already fixed in #1076 (48e10b3). This PR over-generalizes to multi-character names; observed GNU find 4.10.0 still expands foo/ and ab/ to .. Leaving this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants