Add operation to permanently delete trash items, fixes #841

This commit is contained in:
Jeremy Soller 2025-03-03 13:44:06 -07:00
parent 3cce822ffc
commit c8aa80fb2f
No known key found for this signature in database
GPG key ID: 670FDFB5428E05CA
6 changed files with 101 additions and 18 deletions

View file

@ -460,6 +460,10 @@ pub enum Operation {
Delete {
paths: Vec<PathBuf>,
},
/// Delete a path from the trash
DeleteTrash {
items: Vec<trash::TrashItem>,
},
/// Empty the trash
EmptyTrash,
/// Uncompress files
@ -550,6 +554,9 @@ impl Operation {
to = fl!("trash"),
progress = progress()
),
Self::DeleteTrash { items } => {
fl!("deleting", items = items.len(), progress = progress())
}
Self::EmptyTrash => fl!("emptying-trash", progress = progress()),
Self::Extract {
paths,
@ -609,6 +616,7 @@ impl Operation {
from = paths_parent_name(paths),
to = fl!("trash")
),
Self::DeleteTrash { items } => fl!("deleted", items = items.len()),
Self::EmptyTrash => fl!("emptied-trash"),
Self::Extract {
paths,
@ -650,6 +658,7 @@ impl Operation {
Self::Compress { .. }
| Self::Copy { .. }
| Self::Delete { .. }
| Self::DeleteTrash { .. }
| Self::EmptyTrash
| Self::Extract { .. }
| Self::Move { .. }
@ -846,6 +855,34 @@ impl Operation {
}
Ok(OperationSelection::default())
}
Self::DeleteTrash { items } => {
#[cfg(any(
target_os = "windows",
all(
unix,
not(target_os = "macos"),
not(target_os = "ios"),
not(target_os = "android")
)
))]
{
tokio::task::spawn_blocking(move || -> Result<(), OperationError> {
let count = items.len();
for (i, item) in items.into_iter().enumerate() {
controller.check().map_err(OperationError::from_str)?;
controller.set_progress(i as f32 / count as f32);
trash::os_limited::purge_all([item])
.map_err(OperationError::from_str)?;
}
Ok(())
})
.await
.map_err(OperationError::from_str)??;
}
Ok(OperationSelection::default())
}
Self::EmptyTrash => {
#[cfg(any(
target_os = "windows",