aboutsummaryrefslogtreecommitdiff
path: root/crates/fslock-guard/README.md
blob: 75d398a6a058bc2443fd7aef26514af1049a4821 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# `fslock-guard` — A guard object to ensure we have an exclusive lock to a file

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

We add two features that `File::lock` does not 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.

[`File::lock`]: std::fs::File::lock
[`fslock`]: https://docs.rs/fslock/latest/fslock/index.html
[`flock`(2)]: https://man7.org/linux/man-pages/man2/flock.2.html
[`LockFileEx`]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-lockfileex