diff --git a/src/uu/rm/src/rm.rs b/src/uu/rm/src/rm.rs index f9aba615f51..d9804a3631a 100644 --- a/src/uu/rm/src/rm.rs +++ b/src/uu/rm/src/rm.rs @@ -458,7 +458,9 @@ fn count_files_in_directory(p: &Path) -> u64 { entries .flatten() .map(|entry| match entry.file_type() { - Ok(ft) if ft.is_dir() => count_files_in_directory(&entry.path()), + Ok(ft) if ft.is_dir() && !ft.is_symlink() => { + count_files_in_directory(&entry.path()) + } Ok(_) => 1, Err(_) => 0, }) @@ -592,7 +594,14 @@ fn remove_dir_recursive( // a directory and we don't want to recurse. In particular, this // avoids an infinite recursion in the case of a link to the current // directory, like `ln -s . link`. - if !path.is_dir() || path.is_symlink() { + let metadata = match fs::symlink_metadata(path) { + Ok(metadata) => metadata, + Err(e) => return show_removal_error(e, path), + }; + if is_symlink_dir(&metadata) { + return remove_dir(path, options, progress_bar); + } + if !metadata.is_dir() || metadata.file_type().is_symlink() { return remove_file(path, options, progress_bar); }