Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

chgrp: add option --from #7129

wants to merge 5 commits into from

Conversation

sylvestre
Copy link
Contributor

Should make tests/chgrp/from pass

@sylvestre sylvestre force-pushed the chgrp branch 2 times, most recently from e94d84d to 78cff4f Compare January 12, 2025 20:47
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/chgrp/from is no longer failing!
Congrats! The gnu test tests/df/over-mount-device is no longer failing!

@sylvestre sylvestre force-pushed the chgrp branch 5 times, most recently from 1b3db36 to f195b52 Compare January 12, 2025 21:57
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/misc/stdbuf is no longer failing!
GNU test failed: tests/cp/cross-dev-symlink. tests/cp/cross-dev-symlink is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/chgrp/from is no longer failing!

@jfinkels
Copy link
Collaborator

I added a similar function name_to_gid in chroot, in case it helps you

@sylvestre
Copy link
Contributor Author

indeed but as it uses ChrootError, it will require a bunch of refactor for 4 lines
maybe as a good first bugs later?

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/chgrp/from is no longer failing!

Copy link
Collaborator

@jfinkels jfinkels left a 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(':') {
Copy link
Collaborator

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.

@jfinkels jfinkels linked an issue Jan 14, 2025 that may be closed by this pull request
Comment on lines +468 to +484
#[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);
}
Copy link
Contributor

@cakebaker cakebaker Jan 14, 2025

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");
Copy link
Contributor

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.

Suggested change
at.touch("test_file");

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.

chgrp: add --from option
3 participants