#pid #file #locks #file-descriptor #traits #extend #fd-lock

filelock-rs

Minimal Rust library that provides functionality for managing PID files and file locks

2 releases

0.1.0-beta.2 Jun 25, 2023

#10 in #locks

Download history 27/week @ 2023-12-22 5/week @ 2023-12-29 3/week @ 2024-02-16 10/week @ 2024-02-23 28/week @ 2024-03-01 16/week @ 2024-03-08 35/week @ 2024-03-15 9/week @ 2024-03-22 41/week @ 2024-03-29 39/week @ 2024-04-05

126 downloads per month

GPL-2.0 license

13KB
100 lines

filelock-rs

Crates.io Documentation

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

Features

  • Pid: The pid module provides functionality for creating, reading, and managing PID files.
  • FdLock: The fdlock module provides a trait FdLock that extends the AsRawFd trait, allowing file locks to be placed on file descriptors.

Installation

Add this to your Cargo.toml:

[dependencies]
filelock-rs = "0.1.0"

Usage

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");
}

License

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

Dependencies

~42KB