filelock-rs

Crates.io Documentation

filelock-rs is a Rust library that provides functionality for managing PID files and file locks.

Features

Installation

Add this to your Cargo.toml:

toml [dependencies] filelock-rs = "0.1.0"

Usage

``` rust use filelock-rsrs::pid::Pid; use filelock-rsrs::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 pidfile = Pid::new("/var/run", "myapp").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");

} ```

License

Copyright 2023 Vincenzo Palazzo <vincenzopalazzodev@gmail.com>. See LICENSE file.