+
Skip to content

Conversation

CSRessel
Copy link
Contributor

Fixes #7214

@CSRessel CSRessel force-pushed the bugfix/chmod-dangling-symlink branch from 6f5a2c1 to f04bb82 Compare March 31, 2025 01:03
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Comment on lines 896 to 897
.stdout_is("")
.stderr_is("");
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify this to .no_output().

@cakebaker
Copy link
Contributor

I think your PR is only a partial solution and it breaks some functionality that currently works.

Before your changes:

$ cargo run -q --features=unix chmod 755 -R dangling_symlink 
chmod: cannot operate on dangling symlink 'dangling_symlink'
$ echo $?
1
$ cargo run -q --features=unix chmod 755 -R -P dangling_symlink 
chmod: cannot operate on dangling symlink 'dangling_symlink'
$ echo $?
1

After your changes:

$ cargo run -q --features=unix chmod 755 -R dangling_symlink
$ echo $?
0
$ cargo run -q --features=unix chmod 755 -R -P dangling_symlink
$ echo $?
0

And what GNU chmod does:

$ chmod 755 -R dangling_symlink 
chmod: cannot operate on dangling symlink 'dangling_symlink'
$ echo $?
1
$ chmod 755 -R -P dangling_symlink 
$ echo $?
0

@CSRessel
Copy link
Contributor Author

Ah I did not fully understand the flag interaction mentioned at the bottom of the issue, thank you for the examples. Will fix that up tonight, and add the extra unit test for that failure case

@CSRessel
Copy link
Contributor Author

CSRessel commented Apr 2, 2025

A couple of different learnings while fully grokking the flag combinations here:

  1. chmod was using the traversal default from chown, which is not the same
    a. https://www.man7.org/linux/man-pages/man1/chmod.1.html "... -H is the default."
    b. https://man7.org/linux/man-pages/man1/chown.1.html "... -P is the default."
  2. chmod -R -H doesn't seem to work correctly, repro below

I have added tests for each of these scenarios, plus extended the unit tests for all of the positive and negative unit tests for all the dangling link scenarios.

For functionality, I have fixed the original bug, and I have fixed the default traversal flag. I have not yet fixed the -H bug, but have traced it to the file_path == file_path.canonicalize().unwrap_or(file_path.to_path_buf()) test within walk_dirs, which is not doing what was intended. Will explore more to close this out!

chmod -R -H Repro

Given:

$ mkdir -p example/tmp
$ cd example 
$ touch tmp/{a,b}
$ ln -s tmp arg_symlink             
$ ls -l
total 4
lrwxrwxrwx 1 me me    3 Apr  2 02:00 arg_symlink -> tmp
drwxrwxr-x 2 me me 4096 Apr  2 02:00 tmp
$ ls -l tmp
total 0
-rw-rw-r-- 1 me me 0 Apr  2 02:00 a
-rw-rw-r-- 1 me me 0 Apr  2 02:00 b

uutils behavior on main:

$ cargo run -q --features=unix chmod u+x -R -H arg_symlink
$ ls -l
total 4
lrwxrwxrwx 1 me me    3 Apr  2 02:00 arg_symlink -> tmp
drwxrwxr-x 2 me me 4096 Apr  2 02:00 tmp
$ ls -l tmp
total 0
-rw-rw-r-- 1 me me 0 Apr  2 02:00 a
-rw-rw-r-- 1 me me 0 Apr  2 02:00 b

coreutils behavior on 9.6:

$ which chmod
/home/me/Documents/builds/coreutils-9.6/src/chmod
$ chmod u+x -R -H arg_symlink
$ ls -l    
total 4
lrwxrwxrwx 1 me me    3 Apr  2 02:00 arg_symlink -> tmp
drwxrwxr-x 2 me me 4096 Apr  2 02:00 tmp
$ ls -l tmp                  
total 0
-rwxrw-r-- 1 me me 0 Apr  2 02:00 a
-rwxrw-r-- 1 me me 0 Apr  2 02:00 b

Copy link

github-actions bot commented Apr 2, 2025

GNU testsuite comparison:

Congrats! The gnu test tests/chmod/symlinks is no longer failing!

@CSRessel
Copy link
Contributor Author

CSRessel commented Apr 3, 2025

Because the chmod -P -H finding is entirely new, and the fix will focus on lines mostly unrelated to this diff (within walk_dir) and I haven't started much work on it, I'm going to file a separate issue. I've removed the new -P -H tests that examined a symlink command argument, and can re-add those while fixing the follow-on issue

This PR should be ready to review again!

Copy link

github-actions bot commented Apr 3, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/chmod/symlinks is no longer failing!

@CSRessel
Copy link
Contributor Author

CSRessel commented Apr 5, 2025

I created a Lima VM locally to match the SELinux build steps and see what the test failure is. Tried to match the GH workflow as much as possible, but had to install the rust toolchain myself in the VM.

$ limactl start --plain --name=default --cpus=1 --disk=30 --memory=4 --network=lima:user-v2 template://fedora
$ lima mkdir work
$ limactl copy -r ./* default:~/work/

And then after running the test suite, I wasn't able to reproduce the test failure:

$ cd work && cargo test --features 'feat_selinux'
...

test result: ok. 3435 passed; 0 failed; 44 ignored; 0 measured; 0 filtered out; finished in 221.65s

Is it possible that this is a test flake? What's the best way to proceed here?

@cakebaker cakebaker merged commit b7bf8c9 into uutils:main Apr 7, 2025
105 of 106 checks passed
@cakebaker
Copy link
Contributor

Congrats! The gnu test tests/chmod/symlinks is no longer failing!

Great :) And thanks for your PR!

nickorlow pushed a commit to nickorlow/coreutils that referenced this pull request Jul 17, 2025
* Correct chmod -R on dangling symlink and tests

* Add tests of arg-level symlink to chmod

* Add tests of all symlink flag combos on chmod dangling

* Fix no traverse on dangling symlink

* Add chmod recursive tests of default symlink method

* Add default chmod -H flag tests

* Set chmod default traversal method correctly to -H

* Fix arg symlink chmod case

* Remove extra chmod -H testing

---------

Co-authored-by: Clifford Ressel <EMAIL@gmail.com>
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: errors with -R flag on dangling link but shouldn't

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载