Skip to content

readlink: report final component permission errors - #15388

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/readlink-final-component-errors
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/readlink-final-component-errors

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Preserve permission errors when canonicalizing the final path component. Add a regression covering inaccessible paths and continued processing of later operands.

Fixes the remaining canonicalization case after #14799.

Closes #6688.

if (miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())) =>
|| (miss_mode == MissingHandling::Normal
&& (!parts.is_empty() || e.kind() != ErrorKind::NotFound))) =>

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 changes realpath too, could you please add the same test in tests/by-util/test_realpath.rs?

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.

Added the matching realpath regression test. It fails without the fix and passes with it. All 62 readlink/realpath tests pass. Squashed and pushed—thanks!

@limadog9
limadog9 force-pushed the fix/readlink-final-component-errors branch from beec309 to dccf727 Compare October 15, 2026 18:17
if (miss_mode == MissingHandling::Existing
|| (miss_mode == MissingHandling::Normal && !parts.is_empty())) =>
|| (miss_mode == MissingHandling::Normal
&& (!parts.is_empty() || e.kind() != ErrorKind::NotFound))) =>

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 also used by mv (assert_not_same_file uses ?), did you check the error message for mv a dir_without_x/sub/b doesn't change?

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.

Good catch—the shared change did alter mv’s diagnostic. I’ve restored the previous error message and added a regression test for your example that also verifies both files remain unchanged. All 211 mv, readlink, and realpath tests pass.

@limadog9
limadog9 force-pushed the fix/readlink-final-component-errors branch from dccf727 to 4cdebf0 Compare October 15, 2026 19:01
@codspeed

codspeed Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 119 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

✅ 401 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing limadog9:fix/readlink-final-component-errors (168ed8d) with main (54d1309)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (aa74c61) during the generation of this report, so 54d1309 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@limadog9
limadog9 force-pushed the fix/readlink-final-component-errors branch from 4cdebf0 to 72d9098 Compare October 15, 2026 20:29
Comment on lines +409 to +410
|| (miss_mode == MissingHandling::Normal
&& (!parts.is_empty() || e.kind() != ErrorKind::NotFound))) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This condition is complex enough to justify an explanation comment IMO

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.

Added a comment explaining the three modes and why Normal allows only a missing final component. Regression tests pass; squashed and pushed.

@limadog9
limadog9 force-pushed the fix/readlink-final-component-errors branch from 72d9098 to 3bbb97f Compare October 16, 2026 13:28

This branch has not been deployed

No deployments
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.

readlink: Behaviour differs from GNU Coreutils when path exists but cannot be read

3 participants