| Crates.io | file_locking |
| lib.rs | file_locking |
| version | 0.1.0 |
| created_at | 2024-12-15 09:23:44.097751+00 |
| updated_at | 2024-12-15 09:23:44.097751+00 |
| description | A lean file locking implementation for Unix and Windows |
| homepage | |
| repository | https://git.echowritescode.dev/repository/file_locking/head |
| max_upload_size | |
| id | 1484028 |
| size | 21,155 |
This crate provides an extremely lean implementation of file locking for
#[cfg(unix)] (using the libc crate)
and #[cfg(windows)] (using the
windows-sys crate) systems.
The API is exposed as a single extension trait for std::fs::File called
FileExt. Simply bring the trait into scope, and you can lock files to
your heart's content:
use std::fs::{ File };
use file_locking::{ FileExt };
let f = File::options()
.create(true)
.write(true)
.open("database.lock")?;
{
let _guard = f.lock_exclusive()?;
// ... do some stuff with the knowledge that nobody else can lock the file ...
}
// the lock is now released and can be taken again by somebody else c:
Some unavoidable behavior differences exist between platforms. To summarize:
File
object more than once.This project is made available under the terms of the MIT license. See LICENSE.md for details.
Bug reports, feature requests, and patch submissions are welcome at contact@echowritescode.dev.