pub struct ProjectLock { /* private fields */ }Expand description
A file lock for project-level operations.
Provides cross-process synchronization for operations like resource installation. Uses OS-level file locking via the fs4 crate.
§Lock File Location
Lock files are stored in {project_dir}/.agpm/.locks/{lock_name}.lock
§Example
use agpm_cli::installer::project_lock::ProjectLock;
use std::path::Path;
let project_dir = Path::new("/path/to/project");
// Acquire resource lock for file writes
let _lock = ProjectLock::acquire(project_dir, "resource").await?;
// Perform file operations...
// Lock is automatically released when _lock goes out of scopeImplementations§
Source§impl ProjectLock
impl ProjectLock
Sourcepub async fn acquire(project_dir: &Path, lock_name: &str) -> Result<Self>
pub async fn acquire(project_dir: &Path, lock_name: &str) -> Result<Self>
Acquires an exclusive lock for a project operation.
Creates and acquires an exclusive file lock for the specified lock name. Uses non-blocking lock attempts with exponential backoff and timeout.
§Lock File Management
- Creates
.agpm/.locks/directory if needed - Creates
{lock_name}.lockfile - Acquires exclusive access via OS file locking
- Keeps file handle open to maintain lock
§Behavior
- Timeout: 30-second default (configurable via
acquire_with_timeout) - Non-blocking:
try_lock_exclusive()in async retry loop - Backoff: 10ms → 20ms → 40ms… up to 500ms max
§Errors
- Permission denied creating lock directory
- Disk space exhausted
- Timeout acquiring lock
§Platform Support
- Windows: Win32
LockFileAPI - Unix: POSIX
fcntl()locking
Sourcepub async fn acquire_with_timeout(
project_dir: &Path,
lock_name: &str,
timeout: Duration,
) -> Result<Self>
pub async fn acquire_with_timeout( project_dir: &Path, lock_name: &str, timeout: Duration, ) -> Result<Self>
Acquires an exclusive lock with a specified timeout.
Uses exponential backoff (10ms → 500ms) without blocking the async runtime.
§Errors
Returns timeout error if lock cannot be acquired within the specified duration.
Trait Implementations§
Source§impl Debug for ProjectLock
impl Debug for ProjectLock
Auto Trait Implementations§
impl Freeze for ProjectLock
impl RefUnwindSafe for ProjectLock
impl Send for ProjectLock
impl Sync for ProjectLock
impl Unpin for ProjectLock
impl UnwindSafe for ProjectLock
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more