Expand description
Safe file operation management with atomic rollback capabilities.
This module provides the FileManager
for performing batch file operations
with full rollback support. It’s designed to ensure that complex file
operations either complete entirely or leave the filesystem unchanged.
§Key Features
- Atomic Operations: All-or-nothing batch file operations
- Automatic Backup: Removed files are backed up for restoration
- Operation Tracking: Complete history of all performed operations
- Safe Rollback: Guaranteed restoration to original state on failure
- Error Recovery: Robust handling of filesystem errors during rollback
§Use Cases
§Batch Subtitle Processing
When processing multiple subtitle files, ensure that either all files are successfully processed or none are modified:
let mut manager = FileManager::new();
// Process multiple files
// ... processing logic ...
// If something goes wrong, rollback
manager.rollback()?;
§Safe File Replacement
Replace files with new versions while maintaining rollback capability:
let mut manager = FileManager::new();
// Remove old file (automatically backed up)
manager.remove_file(Path::new("old_file.srt"))?;
// Create new file (tracked for rollback)
manager.record_creation(Path::new("new_file.srt"));
// If something goes wrong later...
manager.rollback()?; // old_file.srt is restored, new_file.srt is removed
§Safety Guarantees
The FileManager
provides strong safety guarantees:
- No Data Loss: Removed files are always backed up before deletion
- Consistent State: Rollback always returns to the exact original state
- Error Isolation: Filesystem errors during rollback don’t corrupt state
- Resource Cleanup: Temporary files and backups are properly managed
Structs§
- File
Manager - Safe file operation manager with rollback capabilities.