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

fslock-guard

Wrapper around a lockfile with unlock-on-drop semantics

8 releases

0.2.1 Dec 2, 2024
0.2.0 Sep 30, 2024
0.1.5 Sep 3, 2024
0.1.4 Aug 1, 2024
0.1.0 Feb 5, 2024

#227 in Filesystem

Download history 547/week @ 2024-08-23 578/week @ 2024-08-30 656/week @ 2024-09-06 235/week @ 2024-09-13 408/week @ 2024-09-20 1046/week @ 2024-09-27 529/week @ 2024-10-04 182/week @ 2024-10-11 248/week @ 2024-10-18 296/week @ 2024-10-25 1285/week @ 2024-11-01 445/week @ 2024-11-08 879/week @ 2024-11-15 677/week @ 2024-11-22 1372/week @ 2024-11-29 585/week @ 2024-12-06

3,555 downloads per month
Used in 30 crates (via tor-persist)

MIT/Apache

17KB
156 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