Skip to content

Commit f4aed24

Browse files
committed
refactor(rm): Use DirFd for recursive child dir removal in Linux
- Add DirFd opening for child directories before recursive calls in safe_remove_dir_recursive_impl - Enhances performance and correctness by leveraging file descriptors in recursive removal欧美
1 parent 1619870 commit f4aed24

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/uu/rm/src/platform/linux.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,16 @@ pub fn safe_remove_dir_recursive_impl(
358358
continue;
359359
}
360360

361-
let child_error = safe_remove_dir_recursive_impl(&entry_path, options, progress_bar);
361+
let child_dir_fd = match DirFd::open(&entry_path) {
362+
Ok(fd) => fd,
363+
Err(e) => {
364+
error = handle_error_with_force(e, &entry_path, options) || error;
365+
continue;
366+
}
367+
};
368+
369+
let child_error =
370+
safe_remove_dir_recursive_impl(&entry_path, child_dir_fd, options, progress_bar);
362371
error = error || child_error;
363372

364373
if !child_error

0 commit comments

Comments
 (0)