Skip to content

readlink: ensure last of -e / -f / -m takes precedence - #16401

Open
abdul-karim-mia wants to merge 1 commit into
uutils:mainfrom
abdul-karim-mia:fix/readlink-canonicalize-precedence
Open

abdul-karim-mia wants to merge 1 commit into
uutils:mainfrom
abdul-karim-mia:fix/readlink-canonicalize-precedence

Conversation

@abdul-karim-mia

Copy link
Copy Markdown

Description

Fixes #15995

In GNU readlink, specifying multiple canonicalize options (-f / --canonicalize, -e / --canonicalize-existing, and -m / --canonicalize-missing) follows last-flag-wins semantics. For example:

readlink -e --canonicalize missing

In GNU coreutils, --canonicalize (-f) came last, so it resolves the missing path (exiting 0). In uutils/coreutils, the argument definitions for the three canonicalize options did not declare mutual overrides, and can_mode evaluated -e before -m and -f, causing -e to always win regardless of option order.

Solution

  1. Added .overrides_with_all([OPT_CANONICALIZE, OPT_CANONICALIZE_EXISTING, OPT_CANONICALIZE_MISSING]) to each of OPT_CANONICALIZE, OPT_CANONICALIZE_EXISTING, and OPT_CANONICALIZE_MISSING in uu_app(), mirroring the existing overrides pattern used for [OPT_QUIET, OPT_SILENT, OPT_VERBOSE].
  2. Added comprehensive integration tests in tests/by-util/test_readlink.rs (test_canonicalize_precedence) covering all order permutations between -e, -f, and -m.

Verification

  • cargo test --features readlink --test tests test_canonicalize_precedence: Passed (1/1)
  • cargo fmt --check: Passed (no diff)
  • cargo clippy -p uu_readlink: Passed (0 warnings)

@aozmekik aozmekik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checked this against GNU coreutils 9.12 (Debian sid): every order of -e/-f/-m (pairs, triples, bundled ones like -ef and -mfe, and the long names) on an existing file, a good and a dangling symlink, missing, missing/nested, dir/missing and a symlink loop, for both readlink and realpath. Of the 238 cases, main differs from GNU in 50 and this branch in 10, and all 10 are -m on the symlink loop, which is #16325. It also fixes -m -f missing/nested, which main accepted.

@github-actions

github-actions Bot commented Nov 13, 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!

@abdul-karim-mia
abdul-karim-mia force-pushed the fix/readlink-canonicalize-precedence branch from aeb3370 to 59f4390 Compare November 17, 2026 13:24
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Binary size comparison:

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

Total size of compared binaries: 155.48 MB (+100 KB, +0.06%)

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

@sylvestre
sylvestre force-pushed the fix/readlink-canonicalize-precedence branch from 59f4390 to 974e940 Compare November 18, 2026 09:25
@abdul-karim-mia
abdul-karim-mia force-pushed the fix/readlink-canonicalize-precedence branch from 974e940 to 93e943c Compare November 19, 2026 09:25
…15995)

Add overrides_with_all across OPT_CANONICALIZE, OPT_CANONICALIZE_EXISTING, and OPT_CANONICALIZE_MISSING so that whichever flag is specified last takes precedence, matching GNU coreutils behavior.

Add integration tests verifying precedence across all canonicalize flag permutations.

Signed-off-by: Abdul karim mia <[email protected]>
@abdul-karim-mia
abdul-karim-mia force-pushed the fix/readlink-canonicalize-precedence branch from 93e943c to f61f2af Compare November 19, 2026 13:55

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: the last of -e / -f / -m should win

2 participants