alive_lock_file

Crates.ioalive_lock_file
lib.rsalive_lock_file
version0.1.2
sourcesrc
created_at2024-07-22 15:26:36.238551
updated_at2024-07-30 18:57:25.095552
descriptionA simple crate to create lock files without creating dead locks
homepage
repositoryhttps://github.com/wiiznokes/alive_lock_file
max_upload_size
id1311249
size15,142
(wiiznokes)

documentation

README

alive_lock_file

crates.io docs.rs license

A simple crate to create lock files without creating dead locks. For that, it use 2 things:

  • join the provided path to the $XDG_RUNTIME_DIR env variable. This directory get cleanned automatically by the system, and is mount as a ramfs.
  • intercept signals

Usage

use alive_lock_file::{init_signals, LockFileState};

fn main() {
    // intercept the `SIGINT` and `SIGTERM` signals.
    init_signals();

    match LockFileState::try_lock("file.lock").unwrap() {
        LockFileState::Lock(_lock) => {
            // while _lock is in scope, `file.lock` will not be removed
        }
        LockFileState::AlreadyLocked => {}
    };
}
Commit count: 0

cargo fmt