Skip to content

chmod: only report umask-curtailed modes for option-like operands - #13731

Open
dhruv-15-03 wants to merge 1 commit into
uutils:mainfrom
dhruv-15-03:chmod-leading-hyphen-modes
Open

chmod: only report umask-curtailed modes for option-like operands#13731
dhruv-15-03 wants to merge 1 commit into
uutils:mainfrom
dhruv-15-03:chmod-leading-hyphen-modes

Conversation

@dhruv-15-03

@dhruv-15-03 dhruv-15-03 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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.

$ touch file && chmod 666 file && umask 022
$ chmod u+x,-w file
chmod: file: new permissions are r-xrw-rw-, not r-xr--r--   # exit 1
# GNU: no output, exit 0

Of 17 mode spellings compared against GNU (file at 0666, umask 022), 8 diverged.

Two cases pin the rule down: chmod -w -- file does report, so it isn't "--
suppresses the message"; and chmod -w,u+x file reports while chmod u+x,-w file
doesn't, though both have the same effect - so the rule is about how the mode was
spelled, not what it does.

extract_negative_modes already returns Some(..) exactly when it lifted
option-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 chmod in 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_chmod passes 51.
clippy and fmt are clean. I haven't compared against GNU releases other than 8.32.

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>
Copilot AI review requested due to automatic review settings August 3, 2026 16:38

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HackingRepo

HackingRepo commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@dhruv-15-03 please uses Fixes for close the issue automatically, because closing it manually is a expensive project

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)

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: passing multiple modes with leading hyphens.

3 participants