ferrite_image/
operations.rs1use std::path::{Path, PathBuf};
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum FileOperationError {
6 #[error("Failed to move file to trash: {0}")]
7 TrashError(#[from] trash::Error),
8 #[error("File not found: {0}")]
9 FileNotFound(PathBuf),
10 #[error("IO error: {0}")]
11 IoError(#[from] std::io::Error),
12}
13
14pub type Result<T> = std::result::Result<T, FileOperationError>;
15
16pub struct FileOperations;
18
19impl FileOperations {
20 pub fn delete_file<P: AsRef<Path>>(path: P) -> Result<()> {
29 let path = path.as_ref();
30
31 if !path.exists() {
32 return Err(FileOperationError::FileNotFound(path.to_path_buf()));
33 }
34
35 trash::delete(path)?;
36 tracing::info!("Successfully moved file to trash: {}", path.display());
37 Ok(())
38 }
39
40 pub fn delete_file_permanent<P: AsRef<Path>>(path: P) -> Result<()> {
52 let path = path.as_ref();
53
54 if !path.exists() {
55 return Err(FileOperationError::FileNotFound(path.to_path_buf()));
56 }
57
58 std::fs::remove_file(path)?;
59 tracing::warn!("Permanently deleted file: {}", path.display());
60 Ok(())
61 }
62}