-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chgrp: add option --from #7129
base: main
Are you sure you want to change the base?
chgrp: add option --from #7129
Conversation
e94d84d
to
78cff4f
Compare
GNU testsuite comparison:
|
1b3db36
to
f195b52
Compare
GNU testsuite comparison:
|
I added a similar function |
indeed but as it uses ChrootError, it will require a bunch of refactor for 4 lines |
GNU testsuite comparison:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment, but it makes sense to me!
@@ -19,6 +19,24 @@ use std::os::unix::fs::MetadataExt; | |||
const ABOUT: &str = help_about!("chgrp.md"); | |||
const USAGE: &str = help_usage!("chgrp.md"); | |||
|
|||
fn parse_gid_from_str(group: &str) -> Result<u32, String> { | |||
if let Some(gid_str) = group.strip_prefix(':') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the option is --from=:foo
, could foo
be a group name? This code assumes it is always a numeric group ID, I think. The docs (for chown
, but I think it applies to chgrp
also) seem to imply that it can be a group name: https://www.gnu.org/software/coreutils/manual/html_node/chown-invocation.html
Also, the docs for chgrp
say
Change a file’s ownership only if it has current attributes specified by old-owner. old-owner has the same form as new-owner described above.
new-owner is described in the chown
documentation as allowing anything of the form [USER] [: [GROUP]]
. If that's true, then we should check for user names and IDs too.
All of these can be fixed separately (and common code refactored from chgrp
, chown
, and chroot
), I just wanted to share my understanding of the GNU documentation.
#[test] | ||
#[cfg(not(target_vendor = "apple"))] | ||
fn test_from_with_invalid_group() { | ||
let (at, mut ucmd) = at_and_ucmd!(); | ||
at.touch("test_file"); | ||
#[cfg(not(target_os = "android"))] | ||
let err_msg = "chgrp: invalid group: 'nonexistent_group'\n"; | ||
#[cfg(target_os = "android")] | ||
let err_msg = "chgrp: invalid group: 'staff'\n"; | ||
|
||
ucmd.arg("--from") | ||
.arg("nonexistent_group") | ||
.arg("staff") | ||
.arg("test_file") | ||
.fails() | ||
.stderr_is(err_msg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails on my machine. And I don't know if the error message is deliberately different from GNU chgrp
. With GNU it is about an invalid user and not about an invalid group.
$ cargo run --features=unix -q chgrp --from nonexistent_group staff README.md
chgrp: invalid group: 'staff'
$ chgrp --from nonexistent_group staff README.md
chgrp: invalid user: ‘nonexistent_group’
return; | ||
} | ||
|
||
at.touch("test_file"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is not needed as it isn't used anywhere else in this test.
at.touch("test_file"); |
Should make tests/chgrp/from pass