Skip to main content

LockFile

Struct LockFile 

Source
pub struct LockFile { /* private fields */ }
Expand description

An exclusively created lock/temp file with atomic publication semantics.

Dropping an unpersisted guard closes the handle and removes the file, so failure paths never leave stale locks behind. Persisting renames the file over its target, which is atomic within a filesystem.

Implementations§

Source§

impl LockFile

Source

pub fn create(path: PathBuf) -> Result<Self>

Exclusively create the lock at exactly path; fails when it already exists (AlreadyExists kind, inspectable via GitError::io_kind).

Source

pub fn acquire(target: &Path) -> Result<Self>

Exclusively create the sibling <target>.lock lock for target.

Source

pub fn path(&self) -> &Path

The lock file’s own path.

Source

pub fn target(&self) -> Option<&Path>

The publication target this lock was acquired for, when known.

Source

pub fn file_mut(&mut self) -> Option<&mut File>

Mutable handle for streaming or filter-style writers.

Source

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

Write the full payload through the lock handle.

Source

pub fn sync( &mut self, policy: &Policy, component: FsyncComponents, ) -> Result<()>

Apply policy’s barrier for component to the lock handle. No-op when the policy excludes the component or the test switch disables syncing.

Source

pub fn persist(self) -> Result<()>

Publish onto the target remembered by Self::acquire: rename the lock over it, removing the lock file if the rename fails.

Source

pub fn persist_into(self, target: &Path) -> Result<()>

Publish onto target: rename the lock over it. On rename failure the lock file is removed and the original error surfaces as GitError::Io, matching the pre-existing dance’s cleanup order.

Source

pub fn persist_racy(self, target: &Path) -> Result<()>

Publish tolerating a concurrent writer that landed first: when the rename fails but target now exists, treat the write as won-by-other and succeed after removing our temp file. This matches the loose object store’s race handling, where two processes may materialize the same content-addressed object simultaneously.

Source

pub fn keep(self) -> (PathBuf, Option<File>)

Disarm drop-cleanup and hand back the (path, handle) pair for mkstemp-style creators whose temporary file must survive the guard.

Trait Implementations§

Source§

impl Debug for LockFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.