Skip to content

Commit 6a9f123

Browse files
committed
feat(rm): add progress bar support to recursive dir removal on Linux
Refactor `safe_remove_dir_recursive_impl` to accept an optional `ProgressBar` parameter instead of `dir_fd`, opening the directory internally. Add progress increments for each removed item to improve user feedback during long recursive operations.
1 parent bf28c9a commit 6a9f123

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,11 @@ pub fn safe_remove_dir_recursive(
342342
}
343343
}
344344

345-
pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Options) -> bool {
345+
pub fn safe_remove_dir_recursive_impl(
346+
path: &Path,
347+
options: &Options,
348+
progress_bar: Option<&ProgressBar>,
349+
) -> bool {
346350
// Read directory entries using safe traversal
347351
let dir_fd = match DirFd::open(path) {
348352
Ok(fd) => fd,
@@ -412,6 +416,9 @@ pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Opt
412416
if !child_error {
413417
match DirFd::open(path) {
414418
Ok(fd) => {
419+
if let Some(pb) = progress_bar {
420+
pb.inc(1);
421+
}
415422
error = handle_unlink(&fd, entry_name.as_ref(), &entry_path, true, options)
416423
|| error
417424
}
@@ -424,6 +431,9 @@ pub fn safe_remove_dir_recursive_impl(path: &Path, dir_fd: &DirFd, options: &Opt
424431
if prompt_file_with_stat(&entry_path, &entry_stat, options) {
425432
match DirFd::open(path) {
426433
Ok(fd) => {
434+
if let Some(pb) = progress_bar {
435+
pb.inc(1);
436+
}
427437
error = handle_unlink(&fd, entry_name.as_ref(), &entry_path, false, options)
428438
|| error
429439
}

0 commit comments

Comments
 (0)