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/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl Chmoder {
return Err(ChmodError::PreserveRoot("/".to_string()).into());
}
if self.recursive {
r = self.walk_dir_with_context(file, true);
r = self.walk_dir_with_context(file, true).and(r);
} else {
r = self.chmod_file(file).and(r);
}
Expand Down
32 changes: 32 additions & 0 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,38 @@ fn test_permission_denied() {
.stderr_is("chmod: 'd/no-x/y': Permission denied\n");
}

#[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_recursive_correct_exit_code() {
let (at, mut ucmd) = at_and_ucmd!();

// create 3 folders to test on
at.mkdir("a");
at.mkdir("a/b");
at.mkdir("z");

// remove read permissions for folder a so the chmod command for a/b fails
let mut perms = at.metadata("a").permissions();
perms.set_mode(0o000);
set_permissions(at.plus_as_string("a"), perms).unwrap();

#[cfg(not(target_os = "linux"))]
let err_msg = "chmod: Permission denied\n";
#[cfg(target_os = "linux")]
let err_msg = "chmod: 'a': Permission denied\n";

// order of command is a, a/b then c
// command is expected to fail and not just take the last exit code
ucmd.arg("-R")
.arg("--verbose")
.arg("a+w")
.arg("a")
.arg("z")
.umask(0)
.fails()
.stderr_is(err_msg);
}

#[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_recursive() {
Expand Down
Loading