Crates.io | alive_lock_file |
lib.rs | alive_lock_file |
version | 0.1.2 |
source | src |
created_at | 2024-07-22 15:26:36.238551 |
updated_at | 2024-07-30 18:57:25.095552 |
description | A simple crate to create lock files without creating dead locks |
homepage | |
repository | https://github.com/wiiznokes/alive_lock_file |
max_upload_size | |
id | 1311249 |
size | 15,142 |
A simple crate to create lock files without creating dead locks. For that, it use 2 things:
$XDG_RUNTIME_DIR
env variable. This directory get cleanned automatically by the system, and is mount as a ramfs.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 => {}
};
}