30 lines
815 B
Rust
30 lines
815 B
Rust
#![allow(
|
|||
|
|
clippy::cast_possible_truncation,
|
||
|
|
clippy::cast_sign_loss,
|
||
|
|
clippy::cast_precision_loss,
|
||
|
|
clippy::cast_possible_wrap
|
||
|
|
)]
|
||
|
|
//! Pure SessionLock entity — no lock / unlock logic.
|
||
|
|
//!
|
||
|
|
//! Lock acquisition and release are handled by the repository.
|
||
|
|
use serde::{Deserialize, Serialize};
|
||
|
|
use std::path::{Path, PathBuf};
|
||
|
|
|
||
|
|
/// A PID-file based session lock handle.
|
||
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
|
|
pub struct SessionLock {
|
||
|
|
pub path: PathBuf,
|
||
|
|
pub pid: u32,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl SessionLock {
|
||
|
|
/// Construct a lock handle for a session directory (does not acquire
|
||
|
|
/// the lock yet — use the repository's `try_lock`).
|
||
|
|
pub fn new(session_dir: &Path) -> Self {
|
||
|
|
SessionLock {
|
||
|
|
path: session_dir.join(".lock"),
|
||
|
|
pid: std::process::id(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|