Merge pull request #9990 from cerdelen/chmod_recursive_hyper_nested_dirs

Chmod recursive hyper nested dirs
This commit is contained in:
cerdelen
2026-01-03 11:40:51 +01:00
committed by GitHub
parent baebd290f8
commit d28cb30c63
2 changed files with 19 additions and 3 deletions
+9 -3
View File
@@ -432,14 +432,20 @@ impl Chmoder {
// If the path is a directory (or we should follow symlinks), recurse into it
if (!file_path.is_symlink() || should_follow_symlink) && file_path.is_dir() {
// We buffer all paths in this dir to not keep to be able to close the fd so not
// too many fd's are open during the recursion
let mut paths_in_this_dir = Vec::new();
for dir_entry in file_path.read_dir()? {
let path = match dir_entry {
Ok(entry) => entry.path(),
match dir_entry {
Ok(entry) => paths_in_this_dir.push(entry.path()),
Err(err) => {
r = r.and(Err(err.into()));
continue;
}
};
}
}
for path in paths_in_this_dir {
if path.is_symlink() {
r = self.handle_symlink_during_recursion(&path).and(r);
} else {
+10
View File
@@ -407,6 +407,16 @@ fn test_chmod_recursive_correct_exit_code() {
.stderr_is(err_msg);
}
#[test]
fn test_chmod_hyper_recursive_directory_tree_does_not_fail() {
let (at, mut ucmd) = at_and_ucmd!();
let mkdir = "a/".repeat(400);
at.mkdir_all(&mkdir);
ucmd.arg("-R").arg("777").arg("a").succeeds();
}
#[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_recursive() {