Skip to content

Commit 783015a

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 3217cf6 commit 783015a

1 file changed

Lines changed: 11 additions & 40 deletions

File tree

src/uu/rm/src/rm.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -637,45 +637,6 @@ fn compute_next_parent_dev_id(_options: &Options, _metadata: &Metadata) -> Optio
637637
None
638638
}
639639

640-
#[cfg(unix)]
641-
fn remove_dir_recursive(
642-
path: &Path,
643-
options: &Options,
644-
progress_bar: Option<&ProgressBar>,
645-
parent_dev_id: Option<u64>,
646-
) -> bool {
647-
remove_dir_recursive_impl(path, options, progress_bar, parent_dev_id)
648-
}
649-
650-
#[cfg(not(unix))]
651-
fn remove_dir_recursive(
652-
path: &Path,
653-
options: &Options,
654-
progress_bar: Option<&ProgressBar>,
655-
) -> bool {
656-
remove_dir_recursive_impl(path, options, progress_bar, None)
657-
}
658-
659-
#[cfg(unix)]
660-
fn remove_dir_recursive_with_parent(
661-
path: &Path,
662-
options: &Options,
663-
progress_bar: Option<&ProgressBar>,
664-
parent_dev_id: Option<u64>,
665-
) -> bool {
666-
remove_dir_recursive(path, options, progress_bar, parent_dev_id)
667-
}
668-
669-
#[cfg(not(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)
677-
}
678-
679640
/// Recursively remove the directory tree rooted at the given path.
680641
///
681642
/// If `path` is a file or a symbolic link, just remove it. If it is a
@@ -840,6 +801,9 @@ fn handle_dir_impl(
840801
progress_bar: Option<&ProgressBar>,
841802
parent_dev_id: Option<u64>,
842803
) -> bool {
804+
#[cfg(not(unix))]
805+
let _ = parent_dev_id;
806+
843807
let mut had_err = false;
844808

845809
let path = clean_trailing_slashes(path);
@@ -853,7 +817,14 @@ fn handle_dir_impl(
853817

854818
let is_root = path.has_root() && path.parent().is_none();
855819
if options.recursive && (!is_root || !options.preserve_root) {
856-
had_err = remove_dir_recursive_with_parent(path, options, progress_bar, parent_dev_id);
820+
#[cfg(unix)]
821+
{
822+
had_err = remove_dir_recursive_impl(path, options, progress_bar, parent_dev_id);
823+
}
824+
#[cfg(not(unix))]
825+
{
826+
had_err = remove_dir_recursive_impl(path, options, progress_bar, None);
827+
}
857828
} else if options.dir && (!is_root || !options.preserve_root) {
858829
had_err = remove_dir(path, options, progress_bar).bitor(had_err);
859830
} else if options.recursive {

0 commit comments

Comments
 (0)