diff --git a/crates/uv-cache/src/lib.rs b/crates/uv-cache/src/lib.rs index 0ecf2f39e..e97db0897 100644 --- a/crates/uv-cache/src/lib.rs +++ b/crates/uv-cache/src/lib.rs @@ -447,12 +447,31 @@ impl Cache { Err(err) => return Err(err), } - // Remove any unzipped wheels (i.e., symlinks) from the built wheels cache. for entry in walkdir::WalkDir::new(self.bucket(CacheBucket::SourceDistributions)) { let entry = entry?; - if entry.file_type().is_symlink() { - debug!("Removing unzipped wheel entry: {}", entry.path().display()); - summary += rm_rf(entry.path())?; + + // If the directory contains a `metadata.msgpack`, then it's a built wheel revision. + if !entry.file_type().is_dir() { + continue; + } + + if !entry.path().join("metadata.msgpack").exists() { + continue; + } + + // Remove any symlinks and directories in the revision. The symlinks represent + // unzipped wheels, and the directories represent the source distribution archives. + for entry in fs_err::read_dir(entry.path())? { + let entry = entry?; + let path = entry.path(); + + if path.is_dir() { + debug!("Removing unzipped built wheel entry: {}", path.display()); + summary += rm_rf(path)?; + } else if path.is_symlink() { + debug!("Removing unzipped built wheel entry: {}", path.display()); + summary += rm_rf(path)?; + } } } } diff --git a/crates/uv/tests/cache_prune.rs b/crates/uv/tests/cache_prune.rs index 2c3c436a7..227150c49 100644 --- a/crates/uv/tests/cache_prune.rs +++ b/crates/uv/tests/cache_prune.rs @@ -204,7 +204,7 @@ fn prune_unzipped() -> Result<()> { ----- stderr ----- Pruning cache at: [CACHE_DIR]/ - Removed 162 files ([SIZE]) + Removed 170 files ([SIZE]) "###); // Reinstalling the source distribution should not require re-downloading the source diff --git a/docs/concepts/cache.md b/docs/concepts/cache.md index 04caf9889..7f5c9441b 100644 --- a/docs/concepts/cache.md +++ b/docs/concepts/cache.md @@ -115,9 +115,9 @@ from source tends to be worthwhile, since the wheel building process can be expe for extension modules. To support this caching strategy, uv provides a `uv cache prune --ci` command, which removes all -pre-built wheels from the cache but retains any wheels that were built from source. We recommend -running `uv cache prune --ci` at the end of your continuous integration job to ensure maximum cache -efficiency. For an example, see the +pre-built wheels and unzipped source distributions from the cache, but retains any wheels that were +built from source. We recommend running `uv cache prune --ci` at the end of your continuous +integration job to ensure maximum cache efficiency. For an example, see the [GitHub integration guide](../guides/integration/github.md#caching). ## Cache directory