From 9b1328af3db3d60db395cf73959aa233c699afd5 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 27 Aug 2025 11:42:39 -0500 Subject: [PATCH] Lock during installs in `uv format` to prevent races (#15551) Closes https://github.com/astral-sh/uv/issues/15513 --- crates/uv-bin-install/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/uv-bin-install/src/lib.rs b/crates/uv-bin-install/src/lib.rs index 058c6f652..5e6857245 100644 --- a/crates/uv-bin-install/src/lib.rs +++ b/crates/uv-bin-install/src/lib.rs @@ -165,8 +165,6 @@ pub async fn bin_install( ) -> Result { let platform = Platform::from_env()?; let platform_name = platform.as_cargo_dist_triple(); - - // Check the cache first let cache_entry = CacheEntry::new( cache .bucket(CacheBucket::Binaries) @@ -176,6 +174,8 @@ pub async fn bin_install( binary.executable(), ); + // Lock the directory to prevent racing installs + let _lock = cache_entry.with_file(".lock").lock().await?; if cache_entry.path().exists() { return Ok(cache_entry.into_path_buf()); }