async-fd-lock
Advisory cross-platform file locks using file descriptors, with async support by off-loading blocking operations to newly spawned blocking tasks. Adapted from yoshuawuyts/fd-lock, which was adapted from mafintosh/fd-lock.
Note that advisory lock compliance is opt-in, and can freely be ignored by other parties. This means this crate should never be used for security purposes, but solely to coordinate file access.
Examples
Basic usage
use PathBuf;
use File;
use ;
use ;
let dir = tempdir.unwrap;
let path = dir.path.join;
// Lock it for writing.
// Lock it for reading.
Installation
Safety
This crate uses unsafe
on Windows to interface with windows-sys
. All
invariants have been carefully checked, and are manually enforced.
References
- LockFile function - WDC
- flock(2) - Linux Man Page
rustix::fs::flock
windows_sys::Win32::Storage::FileSystem::LockFile
License
MIT OR Apache-2.0