Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cache robust to removed archives #6284

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/uv-distribution/src/archive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use distribution_types::Hashed;
use pypi_types::HashDigest;
use uv_cache::ArchiveId;
use uv_cache::{ArchiveId, Cache};

/// An archive (unzipped wheel) that exists in the local cache.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
Expand All @@ -16,6 +16,11 @@ impl Archive {
pub(crate) fn new(id: ArchiveId, hashes: Vec<HashDigest>) -> Self {
Self { id, hashes }
}

/// Returns `true` if the archive exists in the cache.
pub(crate) fn exists(&self, cache: &Cache) -> bool {
cache.archive(&self.id).exists()
}
}

impl Hashed for Archive {
Expand Down
18 changes: 13 additions & 5 deletions crates/uv-distribution/src/distribution_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,12 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
CachedClientError::Client(err) => Error::Client(err),
})?;

// If the archive is missing the required hashes, force a refresh.
let archive = if archive.has_digests(hashes) {
// If the archive is missing the required hashes, or has since been removed, force a refresh.
let archive = Some(archive)
.filter(|archive| archive.has_digests(hashes))
.filter(|archive| archive.exists(self.build_context.cache()));

let archive = if let Some(archive) = archive {
archive
} else {
self.client
Expand Down Expand Up @@ -746,12 +750,16 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
CachedClientError::Client(err) => Error::Client(err),
})?;

// If the archive is missing the required hashes, force a refresh.
let archive = if archive.has_digests(hashes) {
// If the archive is missing the required hashes, or has since been removed, force a refresh.
let archive = Some(archive)
.filter(|archive| archive.has_digests(hashes))
.filter(|archive| archive.exists(self.build_context.cache()));

let archive = if let Some(archive) = archive {
archive
} else {
self.client
.managed(|client| async move {
.managed(|client| async {
client
.cached_client()
.skip_cache(self.request(url)?, &http_entry, download)
Expand Down
Loading