Expand description

git-style registered tempfiles that are removed upon typical termination signals.

This crate installs signal handlers the first time its facilities are used. These are powered by [signal-hook] to get notified when the application is told to shut down using signals to assure these 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.

As typical handlers for TERMination are installed on first use and effectively overriding the defaults, we install default handlers to restore this behaviour. Whether or not to do that can be controlled using force_setup().

Note

Applications setting their own signal handlers on termination to abort the process probably want to be called after the ones of this crate can call force_setup() before installing their own handlers. By default, our signal handlers will emulate the default behaviour and abort the process after cleaning temporary files. For full control the application can also prevent our handler to be installed and call it themselves from their own signal handlers.

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.

Modules

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.

Define how our signal handlers act

Functions

Explicitly (instead of lazily) initialize signal handlers and other state to keep track of tempfiles. Only has an effect the first time it is called and furthermore allows to set the mode in which signal handlers are installed.

A shortcut to Handle::<Closed>::at() providing a closed temporary file to mark the presence of something.

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.