pub struct AtomicFile { /* private fields */ }Expand description
Create a file and write to it atomically, in a callback.
Implementations§
Source§impl AtomicFile
impl AtomicFile
Sourcepub fn new<P>(path: P, overwrite: OverwriteBehavior) -> Self
pub fn new<P>(path: P, overwrite: OverwriteBehavior) -> Self
Helper for writing to the file at path atomically, in write-only mode.
If OverwriteBehaviour::DisallowOverwrite is given,
an Error::Internal containing an std::io::ErrorKind::AlreadyExists
will be returned from self.write(...) if the file exists.
The temporary file is written to a temporary subdirectory in ., to ensure
it’s on the same filesystem (so that the move is atomic).
Sourcepub fn new_with_tmpdir<P, Q>(
path: P,
overwrite: OverwriteBehavior,
tmpdir: Q,
) -> Self
pub fn new_with_tmpdir<P, Q>( path: P, overwrite: OverwriteBehavior, tmpdir: Q, ) -> Self
Like AtomicFile::new, but the temporary file is written to a temporary subdirectory in tmpdir.
TODO: does tmpdir have to exist?
Sourcepub fn write<T, E, F>(&self, f: F) -> Result<T, Error<E>>
pub fn write<T, E, F>(&self, f: F) -> Result<T, Error<E>>
Open a temporary file, call f on it (which is supposed to write to it), then move the
file atomically to self.path.
The temporary file is written to a randomized temporary subdirectory with prefix .atomicwrite.
Sourcepub fn write_with_options<T, E, F>(
&self,
f: F,
options: OpenOptions,
) -> Result<T, Error<E>>
pub fn write_with_options<T, E, F>( &self, f: F, options: OpenOptions, ) -> Result<T, Error<E>>
Open a temporary file with custom OpenOptions, call f on it (which is supposed to
write to it), then move the file atomically to self.path.
The temporary file is written to a randomized temporary subdirectory with prefix
.atomicwrite.