pub struct LockFile { /* private fields */ }Expand description
Lock file handle that automatically releases on Drop
Implementations§
Source§impl LockFile
impl LockFile
Sourcepub fn acquire(state_dir: &Path, workspace_root: Option<&Path>) -> Result<Self>
pub fn acquire(state_dir: &Path, workspace_root: Option<&Path>) -> Result<Self>
Acquire a lock file in the specified state directory
This will fail if a lock already exists and is not stale.
Use is_locked first to check, or use acquire_with_timeout for
automatic stale lock handling.
§Example
use shipper_core::lock::LockFile;
use std::path::Path;
let lock = LockFile::acquire(Path::new(".mylock"), None)?;Sourcepub fn acquire_with_timeout(
state_dir: &Path,
workspace_root: Option<&Path>,
timeout: Duration,
) -> Result<Self>
pub fn acquire_with_timeout( state_dir: &Path, workspace_root: Option<&Path>, timeout: Duration, ) -> Result<Self>
Acquire a lock, automatically removing stale locks older than timeout
§Arguments
state_dir- Directory to store the lock fileworkspace_root- Optional workspace root to hash for avoiding global lock collisionstimeout- Age threshold for considering a lock stale
§Example
use shipper_core::lock::LockFile;
use std::path::Path;
use std::time::Duration;
let lock = LockFile::acquire_with_timeout(
Path::new(".mylock"),
None,
Duration::from_secs(3600)
)?;Sourcepub fn release(&self) -> Result<()>
pub fn release(&self) -> Result<()>
Release the lock file
This is normally called automatically when the lock is dropped, but can be called explicitly if needed.
Sourcepub fn set_plan_id(&self, plan_id: &str) -> Result<()>
pub fn set_plan_id(&self, plan_id: &str) -> Result<()>
Update the plan_id in the lock file
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LockFile
impl RefUnwindSafe for LockFile
impl Send for LockFile
impl Sync for LockFile
impl Unpin for LockFile
impl UnsafeUnpin for LockFile
impl UnwindSafe for LockFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more