pub struct LockFile { /* private fields */ }Expand description
Exclusive lock file created by this process.
Drop without Self::commit or Self::commit_to removes the lock file when this
handle created it. Foreign lock files are never removed.
Implementations§
Source§impl LockFile
impl LockFile
Sourcepub fn acquire(target: &Path, wait: LockWait) -> Result<Self, LockError>
pub fn acquire(target: &Path, wait: LockWait) -> Result<Self, LockError>
Create target exclusively (O_CREAT|O_EXCL), optionally waiting per wait.
target is the lock file path (for example refs/heads/main.lock), not the file being
updated. Persist staged bytes with Self::commit_to (or Self::commit after
Self::with_commit_target).
§Errors
Returns LockError::Held when the lock exists and the wait budget is exhausted, or
LockError::Io for other failures.
Sourcepub fn acquire_with_clock(
target: &Path,
wait: LockWait,
clock: Arc<dyn LockClock>,
jitter: Arc<dyn LockJitter>,
) -> Result<Self, LockError>
pub fn acquire_with_clock( target: &Path, wait: LockWait, clock: Arc<dyn LockClock>, jitter: Arc<dyn LockJitter>, ) -> Result<Self, LockError>
Like Self::acquire, with injectable clock and jitter for unit tests.
Sourcepub fn with_commit_target(self, path: &Path) -> Self
pub fn with_commit_target(self, path: &Path) -> Self
Set the destination path used by Self::commit.
Sourcepub fn as_file(&self) -> Result<&File, LockError>
pub fn as_file(&self) -> Result<&File, LockError>
Borrow the open lock file for writing.
§Errors
Returns LockError::Io when the handle was already taken (for example after
the open file handle was moved out for index integration).
Sourcepub fn as_file_mut(&mut self) -> Result<&mut File, LockError>
pub fn as_file_mut(&mut self) -> Result<&mut File, LockError>
Borrow the open lock file mutably for writing.
§Errors
Returns LockError::Io when the handle was already taken.
Sourcepub fn commit(self) -> Result<(), LockError>
pub fn commit(self) -> Result<(), LockError>
Fsync the lock file, rename it over commit_path from Self::with_commit_target, and
disarm drop cleanup.
§Errors
Returns LockError::Io when no commit target was configured or rename fails.
Sourcepub fn commit_to(self, other_path: &Path) -> Result<(), LockError>
pub fn commit_to(self, other_path: &Path) -> Result<(), LockError>
Fsync the lock file and atomically rename it over other_path.
§Errors
Returns LockError::Io on sync or rename failure.
Sourcepub fn write_holder_pid(&mut self) -> Result<(), LockError>
pub fn write_holder_pid(&mut self) -> Result<(), LockError>
Record this process as the holder of Self::lock_path in a Git-compatible pid sidecar.
§Errors
Returns LockError::Io when the sidecar cannot be written.
Trait Implementations§
Source§impl Write for LockFile
impl Write for LockFile
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)