[][src]Crate file_locker

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().

Examples

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")
                        .blocking(true)
                        .writeable(true)
                        .lock()?;

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

    // Manually unlocking is optional as we unlock on Drop
    filelock.unlock()?;
    Ok(())
}

Structs

FileLock

Represents the actually locked file

FileLockBuilder

Builder to create FileLock