Skip to content

Commit 0b8c764

Browse files
committed
Remove sync zip
1 parent 3bf79e2 commit 0b8c764

File tree

19 files changed

+84
-620
lines changed

19 files changed

+84
-620
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-cache/src/archive.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ use uv_pypi_types::{HashAlgorithm, HashDigest};
55
use uv_small_str::SmallString;
66

77
/// The latest version of the archive bucket.
8-
pub static LATEST: ArchiveVersion = ArchiveVersion::V1;
8+
pub static LATEST: ArchiveVersion = ArchiveVersion::V0;
99

1010
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
1111
pub enum ArchiveVersion {
1212
V0 = 0,
13-
V1 = 1,
1413
}
1514

1615
impl std::fmt::Display for ArchiveVersion {
1716
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1817
match self {
1918
Self::V0 => write!(f, "0"),
20-
Self::V1 => write!(f, "1"),
2119
}
2220
}
2321
}
@@ -28,7 +26,6 @@ impl FromStr for ArchiveVersion {
2826
fn from_str(s: &str) -> Result<Self, Self::Err> {
2927
match s {
3028
"0" => Ok(Self::V0),
31-
"1" => Ok(Self::V1),
3229
_ => Err(()),
3330
}
3431
}
@@ -40,18 +37,17 @@ pub struct ArchiveId(SmallString);
4037

4138
impl ArchiveId {
4239
/// Return the content-addressed path for the [`ArchiveId`].
43-
pub fn to_path_buf(&self, version: ArchiveVersion) -> PathBuf {
44-
match version {
45-
// Version 0: A 21-digit NanoID.
46-
ArchiveVersion::V0 => PathBuf::from(self.0.as_ref()),
47-
// Version 1: A SHA256 hex digest, split into three segments.
48-
ArchiveVersion::V1 => {
49-
let mut path = PathBuf::new();
50-
path.push(&self.0[0..2]);
51-
path.push(&self.0[2..4]);
52-
path.push(&self.0[4..]);
53-
path
54-
}
40+
pub fn to_path_buf(&self) -> PathBuf {
41+
if self.0.len() == 21 {
42+
// A 21-digit NanoID.
43+
PathBuf::from(self.0.as_ref())
44+
} else {
45+
// A SHA256 hex digest, split into three segments.
46+
let mut path = PathBuf::new();
47+
path.push(&self.0[0..2]);
48+
path.push(&self.0[2..4]);
49+
path.push(&self.0[4..]);
50+
path
5551
}
5652
}
5753
}

crates/uv-cache/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn migrate_windows_cache(source: &Path, destination: &Path) -> Result<(), io::Er
9696
"interpreter-v2",
9797
"simple-v12",
9898
"wheels-v1",
99-
"archive-v1",
99+
"archive-v0",
100100
"builds-v0",
101101
"environments-v1",
102102
] {

crates/uv-cache/src/lib.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,8 @@ impl Cache {
262262
}
263263

264264
/// Return the path to an archive in the cache.
265-
pub fn archive(&self, id: &ArchiveId, version: ArchiveVersion) -> PathBuf {
266-
// TODO(charlie): Reuse `CacheBucket::Archive`.
267-
self.root
268-
.join(format!("archive-v{version}"))
269-
.join(id.to_path_buf(version))
265+
pub fn archive(&self, id: &ArchiveId) -> PathBuf {
266+
self.bucket(CacheBucket::Archive).join(id.to_path_buf())
270267
}
271268

272269
/// Create a temporary directory to be used as a Python virtual environment.
@@ -355,9 +352,7 @@ impl Cache {
355352
) -> io::Result<ArchiveId> {
356353
// Move the temporary directory into the directory store.
357354
let id = ArchiveId::from(hash);
358-
let archive_entry = self
359-
.bucket(CacheBucket::Archive)
360-
.join(id.to_path_buf(LATEST));
355+
let archive_entry = self.bucket(CacheBucket::Archive).join(id.to_path_buf());
361356
if let Some(parent) = archive_entry.parent() {
362357
fs_err::create_dir_all(parent)?;
363358
}
@@ -744,7 +739,7 @@ impl Cache {
744739
let link = Link::from_str(&contents)?;
745740

746741
// Ignore stale links.
747-
if link.version != ARCHIVE_VERSION {
742+
if link.version != LATEST {
748743
return Err(io::Error::new(
749744
io::ErrorKind::NotFound,
750745
"The link target does not exist.",
@@ -763,7 +758,7 @@ impl Cache {
763758
#[cfg(unix)]
764759
pub fn create_link(&self, id: &ArchiveId, dst: impl AsRef<Path>) -> io::Result<()> {
765760
// Construct the link target.
766-
let src = self.archive(id, ArchiveVersion::V1);
761+
let src = self.archive(id);
767762
let dst = dst.as_ref();
768763

769764
// Attempt to create the symlink directly.
@@ -809,7 +804,7 @@ impl Link {
809804
fn new(id: ArchiveId) -> Self {
810805
Self {
811806
id,
812-
version: ArchiveVersion::V1,
807+
version: ArchiveVersion::V0,
813808
}
814809
}
815810
}
@@ -1130,7 +1125,7 @@ impl CacheBucket {
11301125
Self::Wheels => "wheels-v5",
11311126
// Note that when bumping this, you'll also need to bump
11321127
// `ARCHIVE_VERSION` in `crates/uv-cache/src/lib.rs`.
1133-
Self::Archive => "archive-v1",
1128+
Self::Archive => "archive-v0",
11341129
Self::Builds => "builds-v0",
11351130
Self::Environments => "environments-v2",
11361131
Self::Python => "python-v0",
@@ -1394,10 +1389,8 @@ mod tests {
13941389

13951390
#[test]
13961391
fn test_link_deserialize() {
1397-
assert!(Link::from_str("archive-v1/foo").is_ok());
1392+
assert!(Link::from_str("archive-v0/foo").is_ok());
13981393
assert!(Link::from_str("archive/foo").is_err());
13991394
assert!(Link::from_str("v1/foo").is_err());
1400-
assert!(Link::from_str("archive-v1/").is_err());
1401-
assert!(Link::from_str("archive-v0/foo").is_ok());
14021395
}
14031396
}

crates/uv-distribution/src/archive.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use uv_cache::{ArchiveId, ArchiveVersion, Cache, LATEST};
1+
use uv_cache::{ArchiveId, ArchiveVersion, LATEST};
22
use uv_distribution_filename::WheelFilename;
33
use uv_distribution_types::Hashed;
44
use uv_pypi_types::{HashAlgorithm, HashDigest, HashDigests};
@@ -34,11 +34,6 @@ impl Archive {
3434
version: LATEST,
3535
}
3636
}
37-
38-
/// Returns `true` if the archive exists in the cache.
39-
pub(crate) fn exists(&self, cache: &Cache) -> bool {
40-
cache.archive(&self.id, self.version).exists()
41-
}
4237
}
4338

4439
impl Hashed for Archive {

crates/uv-distribution/src/distribution_database.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
227227
archive: self
228228
.build_context
229229
.cache()
230-
.archive(&archive.id, archive.version)
230+
.archive(&archive.id)
231231
.into_boxed_path(),
232232
hashes: archive.hashes,
233233
filename: wheel.filename.clone(),
@@ -265,7 +265,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
265265
archive: self
266266
.build_context
267267
.cache()
268-
.archive(&archive.id, archive.version)
268+
.archive(&archive.id)
269269
.into_boxed_path(),
270270
hashes: archive.hashes,
271271
filename: wheel.filename.clone(),
@@ -304,7 +304,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
304304
archive: self
305305
.build_context
306306
.cache()
307-
.archive(&archive.id, archive.version)
307+
.archive(&archive.id)
308308
.into_boxed_path(),
309309
hashes: archive.hashes,
310310
filename: wheel.filename.clone(),
@@ -335,7 +335,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
335335
archive: self
336336
.build_context
337337
.cache()
338-
.archive(&archive.id, archive.version)
338+
.archive(&archive.id)
339339
.into_boxed_path(),
340340
hashes: archive.hashes,
341341
filename: wheel.filename.clone(),
@@ -421,11 +421,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
421421

422422
Ok(LocalWheel {
423423
dist: Dist::Source(dist.clone()),
424-
archive: self
425-
.build_context
426-
.cache()
427-
.archive(&id, LATEST)
428-
.into_boxed_path(),
424+
archive: self.build_context.cache().archive(&id).into_boxed_path(),
429425
hashes: built_wheel.hashes,
430426
filename: built_wheel.filename,
431427
cache: built_wheel.cache_info,
@@ -689,7 +685,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
689685
Connectivity::Offline => CacheControl::AllowStale,
690686
};
691687

692-
let archive = self
688+
let archive: Archive = self
693689
.client
694690
.managed(|client| {
695691
client.cached_client().get_serde_with_retry(
@@ -708,7 +704,8 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
708704
// If the archive is missing the required hashes, or has since been removed, force a refresh.
709705
let archive = Some(archive)
710706
.filter(|archive| archive.has_digests(hashes))
711-
.filter(|archive| archive.exists(self.build_context.cache()));
707+
.filter(|archive| archive.version == LATEST)
708+
.filter(|archive| self.build_context.cache().archive(&archive.id).exists());
712709

713710
let archive = if let Some(archive) = archive {
714711
archive
@@ -875,7 +872,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
875872
Connectivity::Offline => CacheControl::AllowStale,
876873
};
877874

878-
let archive = self
875+
let archive: Archive = self
879876
.client
880877
.managed(|client| {
881878
client.cached_client().get_serde_with_retry(
@@ -894,7 +891,8 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
894891
// If the archive is missing the required hashes, or has since been removed, force a refresh.
895892
let archive = Some(archive)
896893
.filter(|archive| archive.has_digests(hashes))
897-
.filter(|archive| archive.exists(self.build_context.cache()));
894+
.filter(|archive| archive.version == LATEST)
895+
.filter(|archive| self.build_context.cache().archive(&archive.id).exists());
898896

899897
let archive = if let Some(archive) = archive {
900898
archive
@@ -957,7 +955,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
957955
archive: self
958956
.build_context
959957
.cache()
960-
.archive(&archive.id, archive.version)
958+
.archive(&archive.id)
961959
.into_boxed_path(),
962960
hashes: archive.hashes,
963961
filename: filename.clone(),
@@ -1024,7 +1022,7 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
10241022
archive: self
10251023
.build_context
10261024
.cache()
1027-
.archive(&archive.id, archive.version)
1025+
.archive(&archive.id)
10281026
.into_boxed_path(),
10291027
hashes: archive.hashes,
10301028
filename: filename.clone(),

crates/uv-distribution/src/index/cached_wheel.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22

3-
use uv_cache::{Cache, CacheEntry};
3+
use uv_cache::{Cache, CacheEntry, LATEST};
44
use uv_cache_info::CacheInfo;
55
use uv_distribution_filename::WheelFilename;
66
use uv_distribution_types::{
@@ -82,9 +82,14 @@ impl CachedWheel {
8282
hashes,
8383
..
8484
} = archive;
85-
let path = cache.archive(&id, version);
85+
86+
// Ignore out-of-date versions.
87+
if version != LATEST {
88+
return None;
89+
}
8690

8791
// Ignore stale pointers.
92+
let path = cache.archive(&id);
8893
if !path.exists() {
8994
return None;
9095
}
@@ -114,9 +119,14 @@ impl CachedWheel {
114119
hashes,
115120
..
116121
} = archive;
117-
let path = cache.archive(&id, version);
122+
123+
// Ignore out-of-date versions.
124+
if version != LATEST {
125+
return None;
126+
}
118127

119128
// Ignore stale pointers.
129+
let path = cache.archive(&id);
120130
if !path.exists() {
121131
return None;
122132
}

crates/uv-extract/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ doctest = false
1616
workspace = true
1717

1818
[dependencies]
19-
uv-configuration = { workspace = true }
2019
uv-distribution-filename = { workspace = true }
2120
uv-pypi-types = { workspace = true }
2221
uv-static = { workspace = true }
@@ -28,7 +27,6 @@ blake2 = { workspace = true }
2827
fs-err = { workspace = true, features = ["tokio"] }
2928
futures = { workspace = true }
3029
md-5 = { workspace = true }
31-
rayon = { workspace = true }
3230
regex = { workspace = true }
3331
reqwest = { workspace = true }
3432
rustc-hash = { workspace = true }
@@ -39,7 +37,6 @@ tokio = { workspace = true }
3937
tokio-util = { workspace = true, features = ["compat"] }
4038
tracing = { workspace = true }
4139
xz2 = { workspace = true }
42-
zip = { workspace = true }
4340
zstd = { workspace = true }
4441

4542
[features]

crates/uv-extract/src/error.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ use std::{ffi::OsString, path::PathBuf};
44
pub enum Error {
55
#[error("I/O operation failed during extraction")]
66
Io(#[source] std::io::Error),
7-
#[error("Invalid zip file")]
8-
Zip(#[from] zip::result::ZipError),
97
#[error("Invalid zip file structure")]
108
AsyncZip(#[from] async_zip::error::ZipError),
119
#[error("Invalid tar file")]
@@ -113,10 +111,6 @@ impl Error {
113111
Ok(zip_err) => return Self::AsyncZip(zip_err),
114112
Err(err) => err,
115113
};
116-
let err = match err.downcast::<zip::result::ZipError>() {
117-
Ok(zip_err) => return Self::Zip(zip_err),
118-
Err(err) => err,
119-
};
120114

121115
Self::Io(err)
122116
}

0 commit comments

Comments
 (0)