Chgrp correct exit code (#10035)

This commit is contained in:
cerdelen
2026-01-09 11:31:24 +01:00
committed by GitHub
parent bda5c200e6
commit ebc08af9c3
2 changed files with 25 additions and 2 deletions
+2 -2
View File
@@ -619,7 +619,6 @@ impl ChownExecutor {
);
continue;
}
ret = match wrap_chown(
path,
&meta,
@@ -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 {
+23
View File
@@ -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();
}