use super::*;
pub fn delete_target_for(node: Option<&Node>, root: &Path) -> Option<PathBuf> {
let n = node?;
if n.depth == 0 || n.path == root {
return None;
}
let canon_root = root.canonicalize().ok();
let canon_target = n.path.canonicalize().ok();
if canon_root.is_some() && canon_target == canon_root {
return None;
}
Some(n.path.clone())
}
pub fn move_to_trash(path: &Path) -> std::io::Result<()> {
#[cfg(not(target_os = "android"))]
{
trash::delete(path).map_err(|e| std::io::Error::other(format!("{e}")))
}
#[cfg(target_os = "android")]
{
android_trash::trash_one(path)
}
}
pub fn move_to_trash_bulk(paths: &[PathBuf]) -> std::io::Result<()> {
if paths.is_empty() {
return Ok(());
}
#[cfg(target_os = "macos")]
{
use trash::macos::{DeleteMethod, TrashContextExtMacos};
let mut ctx = trash::TrashContext::default();
ctx.set_delete_method(DeleteMethod::Finder);
ctx.delete_all(paths)
.map_err(|e| std::io::Error::other(format!("{e}")))
}
#[cfg(not(any(target_os = "macos", target_os = "android")))]
{
trash::delete_all(paths).map_err(|e| std::io::Error::other(format!("{e}")))
}
#[cfg(target_os = "android")]
{
for p in paths {
android_trash::trash_one(p)?;
}
Ok(())
}
}