Function cargo::util::flock::acquire

source ·
fn acquire(
    gctx: &GlobalContext,
    msg: &str,
    path: &Path,
    lock_try: &dyn Fn() -> Result<()>,
    lock_block: &dyn Fn() -> Result<()>
) -> CargoResult<()>
Expand description

Acquires a lock on a file in a “nice” manner.

Almost all long-running blocking actions in Cargo have a status message associated with them as we’re not sure how long they’ll take. Whenever a conflicted file lock happens, this is the case (we’re not sure when the lock will be released).

This function will acquire the lock on a path, printing out a nice message to the console if we have to wait for it. It will first attempt to use try to acquire a lock on the crate, and in the case of contention it will emit a status message based on msg to GlobalContext’s shell, and then use block to block waiting to acquire a lock.

Returns an error if the lock could not be acquired or if any error other than a contention error happens.