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

fslock-guard

Wrapper around a lockfile with unlock-on-drop semantics

3 releases

0.1.2 Apr 2, 2024
0.1.1 Mar 4, 2024
0.1.0 Feb 5, 2024

#407 in Filesystem

Download history 15/week @ 2024-02-05 23/week @ 2024-02-19 19/week @ 2024-02-26 293/week @ 2024-03-04 80/week @ 2024-03-11 203/week @ 2024-03-18 161/week @ 2024-03-25 381/week @ 2024-04-01 169/week @ 2024-04-08 26/week @ 2024-04-15

753 downloads per month
Used in 15 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.4–1MB
~21K SLoC