Prune unused source distributions from the cache (#7112)

## Summary

This has bothered me for a while and should be fairly impactful for
users. It requires a weird implementation, since the
distribution-building crate depends on the cache, and so the prune
operation can't live in the cache, since it needs to access internals of
the distribution-building crate.

Closes https://github.com/astral-sh/uv/issues/7096.
This commit is contained in:
Charlie Marsh 2024-09-05 21:40:51 -04:00 committed by GitHub
parent 1422e18674
commit 93fe3e83be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 213 additions and 10 deletions

View file

@ -18,7 +18,7 @@ use uv_normalize::PackageName;
pub use crate::by_timestamp::CachedByTimestamp;
#[cfg(feature = "clap")]
pub use crate::cli::CacheArgs;
use crate::removal::{rm_rf, Removal};
pub use crate::removal::{rm_rf, Removal};
pub use crate::timestamp::Timestamp;
pub use crate::wheel::WheelCache;
use crate::wheel::WheelCacheKind;
@ -458,9 +458,7 @@ impl Cache {
}
}
// Third, remove any unused archives (by searching for archives that are not symlinked).
// TODO(charlie): Remove any unused source distributions. This requires introspecting the
// cache contents, e.g., reading and deserializing the manifests.
// Fourth, remove any unused archives (by searching for archives that are not symlinked).
let mut references = FxHashSet::default();
for bucket in CacheBucket::iter() {

View file

@ -7,7 +7,7 @@ use std::path::Path;
/// Remove a file or directory and all its contents, returning a [`Removal`] with
/// the number of files and directories removed, along with a total byte count.
pub(crate) fn rm_rf(path: impl AsRef<Path>) -> io::Result<Removal> {
pub fn rm_rf(path: impl AsRef<Path>) -> io::Result<Removal> {
let mut removal = Removal::default();
removal.rm_rf(path.as_ref())?;
Ok(removal)