pub struct SafetyManager {
source: PathBuf,
config: SafetyConfig,
index_hash: String,
trash_dir: PathBuf,
history_file: PathBuf,
trash_cache: Arc<RwLock<Vec<TrashEntry>>>,
}Expand description
Safety manager for protecting file operations.
Fields§
§source: PathBufSource root; agent paths must stay inside this tree.
config: SafetyConfigConfiguration
index_hash: StringIndex hash (used for separating trash/history by index)
trash_dir: PathBufTrash directory
history_file: PathBufHistory file
trash_cache: Arc<RwLock<Vec<TrashEntry>>>In-memory cache of trash entries
Implementations§
Source§impl SafetyManager
impl SafetyManager
Sourcepub fn new(source: &PathBuf, config: Option<SafetyConfig>) -> Self
pub fn new(source: &PathBuf, config: Option<SafetyConfig>) -> Self
Create a new safety manager.
Sourcefn jail(&self, path: &Path) -> Result<PathBuf, String>
fn jail(&self, path: &Path) -> Result<PathBuf, String>
Resolve path so it stays inside the source root.
Sourcepub fn index_hash(&self) -> &str
pub fn index_hash(&self) -> &str
Get the index hash.
Sourcefn load_trash_entries(trash_dir: &PathBuf) -> Result<Vec<TrashEntry>>
fn load_trash_entries(trash_dir: &PathBuf) -> Result<Vec<TrashEntry>>
Load trash entries from disk.
Sourceasync fn save_trash_entries(&self) -> Result<()>
async fn save_trash_entries(&self) -> Result<()>
Save trash entries to disk.
Sourcepub async fn soft_delete(&self, path: &PathBuf) -> Result<TrashEntry, String>
pub async fn soft_delete(&self, path: &PathBuf) -> Result<TrashEntry, String>
Move a file to trash (soft delete).
Sourcepub async fn restore(&self, trash_id: Uuid) -> Result<PathBuf, String>
pub async fn restore(&self, trash_id: Uuid) -> Result<PathBuf, String>
Restore a file from trash.
Sourcepub async fn list_trash(&self) -> Vec<TrashEntry>
pub async fn list_trash(&self) -> Vec<TrashEntry>
List all trash entries.
Sourcepub async fn get_trash_entry(&self, id: Uuid) -> Option<TrashEntry>
pub async fn get_trash_entry(&self, id: Uuid) -> Option<TrashEntry>
Get a specific trash entry.
Sourcepub async fn purge_expired(&self) -> usize
pub async fn purge_expired(&self) -> usize
Purge expired trash entries.
Sourcepub fn log(&self, entry: HistoryEntry) -> Result<()>
pub fn log(&self, entry: HistoryEntry) -> Result<()>
Log an operation to history.
Sourcepub fn log_success(
&self,
operation: HistoryOperation,
undo_data: Option<UndoData>,
) -> Uuid
pub fn log_success( &self, operation: HistoryOperation, undo_data: Option<UndoData>, ) -> Uuid
Log a successful operation and return the history entry id.
This id is the undo_id written to .ops/.result.
Sourcepub fn log_failure(&self, operation: HistoryOperation, error: String)
pub fn log_failure(&self, operation: HistoryOperation, error: String)
Log a failed operation.
Sourcepub fn read_history(&self, limit: Option<usize>) -> Vec<HistoryEntry>
pub fn read_history(&self, limit: Option<usize>) -> Vec<HistoryEntry>
Read history entries.
Sourcepub fn get_history_json(&self, limit: Option<usize>) -> Vec<u8> ⓘ
pub fn get_history_json(&self, limit: Option<usize>) -> Vec<u8> ⓘ
Get history as JSON bytes (for FUSE read).
Sourcepub fn find_operation(&self, id: Uuid) -> Option<HistoryEntry>
pub fn find_operation(&self, id: Uuid) -> Option<HistoryEntry>
Find an operation by ID for undo.
Sourcepub fn soft_delete_enabled(&self) -> bool
pub fn soft_delete_enabled(&self) -> bool
Check if soft delete is enabled.