Merge branch 'master' into patch-1

This commit is contained in:
Levi Portenier 2025-12-19 12:37:25 -07:00 committed by GitHub
commit bc22f1f329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 172 additions and 129 deletions

View file

@ -866,6 +866,8 @@ impl Operation {
let items = trash::os_limited::list()
.map_err(|e| OperationError::from_err(e, &controller))?;
let count = items.len();
let mut errors: Vec<trash::Error> = Vec::new();
for (i, item) in items.into_iter().enumerate() {
futures::executor::block_on(async {
controller
@ -874,11 +876,31 @@ impl Operation {
.map_err(|s| OperationError::from_state(s, &controller))
})?;
controller.set_progress(i as f32 / count as f32);
if let Err(e) = trash::os_limited::purge_all([item]) {
errors.push(e);
}
trash::os_limited::purge_all([item])
.map_err(|e| OperationError::from_err(e, &controller))?;
controller.set_progress(i as f32 / count as f32);
}
// Report errors at the end
if !errors.is_empty() {
log::warn!("Failed to purge {} items:", errors.len());
for e in &errors {
log::warn!(" - {e}");
}
// Return an error to signal partial failure
return Err(OperationError::from_err(
format!(
"Failed to delete {} of {} items. Check log for details.",
errors.len(),
count
),
&controller,
));
}
Ok(())
})
.await

View file

@ -1489,6 +1489,7 @@ impl Location {
}
pub fn with_path(&self, path: PathBuf) -> Self {
let path = Self::expand_tilde(path);
match self {
Self::Desktop(_, display, desktop_config) => {
Self::Desktop(path, display.clone(), *desktop_config)
@ -1562,6 +1563,22 @@ impl Location {
Self::Network(display_name, ..) => display_name.clone(),
}
}
/// Expand a path that starts with "~" with the
/// user's home directory
pub fn expand_tilde(path: PathBuf) -> PathBuf {
let mut components = path.components();
match components.next() {
Some(std::path::Component::Normal(os_str)) if os_str == "~" => {
if let Some(home) = dirs::home_dir() {
home.join(components.as_path())
} else {
path
}
}
_ => path,
}
}
}
pub struct TaskWrapper(pub cosmic::Task<Message>);