From 6f7d0dc7b43e28a94830a91f7ae3419b0276bbe0 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 6 Oct 2025 11:49:24 -0500 Subject: [PATCH] Emit a message on `cache clean` and `prune` when lock is held (#16138) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes https://github.com/astral-sh/uv/issues/16112 ``` ❯ cargo run -q cache clean Cache is currently in-use, waiting for other uv processes to finish (use `--force` to override) ``` Otherwise, `-v` is required to see we're waiting on a lock. I'd rather do this than elevate the exclusive lock log message to something more verbose because this allows us to use a more specific message as appropriate for the situation. We also previously reduced the verbosity of arbitrary locks, e.g., see https://github.com/astral-sh/uv/issues/7489 --- crates/uv/src/commands/cache_clean.rs | 22 ++++++++++++---------- crates/uv/src/commands/cache_prune.rs | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/crates/uv/src/commands/cache_clean.rs b/crates/uv/src/commands/cache_clean.rs index da0f5c599..0c7c613c8 100644 --- a/crates/uv/src/commands/cache_clean.rs +++ b/crates/uv/src/commands/cache_clean.rs @@ -28,17 +28,19 @@ pub(crate) fn cache_clean( return Ok(ExitStatus::Success); } - let cache = if force { - // If `--force` is used, attempt to acquire the exclusive lock but do not block. - match cache.with_exclusive_lock_no_wait() { - Ok(cache) => cache, - Err(cache) => { - debug!("Cache is currently in use, proceeding due to `--force`"); - cache - } + let cache = match cache.with_exclusive_lock_no_wait() { + Ok(cache) => cache, + Err(cache) if force => { + debug!("Cache is currently in use, proceeding due to `--force`"); + cache + } + Err(cache) => { + writeln!( + printer.stderr(), + "Cache is currently in-use, waiting for other uv processes to finish (use `--force` to override)" + )?; + cache.with_exclusive_lock()? } - } else { - cache.with_exclusive_lock()? }; let summary = if packages.is_empty() { diff --git a/crates/uv/src/commands/cache_prune.rs b/crates/uv/src/commands/cache_prune.rs index 1087a0043..af7b445d5 100644 --- a/crates/uv/src/commands/cache_prune.rs +++ b/crates/uv/src/commands/cache_prune.rs @@ -26,17 +26,19 @@ pub(crate) fn cache_prune( return Ok(ExitStatus::Success); } - let cache = if force { - // If `--force` is used, attempt to acquire the exclusive lock but do not block. - match cache.with_exclusive_lock_no_wait() { - Ok(cache) => cache, - Err(cache) => { - debug!("Cache is currently in use, proceeding due to `--force`"); - cache - } + let cache = match cache.with_exclusive_lock_no_wait() { + Ok(cache) => cache, + Err(cache) if force => { + debug!("Cache is currently in use, proceeding due to `--force`"); + cache + } + Err(cache) => { + writeln!( + printer.stderr(), + "Cache is currently in-use, waiting for other uv processes to finish (use `--force` to override)" + )?; + cache.with_exclusive_lock()? } - } else { - cache.with_exclusive_lock()? }; writeln!(