Skip to content

Commit 614cb17

Browse files
committed
Make cache robust to removed archives
1 parent f10ccc4 commit 614cb17

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

crates/uv-distribution/src/archive.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use distribution_types::Hashed;
22
use pypi_types::HashDigest;
3-
use uv_cache::ArchiveId;
3+
use uv_cache::{ArchiveId, Cache};
44

55
/// An archive (unzipped wheel) that exists in the local cache.
66
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -16,6 +16,11 @@ impl Archive {
1616
pub(crate) fn new(id: ArchiveId, hashes: Vec<HashDigest>) -> Self {
1717
Self { id, hashes }
1818
}
19+
20+
/// Returns `true` if the archive exists in the cache.
21+
pub(crate) fn exists(&self, cache: &Cache) -> bool {
22+
cache.archive(&self.id).exists()
23+
}
1924
}
2025

2126
impl Hashed for Archive {

crates/uv-distribution/src/distribution_database.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,12 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
596596
CachedClientError::Client(err) => Error::Client(err),
597597
})?;
598598

599-
// If the archive is missing the required hashes, force a refresh.
600-
let archive = if archive.has_digests(hashes) {
599+
// If the archive is missing the required hashes, or has since been removed, force a refresh.
600+
let archive = Some(archive)
601+
.filter(|archive| archive.has_digests(hashes))
602+
.filter(|archive| archive.exists(self.build_context.cache()));
603+
604+
let archive = if let Some(archive) = archive {
601605
archive
602606
} else {
603607
self.client
@@ -746,12 +750,16 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
746750
CachedClientError::Client(err) => Error::Client(err),
747751
})?;
748752

749-
// If the archive is missing the required hashes, force a refresh.
750-
let archive = if archive.has_digests(hashes) {
753+
// If the archive is missing the required hashes, or has since been removed, force a refresh.
754+
let archive = Some(archive)
755+
.filter(|archive| archive.has_digests(hashes))
756+
.filter(|archive| archive.exists(self.build_context.cache()));
757+
758+
let archive = if let Some(archive) = archive {
751759
archive
752760
} else {
753761
self.client
754-
.managed(|client| async move {
762+
.managed(|client| async {
755763
client
756764
.cached_client()
757765
.skip_cache(self.request(url)?, &http_entry, download)

0 commit comments

Comments
 (0)