Lock during installs in `uv format` to prevent races (#15551)

Closes https://github.com/astral-sh/uv/issues/15513
This commit is contained in:
Zanie Blue 2025-08-27 11:42:39 -05:00 committed by GitHub
parent 0bde9e4b8f
commit 9b1328af3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -165,8 +165,6 @@ pub async fn bin_install(
) -> Result<PathBuf, Error> { ) -> Result<PathBuf, Error> {
let platform = Platform::from_env()?; let platform = Platform::from_env()?;
let platform_name = platform.as_cargo_dist_triple(); let platform_name = platform.as_cargo_dist_triple();
// Check the cache first
let cache_entry = CacheEntry::new( let cache_entry = CacheEntry::new(
cache cache
.bucket(CacheBucket::Binaries) .bucket(CacheBucket::Binaries)
@ -176,6 +174,8 @@ pub async fn bin_install(
binary.executable(), binary.executable(),
); );
// Lock the directory to prevent racing installs
let _lock = cache_entry.with_file(".lock").lock().await?;
if cache_entry.path().exists() { if cache_entry.path().exists() {
return Ok(cache_entry.into_path_buf()); return Ok(cache_entry.into_path_buf());
} }