Expand description
File-based locking using flock(2)
.
You must start with an UnlockedFile
.
let lock_dir = tempfile::tempdir()?;
let mut lock = UnlockedFile::try_from(lock_dir.path().join("foo").as_path())?;
let lock = lock.lock_shared()?;
let lock = lock.lock_exclusive()?;
let lock = lock.unlock()?;
Dropping a LockedFileShared
or LockedFileExclusive
will ordinarily
drop the underlying flock
-based lock by virtue of dropping the File
they each wrap. However, if the file descriptor was duplicated prior to
creating the initial UnlockedFile
, the lock will persist as long as that
descriptor remains valid.