chmod: only report umask-curtailed modes for option-like operands - #13731
Open
dhruv-15-03 wants to merge 1 commit into
Open
chmod: only report umask-curtailed modes for option-like operands#13731dhruv-15-03 wants to merge 1 commit into
dhruv-15-03 wants to merge 1 commit into
Conversation
GNU prints "new permissions are X, not Y" and exits 1 when a umask-relative mode such as `-w` could not remove everything it asked for, but it only does so when the mode was written in the option-like form, e.g. `chmod -w file`. When the mode arrives as an ordinary positional operand the message is not printed and the exit status is 0. Comparing 17 mode spellings against GNU coreutils 8.32 with a file at 0666 and umask 022, 8 diverged, all in the same direction: uutils reported and exited 1 where GNU was silent and exited 0. That includes `chmod u+x,-w file`, an entirely ordinary command with no `--` involved. `extract_negative_modes` already returns `Some(..)` exactly when it lifted option-like mode fragments out of the argument list, which is the predicate needed, so record it and gate the diagnostic on it. Also add the complete 26-row operand matrix from the issue report as a regression test. Those rows already pass, but nothing pinned them. Refs uutils#3147 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
|
@dhruv-15-03 please uses |
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3147
GNU only reports a umask conflict when the mode was spelled like an option - a
leading-hyphen argument to the left of any
--. uutils reported it for any mode.The resulting permission bits were already correct; only the message and the exit
status differed.
Of 17 mode spellings compared against GNU (file at
0666,umask 022), 8 diverged.Two cases pin the rule down:
chmod -w -- filedoes report, so it isn't "--suppresses the message"; and
chmod -w,u+x filereports whilechmod u+x,-w filedoesn't, though both have the same effect - so the rule is about how the mode was
spelled, not what it does.
extract_negative_modesalready returnsSome(..)exactly when it liftedoption-like mode fragments out of the argument list, which is the predicate needed.
The diagnostic is now gated on that. The mode arithmetic is unchanged.
On #3147 itself: the 26-row operand matrix already passes on main - it was fixed by
e982d57 in 2023 and the issue was never closed. Nothing in the suite pinned it,
so this adds the full matrix as a regression test, including the rows that differ
only in where
--sits.Verified against the GNU
chmodin Ubuntu 22.04 (coreutils 8.32) as a black box,no GNU source consulted: all 26 matrix rows match on operands, exit status and
resulting permissions; all 17 diagnostic spellings now match, 8 having differed
before.
cargo test --features chmod --no-default-features test_chmodpasses 51.clippy and fmt are clean. I haven't compared against GNU releases other than 8.32.