#file-lock #lock #locking #fs #fs-file

fslock-guard

Wrapper around a lockfile with unlock-on-drop semantics

9 releases

0.2.2 Jan 7, 2025
0.2.1 Dec 2, 2024
0.2.0 Sep 30, 2024
0.1.3 Jun 5, 2024
0.1.1 Mar 4, 2024

#274 in Filesystem

Download history 590/week @ 2024-10-28 1018/week @ 2024-11-04 811/week @ 2024-11-11 612/week @ 2024-11-18 1129/week @ 2024-11-25 895/week @ 2024-12-02 466/week @ 2024-12-09 470/week @ 2024-12-16 288/week @ 2024-12-23 190/week @ 2024-12-30 551/week @ 2025-01-06 374/week @ 2025-01-13 380/week @ 2025-01-20 162/week @ 2025-01-27 1111/week @ 2025-02-03 430/week @ 2025-02-10

2,139 downloads per month
Used in 27 crates (2 directly)

MIT/Apache

17KB
158 lines

fslock-guard — A guard object to ensure we have an exclusive lock to a file

This crate is a thin wrapper around fslock, which uses flock(2) or LockFileEx to acquire an advisory lock on the filesystem.

We add two features that fslock does not (currently) have:

  • We have a LockFileGuard type, which can be used to ensure that a lock is actually held until the guard is dropped.
  • We perform a post-lock check to make sure that our lockfile has not been removed and re-created on disk by someone else. This check makes it safe to remove lockfiles.

lib.rs:

Dependencies

~0.3–1MB
~20K SLoC