#git #version-control #cli #call #terminate #temporary-files


A tempfile implementation with a global registry to assure cleanup

15 stable releases (7 major)

new 10.0.0 Sep 24, 2023
9.0.0 Sep 8, 2023
8.0.0 Aug 22, 2023
7.0.2 Jul 22, 2023
3.0.2 Feb 17, 2023

#1614 in Filesystem

Download history 45661/week @ 2023-06-06 50569/week @ 2023-06-13 53350/week @ 2023-06-20 59532/week @ 2023-06-27 62573/week @ 2023-07-04 65387/week @ 2023-07-11 72185/week @ 2023-07-18 76915/week @ 2023-07-25 88054/week @ 2023-08-01 81450/week @ 2023-08-08 86658/week @ 2023-08-15 95115/week @ 2023-08-22 107499/week @ 2023-08-29 122096/week @ 2023-09-05 125322/week @ 2023-09-12 108879/week @ 2023-09-19

479,602 downloads per month
Used in 120 crates (6 directly)



Use tempfiles to minimize the risk of resource leakage when preparing to overwrite or create a file with new content in a signal-safe way, making the change atomic.

Tempfiles can also be used as locks as only one tempfile can exist at a given path at a time.

  • registered temporary files which are deleted automatically as the process terminates or on drop
    • write to temporary file and persist it under new name
    • close temporary files to convert them into a marker while saving system resources
    • mark paths with a closed temporary file
  • persist temporary files to prevent them from perishing.
  • signal-handler integration with gix to clean lockfiles before the process is aborted.
  • use a temporary file transparently due thanks to implementations of std::io traits


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())][signal::setup()] 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.


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


~135K SLoC