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!(