Crates.io | fd-lock |
lib.rs | fd-lock |
version | |
source | src |
created_at | 2019-06-28 00:08:41.253765+00 |
updated_at | 2025-03-10 15:53:43.359688+00 |
description | Advisory cross-platform lock on a file using a file descriptor to it. |
homepage | |
repository | https://github.com/yoshuawuyts/fd-lock |
max_upload_size | |
id | 144180 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Advisory cross-platform file locks using file descriptors. 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.
Basic usage
use std::io::prelude::*;
use std::fs::File;
use fd_lock::RwLock;
// Lock a file and write to it.
let mut f = RwLock::new(File::open("foo.txt")?);
write!(f.write()?, "chashu cat")?;
// A lock can also be held across multiple operations.
let mut f = f.write()?;
write!(f, "nori cat")?;
write!(f, "bird!")?;
$ cargo add fd-lock
This crate uses unsafe
on Windows to interface with windows-sys
. All
invariants have been carefully checked, and are manually enforced.
Want to join us? Check out our "Contributing" guide and take a look at some of these issues:
rustix::fs::flock
windows_sys::Win32::Storage::FileSystem::LockFile
MIT OR Apache-2.0