Skip to content

Commit 2fefe61

Browse files
committed
refactor(rm): simplify recursive directory removal logic
Remove wrapper functions `remove_dir_recursive` and `remove_dir_recursive_with_parent`, and inline conditional compilation directly in `handle_dir_impl` to reduce code duplication and improve maintainability without altering functionality.
1 parent 5aebfa9 commit 2fefe61

File tree

1 file changed

+11
-40
lines changed

1 file changed

+11
-40
lines changed

src/uu/rm/src/rm.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -647,45 +647,6 @@ fn compute_next_parent_dev_id(_options: &Options, _metadata: &Metadata) -> Optio
647647
None
648648
}
649649

650-
#[cfg(unix)]
651-
fn remove_dir_recursive(
652-
path: &Path,
653-
options: &Options,
654-
progress_bar: Option<&ProgressBar>,
655-
parent_dev_id: Option<u64>,
656-
) -> bool {
657-
remove_dir_recursive_impl(path, options, progress_bar, parent_dev_id)
658-
}
659-
660-
#[cfg(not(unix))]
661-
fn remove_dir_recursive(
662-
path: &Path,
663-
options: &Options,
664-
progress_bar: Option<&ProgressBar>,
665-
) -> bool {
666-
remove_dir_recursive_impl(path, options, progress_bar, None)
667-
}
668-
669-
#[cfg(unix)]
670-
fn remove_dir_recursive_with_parent(
671-
path: &Path,
672-
options: &Options,
673-
progress_bar: Option<&ProgressBar>,
674-
parent_dev_id: Option<u64>,
675-
) -> bool {
676-
remove_dir_recursive(path, options, progress_bar, parent_dev_id)
677-
}
678-
679-
#[cfg(not(unix))]
680-
fn remove_dir_recursive_with_parent(
681-
path: &Path,
682-
options: &Options,
683-
progress_bar: Option<&ProgressBar>,
684-
_parent_dev_id: Option<u64>,
685-
) -> bool {
686-
remove_dir_recursive(path, options, progress_bar)
687-
}
688-
689650
/// Recursively remove the directory tree rooted at the given path.
690651
///
691652
/// If `path` is a file or a symbolic link, just remove it. If it is a
@@ -850,6 +811,9 @@ fn handle_dir_impl(
850811
progress_bar: Option<&ProgressBar>,
851812
parent_dev_id: Option<u64>,
852813
) -> bool {
814+
#[cfg(not(unix))]
815+
let _ = parent_dev_id;
816+
853817
let mut had_err = false;
854818

855819
let path = clean_trailing_slashes(path);
@@ -863,7 +827,14 @@ fn handle_dir_impl(
863827

864828
let is_root = path.has_root() && path.parent().is_none();
865829
if options.recursive && (!is_root || !options.preserve_root) {
866-
had_err = remove_dir_recursive_with_parent(path, options, progress_bar, parent_dev_id);
830+
#[cfg(unix)]
831+
{
832+
had_err = remove_dir_recursive_impl(path, options, progress_bar, parent_dev_id);
833+
}
834+
#[cfg(not(unix))]
835+
{
836+
had_err = remove_dir_recursive_impl(path, options, progress_bar, None);
837+
}
867838
} else if options.dir && (!is_root || !options.preserve_root) {
868839
had_err = remove_dir(path, options, progress_bar).bitor(had_err);
869840
} else if options.recursive {

0 commit comments

Comments
 (0)