Skip to content

chown: set group to owner's login group on "OWNER:" - #15204

Merged
sylvestre merged 2 commits into
uutils:mainfrom
varranvar:fix2154013
Oct 9, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
varranvar:fix2154013

Conversation

@varranvar

Copy link
Copy Markdown
Contributor

chown OWNER: FILE changed the owner but left the group unchanged,
while GNU chown sets the group to OWNER's login group. This fixes that
and adds test.

Fixes #12751

Copilot AI balanced review requested due to automatic review settings October 9, 2026 05:21

Copilot AI left a comment

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.

🟡 Changes recommended

The shared parser incorrectly changes --from=OWNER: filtering semantics.

1 open finding
What changed in this PR

Updates chown OWNER: to apply the owner’s login group.

Changes:

  • Resolves login groups during owner-spec parsing.
  • Adds unit and integration coverage.
File Description
src/​uu/​chown/​src/​chown.rs Implements login-group resolution.
tests/​by-util/​test_chown.rs Tests valid and invalid owner specifications.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/uu/chown/src/chown.rs
Comment on lines +223 to +228
if !user.is_empty() && group.is_empty() && spec != user {
// A separator was given but the group was not ("owner:"), so the
// group is set to the owner's login group.
return match Passwd::locate(user) {
// Lookup must occur through name, not ID, to be valid here.
Ok(passwd) if passwd.name == user => Ok((Some(passwd.uid), Some(passwd.gid))),
Comment thread src/uu/chown/src/chown.rs
return match Passwd::locate(user) {
// Lookup must occur through name, not ID, to be valid here.
Ok(passwd) if passwd.name == user => Ok((Some(passwd.uid), Some(passwd.gid))),
_ => Err(USimpleError::new(

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.

for an unknown user GNU says "invalid user: 'nosuchuser:'", not "invalid spec". Could you please keep the invalid-user error here and only use invalid spec for the numeric case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When I try it out I get this:

❯ gnuchown someone: file
gnuchown: invalid spec: ‘someone:’

So I think the "invalid spec" message is correct in this case.

Comment thread src/uu/chown/src/chown.rs Outdated
.arg("auserthatdoesntexist:")
.arg("f")
.fails()
.stderr_contains("chown: invalid spec: 'auserthatdoesntexist:'");

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.

this locks in the wrong message, GNU prints "invalid user" here

"chown USER:" left the group unchanged instead of setting it to
USER's login group like in GNU.
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:57

Copilot AI left a comment

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.

🟡 Changes recommended

The shared parser incorrectly constrains --from=OWNER: to the owner’s login group, contrary to its documented semantics.

3 open findings

🧠 Review effort: Balanced

let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());

let result = scene.cmd("id").arg("-gn").run();
Comment thread src/uu/chown/src/chown.rs
Comment on lines 199 to +203
/// and the owner or group can be specified either as an ID or a
/// name. The `sep` argument specifies which character to use as a
/// separator between the owner and group; calling code should set
/// this to `':'`.
/// this to `':'`. If a separator is given but the group is omitted
/// (as in `"owner:"`), the group is set to the owner's login group.
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

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

@sylvestre
sylvestre merged commit af46d13 into uutils:main Oct 9, 2026
97 checks passed
@sylvestre

Copy link
Copy Markdown
Contributor

Thanks for your PR

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.

chown USER: does not change group to user's login group

3 participants