Skip to main content

LockFile

Struct LockFile 

Source
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

Source

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.

Source

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.

Source

pub fn with_commit_target(self, path: &Path) -> Self

Set the destination path used by Self::commit.

Source

pub fn lock_path(&self) -> &Path

Path to the lock file held by this handle.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn rollback(self)

Release the lock without committing (same as drop).

Source

pub fn detach(self)

Close this handle but leave the lock file on disk (mutex-only locks).

Trait Implementations§

Source§

impl Drop for LockFile

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Write for LockFile

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.