Skip to content
Merged
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
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
23 changes: 23 additions & 0 deletions tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,26 @@ fn test_chgrp_recursive_on_file() {
current_gid
);
}

#[test]
fn test_chgrp_exit_code_not_being_overwritten_by_last_file() {
use std::os::unix::prelude::PermissionsExt;

let current_gid = getegid();
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir");
at.mkdir("dir/a");
at.mkdir("dir/b");
at.touch("dir/b/file");
at.touch("dir/a/file");
std::fs::set_permissions(at.plus("dir/a"), PermissionsExt::from_mode(0o0000)).unwrap();

// chgrp walks the dir alphabetically. Dir a does not have permissions so it fails, dir b does have
// permissions so it succeeds. We check that the overall command does fail although the
// last step succeeded.

ucmd.arg("-R")
.arg(current_gid.to_string())
.arg("dir")
.fails();
}
Loading