Repository navigation
chown: set group to owner's login group on "OWNER:" - #15204
Conversation
There was a problem hiding this comment.
🟡 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.
| 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))), |
| 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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| .arg("auserthatdoesntexist:") | ||
| .arg("f") | ||
| .fails() | ||
| .stderr_contains("chown: invalid spec: 'auserthatdoesntexist:'"); |
There was a problem hiding this comment.
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.
| let user_name = String::from(result.stdout_str().trim()); | ||
| assert!(!user_name.is_empty()); | ||
|
|
||
| let result = scene.cmd("id").arg("-gn").run(); |
| /// 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. |
|
GNU testsuite comparison: |
|
Thanks for your PR |


chown OWNER: FILEchanged 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