Crates.io | filelock-rs |
lib.rs | filelock-rs |
version | 0.1.0-beta.2 |
source | src |
created_at | 2023-06-25 14:42:09.338976 |
updated_at | 2023-06-25 16:43:39.064097 |
description | Minimal Rust library that provides functionality for managing PID files and file locks. |
homepage | https://github.com/rsmicro/fd-lock |
repository | https://github.com/rsmicro/fd-lock.git |
max_upload_size | |
id | 899538 |
size | 32,242 |
filelock-rs is a Rust library that provides functionality for managing PID files and file locks.
pid
module provides functionality for creating, reading, and managing PID files.fdlock
module provides a trait FdLock
that extends the AsRawFd
trait, allowing file locks to be placed on file descriptors.Add this to your Cargo.toml
:
[dependencies]
filelock-rs = "0.1.0"
use filelock-rs_rs::pid::Pid;
use filelock-rs_rs::fdlock::FdLock;
fn main() {
// Store the file in the struct of the process
// because the pid stop to exist when this Pid instance
// is dropped.
let pid_file = Pid::new("/var/run", "my_app").expect("Failed to create PID file");
let file = std::fs::File::new("/tmp/file.txt").unwrap();
// Lock the file exclusively
file.lock_exclusive().expect("Failed to lock PID file");
// Perform some operations...
// Unlock the file
file.unlock().expect("Failed to unlock PID file");
}
Copyright 2023 Vincenzo Palazzo <vincenzopalazzodev@gmail.com>. See LICENSE file.