Skip to content

Conversation

@naoNao89
Copy link
Contributor

Fixes #8924 by rewriting dirname as pure byte-level string operations, avoiding Path::parent() normalization.

Handles all edge cases: foo//., foo///., foo/./, etc. Implementation uses explicit step-by-step logic without unsafe code, making it maintainable and platform-safe.

Added comprehensive tests for slash variations and dot-slash patterns.

Alternative to #8927 - this approach prioritizes code clarity and safety over conciseness. Both fix the same issues, but this avoids unsafe assumptions about OsStr encoding.

Add test_missing_operand to cover error path when dirname called with no arguments (lines 80-82). Add test_multiple_paths_comprehensive to cover loop iteration with mixed edge cases including trailing dot paths, empty strings, and various path types (line 84).
Replace Path::parent() approach with byte-level string operations to avoid path normalization. This ensures dirname behaves as a pure string manipulation tool per POSIX/GNU specifications, correctly handling patterns like foo//., foo/./bar, and preserving /. components in middle of paths.

Add comprehensive test coverage for edge cases including multiple slash variations, dot-slash patterns, and component preservation.

Addresses issue uutils#8910 with complete POSIX-compliant implementation.
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 17, 2025

CodSpeed Performance Report

Merging this PR will improve performance by 4.08%

Comparing naoNao89:test/dirname-additional-coverage (cdc5eca) with main (7eb78ab)1

Summary

⚡ 2 improved benchmarks
✅ 280 untouched benchmarks
⏩ 38 skipped benchmarks2

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory du_wide_tree[(5000, 500)] 1.2 MB 1.2 MB +3.42%
Memory numfmt_large_numbers_si[10000] 4.8 MB 4.6 MB +4.08%

Footnotes

  1. No successful run was found on main (75f45e8) during the generation of this report, so 7eb78ab was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 38 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@sylvestre
Copy link
Contributor

@naoNao89 please don't start new pr when others started. Contribute to the other instead :)

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the test/dirname-additional-coverage branch from 63fe1ff to dc5e0eb Compare October 20, 2025 08:10
@sylvestre
Copy link
Contributor

why draft ? :)

@naoNao89 naoNao89 force-pushed the test/dirname-additional-coverage branch from dc5e0eb to 2c72ad3 Compare October 20, 2025 08:19
@naoNao89 naoNao89 marked this pull request as ready for review October 20, 2025 08:24
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 closed this by deleting the head repository Nov 6, 2025
@naoNao89 naoNao89 reopened this Nov 7, 2025
@RenjiSann
Copy link
Collaborator

@naoNao89 what's the status on this ? It has conflicts

@naoNao89
Copy link
Contributor Author

resolved

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)

@naoNao89
Copy link
Contributor Author

naoNao89 commented Nov 25, 2025

Caught an .unwrap() crash on an unrelated test where a process was killed by signal instead of exiting normally 💀 #9430

#[test]
fn test_missing_operand() {
// Test calling dirname with no arguments - should fail
// This covers the error path at line 80-82 in dirname.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This covers the error path at line 80-82 in dirname.rs

lines will change

- Remove unnecessary comments from test_dirname.rs
- Change dirname_string_manipulation() return type to Cow<'_, [u8]>
- Add explicit lifetime annotation to resolve compiler warning
- Optimize memory allocation with copy-on-write pattern
@sylvestre sylvestre merged commit b3ad96f into uutils:main Jan 17, 2026
157 checks passed
@sylvestre
Copy link
Contributor

follow up #10294

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.

dirname fails with some class of paths

3 participants