pub struct AtomicFile { /* private fields */ }Expand description
One named file capability. It reads, creates, replaces and removes bytes without exposing a path. Replacement atomically installs a complete version.
Implementations§
Source§impl AtomicFile
impl AtomicFile
Sourcepub fn read_optional(&self) -> Result<Option<Vec<u8>>, FileError>
pub fn read_optional(&self) -> Result<Option<Vec<u8>>, FileError>
Read the complete file. Only a missing file is None; other errors
retain their operating-system cause.
Sourcepub fn open_reader(&self) -> Result<FileReader, ObservationError>
pub fn open_reader(&self) -> Result<FileReader, ObservationError>
Open this owned file for checked scans and positioned reads.
Sourcepub fn replace(&self, bytes: &[u8]) -> Result<(), FileError>
pub fn replace(&self, bytes: &[u8]) -> Result<(), FileError>
Write and sync a temporary sibling, replace the target, then sync its directory. The parent must already exist. Concurrent writers each install one complete version; a failed pre-rename write leaves it alone.
Windows uses POSIX replacement on a write-through file handle, which
flushes the rename’s metadata on NTFS. This requires FileRenameInfoEx
and a filesystem supporting POSIX replacement. Windows 10 before 1607
lacks that API; unsupported systems return the OS error without falling
back to a rename that can fail while readers hold old versions open.
Sourcepub fn write_recorded(&self, bytes: &[u8]) -> Result<(), FileError>
pub fn write_recorded(&self, bytes: &[u8]) -> Result<(), FileError>
Write and sync complete bytes at this name, then flush its directory and the drive’s cache, as a batch of this one file, with no temporary sibling. The caller records the name as its own first, so bytes a crash interrupts stay recorded for removal. Anything but a regular file there is refused before a byte is written.
Sourcepub fn overwrite_at(
&self,
offset: u64,
bytes: &[u8],
) -> Result<(), ObservationError>
pub fn overwrite_at( &self, offset: u64, bytes: &[u8], ) -> Result<(), ObservationError>
Write bytes over this existing file’s bytes from offset, which
they must lie within, and hand them to the drive. Readers can see
some of the old bytes and some of the new while it writes, and a
crash can leave them so: only bytes that check themselves, as a
cache’s authenticated chunks do, are written this way.
Sourcepub fn set_len(&self, length: u64) -> Result<(), ObservationError>
pub fn set_len(&self, length: u64) -> Result<(), ObservationError>
Give this existing file length bytes, cutting it short or adding
zeros at its end, and hand the change to the drive.
Sourcepub fn remove(&self) -> Result<(), FileError>
pub fn remove(&self) -> Result<(), FileError>
Remove the owned file; an absent file is success. On Unix, sync the directory even on a retry after an earlier directory-sync failure. A missing parent is already absent and needs no durability barrier.
Sourcepub fn remove_with_temporaries(&self) -> Result<(), FileError>
pub fn remove_with_temporaries(&self) -> Result<(), FileError>
Remove the owned file and every temporary sibling a write of it left, as a crash or a failed removal does: each holds a whole version of its bytes. The caller holds what guards this file’s writes, so none of them is a write in flight.
Sourcepub fn leave_temporary(&self, bytes: &[u8]) -> PathBuf
pub fn leave_temporary(&self, bytes: &[u8]) -> PathBuf
Leave a temporary sibling holding bytes, as a crash between writing
it and renaming it does, and say where.
Trait Implementations§
Source§impl Clone for AtomicFile
impl Clone for AtomicFile
Source§fn clone(&self) -> AtomicFile
fn clone(&self) -> AtomicFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more