Skip to content

realpath: fail on dangling symlink with -s -e - #16034

Open
Logic769 wants to merge 5 commits into
uutils:mainfrom
Logic769:realpath-e-dangling-symlink
Open

Logic769 wants to merge 5 commits into
uutils:mainfrom
Logic769:realpath-e-dangling-symlink

Conversation

@Logic769

Copy link
Copy Markdown
Contributor

Problem

realpath -s -e dangling printed a path and exited 0, but with -e every component must exist; GNU reports 'No such file or directory' and exits 1.

Change

When -e is given, verify that the resulting path actually resolves before printing it. Added a regression test.

Closes #15996

@Logic769
Logic769 force-pushed the realpath-e-dangling-symlink branch from 51b595c to bc0586c Compare October 30, 2026 13:02
Comment thread src/uu/realpath/src/realpath.rs Resolved
Comment thread src/uu/realpath/src/realpath.rs Resolved
Comment thread tests/by-util/test_realpath.rs Resolved
@Logic769
Logic769 force-pushed the realpath-e-dangling-symlink branch from bc0586c to 674e264 Compare October 31, 2026 01:52
@Logic769

Copy link
Copy Markdown
Contributor Author

The check only applies with -e/--canonicalize-existing now (ResolveMode::None plus MissingHandling::Existing), and the test also asserts stdout stays empty.

@cakebaker
cakebaker force-pushed the realpath-e-dangling-symlink branch from 674e264 to 12a7543 Compare November 1, 2026 15:48
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/tail/follow-name is no longer failing!
Congrats! The gnu test tests/tail/pid-pipe is no longer failing!

@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 2 benchmarks

2 warnings, 1 note

⚠️ 123 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

⚠️ 4 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 409 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory timeout_enforced 88.8 KB 163.6 KB -45.74%
❌ Memory cp_recursive_deep_tree[(120, 4)] 670.5 KB 788.5 KB -14.97%
⚡ Memory socket_addrs_direct[100000] 68 KB 8.6 KB ×7.9
⚡ Memory hostname_ip_lookup[100000] 159.7 KB 100.3 KB +59.19%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Logic769:realpath-e-dangling-symlink (6191c9e) with main (dded1b5)

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

Comment thread src/uucore/src/lib/features/fs.rs Resolved
@sylvestre

Copy link
Copy Markdown
Contributor

a bunch of jobs are failing

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.49 MB (+108 KB, +0.07%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

@Logic769
Logic769 force-pushed the realpath-e-dangling-symlink branch from 331c1e9 to 79e0113 Compare November 18, 2026 04:38
@Logic769

Copy link
Copy Markdown
Contributor Author

CI note: the Build MSYS (windows-latest, feat_os_windows) job failed in its packaging step, not in this PR's code:

mv target/release-small/deps/stdbuf.dll -t /tmp/c/usr/local/bin
mv: cannot stat 'target/release-small/deps/stdbuf.dll': No such file or directory

The same stdbuf.dll packaging failure is appearing on several unrelated PRs, so it looks like an MSYS/Windows packaging issue in the shared make workflow rather than a failure caused by this change.

@sylvestre
sylvestre force-pushed the realpath-e-dangling-symlink branch from 79e0113 to b75f924 Compare November 19, 2026 14:48
Comment thread src/uucore/src/lib/features/fs.rs Resolved
Comment thread tests/by-util/test_realpath.rs Resolved
Comment thread tests/by-util/test_realpath.rs Resolved
realpath -s resolved file/.. to the parent directory of file because .. was popped before the accumulated path was checked. GNU fails with "Not a directory", and with a missing component it fails with "No such file or directory", so .. has to verify that the component it leaves exists and is a directory.

Check the accumulated path before popping it when symlinks are not resolved and missing components are not allowed, reusing ensure_is_directory. -m still never touches the filesystem.

Add regression tests for file/.., missing/.., dir/.. and -s -m file/..
@sylvestre
sylvestre force-pushed the realpath-e-dangling-symlink branch from 6191c9e to 0d81110 Compare November 24, 2026 00:11

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.

realpath: -s -e does not fail on a dangling symlink

2 participants