22 stable releases (10 major)

13.1.1 Mar 14, 2024
13.0.0 Jan 20, 2024
12.0.1 Dec 30, 2023
11.0.1 Dec 6, 2023
3.0.2 Feb 17, 2023

#77 in Filesystem

Download history 89488/week @ 2023-12-23 101301/week @ 2023-12-30 111965/week @ 2024-01-06 114370/week @ 2024-01-13 124495/week @ 2024-01-20 130920/week @ 2024-01-27 139045/week @ 2024-02-03 133564/week @ 2024-02-10 132595/week @ 2024-02-17 137134/week @ 2024-02-24 142774/week @ 2024-03-02 144868/week @ 2024-03-09 156822/week @ 2024-03-16 157009/week @ 2024-03-23 152899/week @ 2024-03-30 121597/week @ 2024-04-06

612,771 downloads per month
Used in 201 crates (7 directly)

MIT/Apache

73KB
1.5K SLoC

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

lib.rs:

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.

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

Dependencies

~3–14MB
~192K SLoC