Skip to content

readlink: keep going after an operand that cannot be read - #14799

Merged
sylvestre merged 2 commits into
uutils:mainfrom
luantaraschi:fix/readlink-continue-after-error
Sep 27, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
luantaraschi:fix/readlink-continue-after-error

Conversation

@luantaraschi

Copy link
Copy Markdown
Contributor

Part of #6688.

With more than one operand, readlink returned 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:

$ ln -s target good; ln -s t2 good2
$ readlink good nope good2
target
$ echo $?
1

GNU readlink 9.7 prints target and t2, mentions nope on 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/passwd prints both existing paths there and only the first one here.

The change keeps a failed flag, moves on after an unresolvable operand (still printing the diagnostic when -v is set), and turns the flag into the exit status at the end. Nothing changes for a single operand, and the write error from show() still stops the loop as before.

Three tests in test_readlink.rs, for the plain, -v and -e forms. All three fail on main (foo\n where foo\nbaz\n is expected) and pass with the change; the file goes from 24 to 27 passing. Measured against /usr/bin/readlink from coreutils 9.7 in a Debian container, comparing stdout, stderr and exit status; no GNU source was read.

The other half of #6688, -f printing /proc/1/exe where GNU prints nothing because the final link cannot be read, lives in canonicalize and is left alone here.

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.
Copilot AI lite review requested due to automatic review settings September 21, 2026 21:40

Copilot AI left a comment

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.

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 Low severity

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 failed flag 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 -e cases 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.

Comment on lines +79 to +80
// 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.
Comment thread tests/by-util/test_readlink.rs Outdated

#[test]
fn test_verbose_keeps_going_after_an_operand_that_cannot_be_read() {
let (at, mut ucmd) = at_and_ucmd!();

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 4 lines of setup as the test above, could you merge the two cases in one test?

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.

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.

Comment thread src/uu/readlink/src/readlink.rs Outdated
}
Err(err) => {
failed = true;
if !verbose {

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 if verbose { ... } instead of the continue, no?

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, done in a06fc10. The message is built inside if verbose { ... } now, and the loop just moves on to the next operand.

Copilot AI review requested due to automatic review settings September 25, 2026 06:16

Copilot AI left a comment

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.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified, and all assessments indicate readiness.

Review effort: Lite
Findings: 1 Low severity

Open (1)

@codspeed

codspeed Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 19.67%

⚡ 1 improved benchmark
✅ 388 untouched benchmarks
⏩ 54 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Simulation five_38_bit_primes 2.1 s 1.7 s +19.67%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing luantaraschi:fix/readlink-continue-after-error (a06fc10) with main (a5080ba)

Open in CodSpeed

Footnotes

  1. 54 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
Copy Markdown

GNU testsuite comparison:

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

@sylvestre
sylvestre enabled auto-merge (rebase) September 25, 2026 12:22
@sylvestre
sylvestre disabled auto-merge September 27, 2026 19:04
@sylvestre
sylvestre merged commit b2c35f1 into uutils:main Sep 27, 2026
190 checks passed
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.

3 participants