Skip to content

Commit 2957789

Browse files
committed
refactor(rm): simplify control flow in safe_remove_dir_recursive_impl
Replaced nested if-else logic with direct else-if in the file removal path to reduce code nesting and improve readability for handling interactive prompts during recursive directory removal.
1 parent 6a9f123 commit 2957789

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,26 +420,24 @@ pub fn safe_remove_dir_recursive_impl(
420420
pb.inc(1);
421421
}
422422
error = handle_unlink(&fd, entry_name.as_ref(), &entry_path, true, options)
423-
|| error
423+
|| error;
424424
}
425425
Err(e) => {
426426
error = handle_error_with_force(e, &entry_path, options) || error;
427427
}
428428
}
429429
}
430-
} else {
431-
if prompt_file_with_stat(&entry_path, &entry_stat, options) {
432-
match DirFd::open(path) {
433-
Ok(fd) => {
434-
if let Some(pb) = progress_bar {
435-
pb.inc(1);
436-
}
437-
error = handle_unlink(&fd, entry_name.as_ref(), &entry_path, false, options)
438-
|| error
439-
}
440-
Err(e) => {
441-
error = handle_error_with_force(e, &entry_path, options) || error;
430+
} else if prompt_file_with_stat(&entry_path, &entry_stat, options) {
431+
match DirFd::open(path) {
432+
Ok(fd) => {
433+
if let Some(pb) = progress_bar {
434+
pb.inc(1);
442435
}
436+
error = handle_unlink(&fd, entry_name.as_ref(), &entry_path, false, options)
437+
|| error;
438+
}
439+
Err(e) => {
440+
error = handle_error_with_force(e, &entry_path, options) || error;
443441
}
444442
}
445443
}

0 commit comments

Comments
 (0)