#methods #convenience #locking #command

fcntl

fcntl (2) 的包装器,并提供方便的方法使其交互更容易

1 个不稳定版本

0.1.0 2020年7月24日

#1233文件系统

Download history 58/week @ 2024-03-13 32/week @ 2024-03-20 31/week @ 2024-03-27 59/week @ 2024-04-03 63/week @ 2024-04-10 72/week @ 2024-04-17 40/week @ 2024-04-24 23/week @ 2024-05-01 16/week @ 2024-05-08 16/week @ 2024-05-15 22/week @ 2024-05-22 25/week @ 2024-05-29 39/week @ 2024-06-05 39/week @ 2024-06-12 47/week @ 2024-06-19 29/week @ 2024-06-26

160 每月下载量

MIT/Apache

17KB
205

fcntl-rs

fcntl (2) 的包装器,并提供方便的方法使其交互更容易。目前仅支持与咨询记录锁定相关的命令。

用法

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),
}

许可证

MIT OR Apache-2.0

依赖

~43KB