Crate gix_tempfile
source ·Expand description
git-style registered tempfiles that are removed upon typical termination signals.
To register signal handlers in a typical application that doesn’t have its own, call
gix_tempfile::signal::setup(Default::default())
before creating the first tempfile.
Signal handlers are powered by signal-hook
to get notified when the application is told to shut down
to assure tempfiles are deleted. The deletion is filtered by process id to allow forks to have their own
set of tempfiles that won’t get deleted when the parent process exits.
§Initial Setup
As no handlers for TERMination
are installed, it is required to call signal::setup()
before creating
the first tempfile. This also allows to control how this crate integrates with
other handlers under application control.
As a general rule of thumb, use Default::default()
as argument to emulate the default behaviour and
abort the process after cleaning temporary files. Read more about options in signal::handler::Mode
.
§Limitations
§Tempfiles might remain on disk
- Uninterruptible signals are received like
SIGKILL
- The application is performing a write operation on the tempfile when a signal arrives, preventing this tempfile to be removed, but not others. Any other operation dealing with the tempfile suffers from the same issue.
§Feature Flags
signals
— Support for signal handlers to cleanup tempfiles when a signal is received.hp-hashmap
(enabled by default) — Use a high-performance concurrent hashmap implementation for optimal performance with less contention if there are many tempfiles opening at the same time. It also allows to potentially cleanup more tempfiles in a signal handler as the hashmap can be partially locked.
Modules§
- signal
signals
signal setup and reusable handlers.
Structs§
- A registered temporary file which will delete itself on drop or if the program is receiving signals that should cause it to terminate.
Enums§
- A type expressing the ways we cleanup after ourselves to remove resources we created. Note that cleanup has no effect if the tempfile is persisted.
- A type expressing the ways we can deal with directories containing a tempfile.
Functions§
- A shortcut to
Handle::<Closed>::at()
providing a closed temporary file to mark the presence of something. - Like
mark_at
, but allows to set the given filesystempermissions
. - A shortcut to
Handle::<Writable>::new()
, creating a writable temporary file with non-clashing name in a directory. - A shortcut to
Handle::<Writable>::at()
providing a writable temporary file at the given path. - Like
writable_at
, but allows to set the given filesystempermissions
.