Skip to content

chmod: change the referent of symlinks met under -R --dereference - #16714

Open
aozmekik wants to merge 1 commit into
uutils:mainfrom
aozmekik:chmod-dereference-in-tree
Open

aozmekik wants to merge 1 commit into
uutils:mainfrom
aozmekik:chmod-dereference-in-tree

Conversation

@aozmekik

Copy link
Copy Markdown

With --dereference, chmod -R now changes the referent of each symlink it meets while recursing, without descending into it (that is still -L). A link that can't be followed is reported as cannot dereference 'x': ... and chmod exits 1, and under --preserve-root a link to / is refused instead of skipped silently. Plain -R, -H, -h and -P behave as before.

I compared this with the GNU chmod 9.12 binary on trees with links to files and directories inside and outside the tree, a dangling link, a loop and a link to /, under -R, --dereference, -h, -H, -L, -P and --preserve-root. The --dereference cases now match. One difference is left on purpose: after refusing a link to /, GNU also skips the next entry in that directory, which looks like a bug there.

The ignored test from #16493 made its link with symlink_file, which prefixes the fixture path to ../target and leaves the link dangling. It now uses relative_symlink_file and runs.

Closes #16505

Comment thread src/uu/chmod/src/chmod.rs Outdated
traverse_symlinks,
dereference,
#[cfg(not(target_os = "redox"))]
dereference_in_tree: dereference

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.

do we need dereference && here? --dereference already implies it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right, it's not needed. configure_symlink_and_recursion already returns true when --dereference is given. Dropped it.

@github-actions

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!

When --dereference is given, chmod -R also changes the referent of each
symlink found while recursing, without descending into it (only -L does
that). A link that cannot be followed is reported as "cannot dereference",
and a link to / is refused under --preserve-root. This was compared with
the GNU chmod binary. Plain -R still leaves such links alone.

The ignored test for this created its link with symlink_file(), which
prefixes the fixture path to "../target" and leaves the link dangling.
Use relative_symlink_file() and enable the test.

Closes uutils#16505
@aozmekik
aozmekik force-pushed the chmod-dereference-in-tree branch from abb99f2 to 02e459a Compare November 20, 2026 07:12
@sylvestre

Copy link
Copy Markdown
Contributor

a bunch of jobs are failing

@aozmekik

Copy link
Copy Markdown
Author

I looked at them, they don't seem related to chmod. The two Build jobs fail in test_tail (test_follow_when_files_are_pointing_to_same_relative_file_and_file_stays_same_size on i686-musl, test_retry_descriptor_detects_truncation on PGO), and test_chmod passes in both. The L10n one fails with "Could not find embedded_locales.rs" while building uu_yes, and it's red on other branches too. I can rebase if that helps.

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.

chmod: -R --dereference skips symlinks found while recursing

2 participants