Expand description
Idempotency + staging-area bookkeeping for file-mutating tools. Two-phase commit transaction manager for file write operations.
TransactionManager implements StagingBackend from brainwires-core.
§Protocol
-
Stage — calls to
TransactionManager::stagewrite content to a temporary directory with a key-addressed filename. The target path is not touched. -
Commit —
TransactionManager::commitatomically renames each staged file to its target path. On cross-filesystem moves a copy+delete fallback is used. Parent directories are created as needed. -
Rollback —
TransactionManager::rollbackdeletes all staged files from the temp dir without touching any target path.
A TransactionManager is single-use per transaction: after commit() or
rollback() the queue is empty and new stages can be accepted.
§Usage
use std::sync::Arc;
use brainwires_tool_runtime::transaction::TransactionManager;
use brainwires_core::{StagedWrite, ToolContext};
let mgr = Arc::new(TransactionManager::new().unwrap());
let ctx = ToolContext::default().with_staging_backend(mgr.clone());
// … execute file tools against `ctx` — writes are staged, not applied …
mgr.commit().unwrap(); // atomically write all staged files
// or mgr.rollback(); // discard everythingStructs§
- Transaction
Manager - Filesystem-backed two-phase commit transaction manager.