Expand description

File locking via POSIX advisory record locks.

This crate provides the facility to obtain a write-lock and unlock a file following the advisory record lock scheme as specified by UNIX IEEE Std 1003.1-2001 (POSIX.1) via fcntl().


Please note that the examples use tempfile merely to quickly create a file which is removed automatically. In the common case, you would want to lock a file which is known to multiple processes.

use file_locker::FileLock;
use std::io::prelude::*;
use std::io::Result;

fn main() -> Result<()> {
    let mut filelock = FileLock::new("myfile.txt")

    filelock.file.write_all(b"Hello, World!")?;

    // Manually unlocking is optional as we unlock on Drop


Represents the actually locked file

Builder to create FileLock