Skip to main content

FileLock

Struct FileLock 

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

An exclusive advisory lock over one file, held for as long as the value lives and released when it drops, including on an early ? and by the kernel if the process dies holding it.

The lock is on a sibling <name>.lock, never on the guarded file itself, and that is the whole design decision: a store finishes its write by renameing a new file over the old one, which replaces the inode. A lock on the store would guard an inode the next successful write unlinks, and the writer after that would open the new inode, find it unlocked, and exclude nothing. The lock file is never renamed, rewritten or read; it is an inode with a stable identity, left on disk between writes so every writer keeps agreeing on which one it is.

Two are held at once only over shep.toml and dogs.toml, in that order, which is what keeps the callers that nest them from deadlocking; commands::dog_migration says so where it nests them.

Derives Debug: the fields are a held OS lock handle (a flock(2) wrapper on unix, a bare File on Windows), never a secret.

Implementations§

Source§

impl FileLock

Source

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

Blocks until this process holds path’s lock exclusively.

§Errors

The lock file could not be created beside path, or flock failed for a reason other than contention (contention blocks rather than failing).

Trait Implementations§

Source§

impl Debug for FileLock

Source§

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

Formats the value using the given formatter. 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 = !

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.