From cbe1cb4229591a437dd8f2514a8575eb56c41d1f Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 8 Dec 2023 12:46:19 -0500 Subject: [PATCH] Avoid race when unpacking wheels (#593) ## Summary If someone else beats us to the unzip, we should let them win. We already have a check for this at the top of the unzip method, but it's also possible that two source distributions get built in parallel that both try to unpack the same build dependency. --- crates/puffin-installer/src/unzipper.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/puffin-installer/src/unzipper.rs b/crates/puffin-installer/src/unzipper.rs index 790399573..e01702e8a 100644 --- a/crates/puffin-installer/src/unzipper.rs +++ b/crates/puffin-installer/src/unzipper.rs @@ -59,7 +59,15 @@ impl Unzipper { download.unzip(staging.path())?; // Move the unzipped wheel into the cache,. - fs_err::rename(staging.into_path(), download.target())?; + if let Err(err) = fs_err::rename(staging.into_path(), download.target()) { + // If another thread already unpacked the wheel, we can ignore the error. + return if download.target().is_dir() { + warn!("Wheel is already unpacked: {}", download.remote()); + Ok(download.target().to_path_buf()) + } else { + Err(err.into()) + }; + } Ok(download.target().to_path_buf()) }