#methods #convenience #locking #command

fcntl

Wrapper around fcntl (2) and convenience methods to make interacting with it easier

1 unstable release

0.1.0 Jul 24, 2020

#1274 in Filesystem

Download history 16/week @ 2024-01-04 14/week @ 2024-01-11 80/week @ 2024-01-18 25/week @ 2024-01-25 38/week @ 2024-02-01 45/week @ 2024-02-08 51/week @ 2024-02-15 76/week @ 2024-02-22 51/week @ 2024-02-29 59/week @ 2024-03-07 67/week @ 2024-03-14 12/week @ 2024-03-21 46/week @ 2024-03-28 52/week @ 2024-04-04 67/week @ 2024-04-11 63/week @ 2024-04-18

229 downloads per month

MIT/Apache

17KB
205 lines

fcntl-rs

Wrapper around fcntl (2) and convenience methods to make interacting with it easier. Currently only supports commands related to Advisory record locking.

Usage

Cargo.toml

[dependencies]
fcntl = "0.1"
use std::fs::OpenOptions;
use fcntl::{is_file_locked, lock_file, unlock_file};

// Open file
let file = OpenOptions::new().read(true).open("my.lock").unwrap();

// Check whether any process is currently holding a lock
match is_file_locked(&file, None) {
    Ok(true) => println!("File is currently locked"),
    Ok(false) => println!("File is not locked"),
    Err(err) => println!("Error: {:?}", err),
}


// Attempt to acquire a lock
match lock_file(&file, None, Some(FcntlLockType::Write)) {
    Ok(true) => println!("Lock acquired!"),
    Ok(false) => println!("Could not acquire lock!"),
    Err(err) => println!("Error: {:?}", err),
}


// Release lock again
match unlock_file(&file, None) {
    Ok(true) => println!("Lock successfully release"),
    Ok(false) => println!("Failed to release lock"),
    Err(err) => println!("Error: {:?}", err),
}

License

MIT OR Apache-2.0

Dependencies

~42KB