pub struct AtomicOutput { /* private fields */ }Expand description
Write beside a destination and rename into place only after success.
The content is written into a protected (0600, unpredictable name) temp
file in the destination’s directory — the same filesystem, so the final
rename is atomic. The destination is never opened for truncation: it keeps
its original bytes until commit renames the finished temp
over it. On Unix the published file follows normal output-file permissions
(an existing destination’s mode is preserved; a new destination follows the
umask-adjusted default), while the temp stayed owner-only throughout. If the
output is dropped without committing, the temp file is removed and the
destination is left untouched.
Implementations§
Source§impl AtomicOutput
impl AtomicOutput
Sourcepub fn create(destination: impl AsRef<Path>) -> Result<Self>
pub fn create(destination: impl AsRef<Path>) -> Result<Self>
Stage a protected temp output beside destination.
Sourcepub fn destination(&self) -> &Path
pub fn destination(&self) -> &Path
The final destination path.
Sourcepub fn commit(self) -> Result<()>
pub fn commit(self) -> Result<()>
Flush and fsync the temp file, apply the published mode, then atomically
rename it over the destination and fsync the destination’s directory so
the rename itself is durable. Only after this returns Ok does the
destination change.
Atomicity note: rename(2) is atomic on Unix (same filesystem, which is
guaranteed since the temp is a sibling of the destination). On Windows
fs::rename over an existing file is not atomic; this module is
Unix-first.
Trait Implementations§
Source§impl Drop for AtomicOutput
impl Drop for AtomicOutput
Auto Trait Implementations§
impl Freeze for AtomicOutput
impl RefUnwindSafe for AtomicOutput
impl Send for AtomicOutput
impl Sync for AtomicOutput
impl Unpin for AtomicOutput
impl UnsafeUnpin for AtomicOutput
impl UnwindSafe for AtomicOutput
Blanket Implementations§
impl<T> Allocation for T
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
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