#file #fd #lock #windows #unix

fd-lock

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

6 stable releases

3.0.1 Nov 24, 2021
3.0.0 Jul 17, 2021
2.0.0 Dec 21, 2020
1.1.1 Jan 9, 2020
1.1.0 Jun 28, 2019

#33 in Filesystem

Download history 12420/week @ 2021-08-15 13552/week @ 2021-08-22 12255/week @ 2021-08-29 12321/week @ 2021-09-05 14603/week @ 2021-09-12 13663/week @ 2021-09-19 13582/week @ 2021-09-26 16116/week @ 2021-10-03 15711/week @ 2021-10-10 15783/week @ 2021-10-17 18072/week @ 2021-10-24 16385/week @ 2021-10-31 15206/week @ 2021-11-07 16334/week @ 2021-11-14 15378/week @ 2021-11-21 14590/week @ 2021-11-28

63,454 downloads per month
Used in 96 crates (8 directly)

MIT/Apache

24KB
502 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 to interface with libc and winapi. 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–6.5MB
~119K SLoC

a