use std::path::{Path, PathBuf};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum FileOperationError {
#[error("Failed to move file to trash: {0}")]
TrashError(#[from] trash::Error),
#[error("File not found: {0}")]
FileNotFound(PathBuf),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, FileOperationError>;
pub struct FileOperations;
impl FileOperations {
pub fn delete_file<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();
if !path.exists() {
return Err(FileOperationError::FileNotFound(path.to_path_buf()));
}
trash::delete(path)?;
tracing::info!("Successfully moved file to trash: {}", path.display());
Ok(())
}
pub fn delete_file_permanent<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();
if !path.exists() {
return Err(FileOperationError::FileNotFound(path.to_path_buf()));
}
std::fs::remove_file(path)?;
tracing::warn!("Permanently deleted file: {}", path.display());
Ok(())
}
}