pub struct AtomicWriter { /* private fields */ }Expand description
Atomic-write fixture: open a temp file, hand the caller a writer, then either
fsync + rename it onto dest or unlink it on error.
The pattern in commit:
- Caller writes payload via
Self::write_all. - Caller invokes
Self::commit. - We
flush+sync_all+close, thenrename(2)onto the destination. - On error in step 3, the
UnlinkOnDropguard removes the temp file.
The cross-FS pre-flight check runs in Self::open; subsequent commit cannot
fail with EXDEV because we’ve already validated.
Implementations§
Source§impl AtomicWriter
impl AtomicWriter
Sourcepub fn open(dest: &Path) -> Result<Self, SnapshotError>
pub fn open(dest: &Path) -> Result<Self, SnapshotError>
Open the temp file for writing.
Pre-flight: validate that the temp dir and destination dir live on the same filesystem (cross-FS rename cannot be atomic).
§Errors
SnapshotError::AtomicCommitCrossFs for the cross-FS case;
SnapshotError::Io for an open / mkdir / stat failure.
Sourcepub fn file_mut(&mut self) -> &mut File
pub fn file_mut(&mut self) -> &mut File
Borrow the underlying file for direct writes (used by the streaming envelope
- memory file paths).
Sourcepub fn commit(self) -> Result<(), SnapshotError>
pub fn commit(self) -> Result<(), SnapshotError>
fsync the temp file, drop the writer, and rename(2) it onto the destination.
§Errors
SnapshotError::AtomicCommitFailed for the rename failure (temp file is
unlinked); SnapshotError::Io for an fsync failure (temp file is also
unlinked).
Trait Implementations§
Source§impl Debug for AtomicWriter
impl Debug for AtomicWriter
Source§impl Write for AtomicWriter
impl Write for AtomicWriter
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)