pub struct WriteLedger { /* private fields */ }Expand description
A turn-scoped copy-on-first-write ledger: the record that lets retry revert a
fabricated file to the state it had before the turn began.
The first time a path is written during a turn, its prior bytes are captured
(Some = the file existed; None = it did not). Later writes to the same path
in the same turn do not overwrite that entry — the pre-turn state is the
revert target, never an intermediate write. The rig instrument reverted with a
bare rm (sound only because its corpus files never pre-existed); in the real
loop a flagged file may be an edit of a tracked file, so the ledger restores
bytes rather than deleting. Git-independent by design — newt gates non-git
trees too (docs/design/retry-technique.md).
Implementations§
Source§impl WriteLedger
impl WriteLedger
Sourcepub fn note_before_write(&mut self, path: impl Into<PathBuf>)
pub fn note_before_write(&mut self, path: impl Into<PathBuf>)
Record path’s pre-turn state the first time it is written this turn.
Call this before the write lands. A no-op on any subsequent write to the
same path — the pre-turn snapshot is preserved.
Only a genuine NotFound records the “did-not-exist” marker (None) that
makes revert delete the path. Any other read error (EACCES, a
transient NFS hiccup, the path being a directory) leaves the path
untracked — conflating “unreadable” with “absent” would let revert delete
a pre-existing file whose note-time read merely failed. Untracked ⇒ revert
returns false and refuses to touch it.
Sourcepub fn revert(&self, path: &Path) -> Result<bool>
pub fn revert(&self, path: &Path) -> Result<bool>
Restore path to its recorded pre-turn state: write the captured bytes
back, or remove the file if it did not exist pre-turn. Returns true iff
the path had a ledger entry (so the caller can warn on a gate-flagged path
the ledger never saw — a bug, not a silent delete of an untracked file).
§Errors
Propagates I/O errors from the restore write or remove (a NotFound on
remove is treated as already-reverted, not an error).
Trait Implementations§
Source§impl Clone for WriteLedger
impl Clone for WriteLedger
Source§fn clone(&self) -> WriteLedger
fn clone(&self) -> WriteLedger
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WriteLedger
impl Debug for WriteLedger
Source§impl Default for WriteLedger
impl Default for WriteLedger
Source§fn default() -> WriteLedger
fn default() -> WriteLedger
Auto Trait Implementations§
impl Freeze for WriteLedger
impl RefUnwindSafe for WriteLedger
impl Send for WriteLedger
impl Sync for WriteLedger
impl Unpin for WriteLedger
impl UnsafeUnpin for WriteLedger
impl UnwindSafe for WriteLedger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more