#temporary-files #process #gix #persist #git #mark #marker

deprecated git-tempfile

Please use gix-<thiscrate> instead (‘git’ -> ‘gix’)

25 releases (stable)

3.0.3 Feb 17, 2023
3.0.1 Jan 10, 2023
3.0.0 Nov 21, 2022
2.0.6 Nov 6, 2022
0.4.0 Jun 23, 2021

#9 in #gix

Download history 556/week @ 2024-07-21 574/week @ 2024-07-28 394/week @ 2024-08-04 383/week @ 2024-08-11 280/week @ 2024-08-18 338/week @ 2024-08-25 328/week @ 2024-09-01 334/week @ 2024-09-08 442/week @ 2024-09-15 570/week @ 2024-09-22 336/week @ 2024-09-29 396/week @ 2024-10-06 324/week @ 2024-10-13 118/week @ 2024-10-20 203/week @ 2024-10-27 163/week @ 2024-11-03

834 downloads per month
Used in 16 crates (4 directly)

MIT/Apache

42KB
761 lines

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 [git_tempfile::setup(Default::default())][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 [setup()] before creating the first tempfile. This also allows to control how git-tempfiles 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 [SignalHandlerMode].

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.

Dependencies

~3–11MB
~136K SLoC