Repository navigation
readlink: keep going after an operand that cannot be read - #14799
Conversation
An operand that failed to resolve returned from the loop at once, so the operands after it were never printed. GNU readlink prints every operand it can read, reports the ones it cannot when -v is given, and exits 1 at the end. Remember the failure and let the loop finish. Part of uutils#6688: the second half of that report, -f printing a path whose final link cannot be read, is a canonicalize question and is not touched here.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Adjusts readlink to continue processing remaining operands after encountering an unreadable/unresolvable operand, matching GNU readlink behavior for multi-operand invocations.
Changes:
- Track a
failedflag during operand iteration and only decide the final exit status after all operands are attempted. - Change non-verbose error handling to continue (instead of returning early) for multi-operand cases; maintain existing “stop on write error” behavior.
- Add regression tests covering plain,
-v, and-ecases with a missing operand in the middle.
| File | Description |
|---|---|
| tests/by-util/test_readlink.rs | Adds tests ensuring processing continues after an unreadable operand and exit status reflects failure after all operands. |
| src/uu/readlink/src/readlink.rs | Implements “keep going” behavior with a failed flag and final exit status selection. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // An operand that cannot be resolved does not stop the ones after it; the | ||
| // failure only decides the exit status once every operand has been tried. |
|
|
||
| #[test] | ||
| fn test_verbose_keeps_going_after_an_operand_that_cannot_be_read() { | ||
| let (at, mut ucmd) = at_and_ucmd!(); |
There was a problem hiding this comment.
same 4 lines of setup as the test above, could you merge the two cases in one test?
There was a problem hiding this comment.
Merged into one test in a06fc10: one setup, then the plain run and the -v run. It still fails on main at the first assertion.
| } | ||
| Err(err) => { | ||
| failed = true; | ||
| if !verbose { |
There was a problem hiding this comment.
could be just if verbose { ... } instead of the continue, no?
There was a problem hiding this comment.
Yes, done in a06fc10. The message is built inside if verbose { ... } now, and the loop just moves on to the next operand.
Merging this PR will improve performance by 19.67%
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
|
GNU testsuite comparison: |

Part of #6688.
With more than one operand,
readlinkreturned from the loop on the first one it could not resolve, so everything after it was silently skipped and the exit status was the only sign that the command had done anything at all:GNU readlink 9.7 prints
targetandt2, mentionsnopeon stderr only under-v, and exits 1 once every operand has been tried. The same holds for the canonicalize modes:readlink -e /etc/hosts /nope /etc/passwdprints both existing paths there and only the first one here.The change keeps a
failedflag, moves on after an unresolvable operand (still printing the diagnostic when-vis set), and turns the flag into the exit status at the end. Nothing changes for a single operand, and the write error fromshow()still stops the loop as before.Three tests in
test_readlink.rs, for the plain,-vand-eforms. All three fail onmain(foo\nwherefoo\nbaz\nis expected) and pass with the change; the file goes from 24 to 27 passing. Measured against/usr/bin/readlinkfrom coreutils 9.7 in a Debian container, comparing stdout, stderr and exit status; no GNU source was read.The other half of #6688,
-fprinting/proc/1/exewhere GNU prints nothing because the final link cannot be read, lives incanonicalizeand is left alone here.