Skip to content

Commit

Permalink
Don't compute trash dirs twice when emptying
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Jan 24, 2025
1 parent 87cd037 commit 03665e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, io::stdin, path::PathBuf};
use std::{collections::BTreeSet, fs, io::stdin, path::PathBuf};

use anyhow::{Context, Result};
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -289,14 +289,18 @@ pub fn restore_with_ui(exclude_dirs: &[PathBuf]) -> Result<()> {
}

pub fn empty(exclude_dirs: &[PathBuf]) -> Result<()> {
let trash_dirs = list_trash_dirs(exclude_dirs)?;
let items = list_all_trash_items(exclude_dirs)?;

if items.is_empty() {
info!("Trash is empty");
return Ok(());
}

let trash_dirs = items
.iter()
.map(|item| &item.trash_dir)
.collect::<BTreeSet<_>>();

warn!("You are about to delete the entire trash directories of:\n");

for trash_dir in &trash_dirs {
Expand All @@ -305,7 +309,7 @@ pub fn empty(exclude_dirs: &[PathBuf]) -> Result<()> {
trash_dir.display(),
items
.iter()
.filter(|item| &item.trash_dir == trash_dir)
.filter(|item| &&item.trash_dir == trash_dir)
.count()
);
}
Expand All @@ -330,7 +334,7 @@ pub fn empty(exclude_dirs: &[PathBuf]) -> Result<()> {

warn!("> Listing files and directories to delete...");

let items = list_deletable_fs_items(&trash_dir)?;
let items = list_deletable_fs_items(trash_dir)?;

warn!("> Deleting all {} items...", items.len());

Expand Down

0 comments on commit 03665e3

Please sign in to comment.