Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/uucore/src/lib/features/perms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,6 @@ impl ChownExecutor {
);
continue;
}

ret = match wrap_chown(
path,
&meta,
Expand All @@ -632,7 +631,8 @@ impl ChownExecutor {
if !n.is_empty() {
show_error!("{n}");
}
0
// retain previous errors
ret.max(0)
}
Err(e) => {
if self.verbosity.level != VerbosityLevel::Silent {
Expand Down
21 changes: 21 additions & 0 deletions tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,24 @@ fn test_chgrp_recursive_on_file() {
current_gid
);
}

#[test]
#[cfg(not(target_vendor = "apple"))]
fn test_chgrp_exit_code_not_being_overwritten_by_last_file() {
use std::os::unix::prelude::PermissionsExt;

if let Some(group) = nix::unistd::getgroups().unwrap().first() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir");
at.mkdir("dir/subdir");
at.touch("dir/subdir/file");
at.touch("a");
std::fs::set_permissions(at.plus("dir/subdir"), PermissionsExt::from_mode(0o0000)).unwrap();
ucmd.arg("-R")
.arg(group.as_raw().to_string())
.arg("dir")
.arg("a")
.fails()
.stderr_only("chgrp: cannot access 'dir/subdir': Permission denied\n");
}
}
Loading