#file #fd #lock #windows #unix

fd-lock

Advisory cross-platform lock on a file using a file descriptor to it

11 stable releases

3.0.6 Jun 21, 2022
3.0.5 Mar 23, 2022
3.0.4 Feb 22, 2022
3.0.2 Dec 9, 2021
1.1.0 Jun 28, 2019

#21 in Operating systems

Download history 22870/week @ 2022-03-16 24000/week @ 2022-03-23 24910/week @ 2022-03-30 21896/week @ 2022-04-06 21077/week @ 2022-04-13 22457/week @ 2022-04-20 23127/week @ 2022-04-27 23946/week @ 2022-05-04 25548/week @ 2022-05-11 26382/week @ 2022-05-18 22568/week @ 2022-05-25 25312/week @ 2022-06-01 27975/week @ 2022-06-08 29965/week @ 2022-06-15 34844/week @ 2022-06-22 26776/week @ 2022-06-29

124,195 downloads per month
Used in 169 crates (12 directly)

MIT/Apache

24KB
490 lines

fd-lock

crates.io version downloads docs.rs docs

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.

Examples

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!")?;

Installation

$ cargo add fd-lock

Safety

This crate uses unsafe on Windows to interface with windows-sys. All invariants have been carefully checked, and are manually enforced.

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

References

License

MIT OR Apache-2.0

Dependencies

~0–8.5MB
~153K SLoC