Struct git_tempfile::Registration [−][src]
pub struct Registration<Marker> { /* fields omitted */ }
Expand description
A registered temporary file which will delete itself on drop or if the program is receiving signals that should cause it to terminate.
Note
Signals interrupting the calling thread right after taking ownership of the registered tempfile will cause all but this tempfile to be removed automatically. In the common case it will persist on disk as destructors were not called or didn’t get to remove the file.
In the best case the file is a true temporary with a non-clashing name that ‘only’ fills up the disk, in the worst case the temporary file is used as a lock file which may leave the repository in a locked state forever.
This kind of raciness exists whenever take()
is used and can’t be circumvented.
Implementations
Creation and ownership transfer
pub fn at(
path: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
pub fn at(
path: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
Create a registered tempfile at the given path
, where path
includes the desired filename and close it immediately.
Depending on the directory
configuration, intermediate directories will be created, and depending on cleanup
empty
intermediate directories will be removed.
Creation and ownership transfer
pub fn at(
path: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
pub fn at(
path: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
Create a registered tempfile at the given path
, where path
includes the desired filename.
Depending on the directory
configuration, intermediate directories will be created, and depending on cleanup
empty
intermediate directories will be removed.
pub fn new(
containing_directory: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
pub fn new(
containing_directory: impl AsRef<Path>,
directory: ContainingDirectory,
cleanup: AutoRemove
) -> Result<Self>
Create a registered tempfile within containing_directory
with a name that won’t clash, and clean it up as specified with cleanup
.
Control how to deal with intermediate directories with directory
.
The temporary file is opened and can be written to using the map()
method.
Take ownership of the temporary file.
It’s a theoretical possibility that the file isn’t present anymore if signals interfere, hence the Option
Mutation
Obtain a mutable handler to the underlying named tempfile and call f(&mut named_tempfile)
on it.
Note that for the duration of the call, a signal interrupting the operation will cause the tempfile not to be cleaned up.
Also note that it might theoretically be possible that due to signal interference the underlying tempfile isn’t present
anymore which may cause the function f
not to be called and an io error kind Interrupted
is returned, consuming the
handle in the process.
Trait Implementations
Auto Trait Implementations
impl<Marker> RefUnwindSafe for Registration<Marker> where
Marker: RefUnwindSafe,
impl<Marker> Send for Registration<Marker> where
Marker: Send,
impl<Marker> Sync for Registration<Marker> where
Marker: Sync,
impl<Marker> Unpin for Registration<Marker> where
Marker: Unpin,
impl<Marker> UnwindSafe for Registration<Marker> where
Marker: UnwindSafe,