1use anyhow::{Context, Result};
2use std::path::Path;
3
4pub fn move_to_trash(paths: &[&Path]) -> Result<usize> {
5 let mut moved = 0;
6 for p in paths {
7 trash::delete(p).with_context(|| format!("failed to trash {}", p.display()))?;
8 moved += 1;
9 }
10 Ok(moved)
11}
12
13pub fn restore_from_trash(name_contains: &str) -> Result<usize> {
14 let items = trash::os_limited::list()?;
15 let matches: Vec<_> = items.into_iter()
16 .filter(|i| i.name.to_string_lossy().contains(name_contains))
17 .collect();
18 if matches.is_empty() {
19 return Ok(0);
20 }
21 trash::os_limited::restore_all(matches.clone())?;
22 Ok(matches.len())
23}