Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn wrap_chown<P: AsRef<Path>>(
format!(
"group of {} retained as {}",
path.quote(),
entries::gid2grp(dest_gid).unwrap_or_default()
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
)
} else {
format!(
Expand Down
23 changes: 22 additions & 1 deletion tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use std::os::unix::ffi::OsStringExt;
use uucore::process::getegid;
use uutests::{at_and_ucmd, new_ucmd};
#[cfg(not(target_vendor = "apple"))]
use uutests::{util::TestScenario, util_name};

#[test]
Expand Down Expand Up @@ -640,3 +639,25 @@ fn test_chgrp_recursive_on_file() {
current_gid
);
}

#[test]
fn test_chgrp_verbose_for_unmapped_gid() {
// To be able to change the gid we need root privileges so we skip if the user running the test
// suite does not have root privileges
if getegid() == 0 {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.touch("tmp");

scene.ucmd().arg("1337").arg("tmp").succeeds().no_stderr();

scene
.ucmd()
.arg("-v")
.arg("1337")
.arg("tmp")
.succeeds()
.stderr_contains("chgrp: group of 'tmp' retained as 1337");
}
}
Loading