Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/uu/rm/src/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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);
}

Expand Down
Loading