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
impl LockFile
Sourcepub fn create(path: PathBuf) -> Result<Self>
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).
Sourcepub fn acquire(target: &Path) -> Result<Self>
pub fn acquire(target: &Path) -> Result<Self>
Exclusively create the sibling <target>.lock lock for target.
Sourcepub fn target(&self) -> Option<&Path>
pub fn target(&self) -> Option<&Path>
The publication target this lock was acquired for, when known.
Sourcepub fn file_mut(&mut self) -> Option<&mut File>
pub fn file_mut(&mut self) -> Option<&mut File>
Mutable handle for streaming or filter-style writers.
Sourcepub fn write_all(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_all(&mut self, bytes: &[u8]) -> Result<()>
Write the full payload through the lock handle.
Sourcepub fn sync(
&mut self,
policy: &Policy,
component: FsyncComponents,
) -> Result<()>
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.
Sourcepub fn persist(self) -> Result<()>
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.
Sourcepub fn persist_into(self, target: &Path) -> Result<()>
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.
Sourcepub fn persist_racy(self, target: &Path) -> Result<()>
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.