From d111e5ccf36c1fda9886c56f0a7f2c92d6becfa9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 22 Nov 2025 09:04:39 -0600 Subject: [PATCH] Remove prefix --- crates/uv-cache/src/archive.rs | 19 +++------- crates/uv-cache/src/lib.rs | 35 ++++++++++--------- crates/uv/tests/it/common/mod.rs | 2 +- .../troubleshooting/build-failures.md | 4 +-- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/crates/uv-cache/src/archive.rs b/crates/uv-cache/src/archive.rs index 81e613d60..6e2c07618 100644 --- a/crates/uv-cache/src/archive.rs +++ b/crates/uv-cache/src/archive.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use std::str::FromStr; use uv_pypi_types::{HashAlgorithm, HashDigest}; @@ -35,20 +35,9 @@ impl FromStr for ArchiveVersion { #[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)] pub struct ArchiveId(SmallString); -impl ArchiveId { - /// Return the content-addressed path for the [`ArchiveId`]. - pub fn to_path_buf(&self) -> PathBuf { - if self.0.len() == 21 { - // A 21-digit NanoID. - PathBuf::from(self.0.as_ref()) - } else { - // A SHA256 hex digest, split into three segments. - let mut path = PathBuf::new(); - path.push(&self.0[0..2]); - path.push(&self.0[2..4]); - path.push(&self.0[4..]); - path - } +impl AsRef for ArchiveId { + fn as_ref(&self) -> &Path { + self.0.as_ref().as_ref() } } diff --git a/crates/uv-cache/src/lib.rs b/crates/uv-cache/src/lib.rs index 998dba652..c43d90f5f 100644 --- a/crates/uv-cache/src/lib.rs +++ b/crates/uv-cache/src/lib.rs @@ -263,7 +263,7 @@ impl Cache { /// Return the path to an archive in the cache. pub fn archive(&self, id: &ArchiveId) -> PathBuf { - self.bucket(CacheBucket::Archive).join(id.to_path_buf()) + self.bucket(CacheBucket::Archive).join(id) } /// Create a temporary directory to be used as a Python virtual environment. @@ -352,7 +352,7 @@ impl Cache { ) -> io::Result { // Move the temporary directory into the directory store. let id = ArchiveId::from(hash); - let archive_entry = self.bucket(CacheBucket::Archive).join(id.to_path_buf()); + let archive_entry = self.bucket(CacheBucket::Archive).join(id.as_ref()); if let Some(parent) = archive_entry.parent() { fs_err::create_dir_all(parent)?; } @@ -621,34 +621,34 @@ impl Cache { match fs_err::read_dir(self.bucket(CacheBucket::Archive)) { Ok(entries) => { for entry in entries { - let entry = entry?; // If two hex characters, it's a prefix; recurse. - if entry - .file_name() - .to_str() - .is_some_and(|name| name.len() == 2 && name.chars().all(|c| c.is_ascii_hexdigit())) - { + if entry.file_name().to_str().is_some_and(|name| { + name.len() == 2 && name.chars().all(|c| c.is_ascii_hexdigit()) + }) { match fs_err::read_dir(entry.path()) { Ok(subentries) => { for subentry in subentries { let subentry = subentry?; // If two hex characters, it's a prefix; recurse. - if subentry - .file_name() - .to_str() - .is_some_and(|name| name.len() == 2 && name.chars().all(|c| c.is_ascii_hexdigit())) - { + if subentry.file_name().to_str().is_some_and(|name| { + name.len() == 2 + && name.chars().all(|c| c.is_ascii_hexdigit()) + }) { match fs_err::read_dir(subentry.path()) { Ok(subsubentries) => { for subsubentry in subsubentries { let subsubentry = subsubentry?; - let path = fs_err::canonicalize(subsubentry.path())?; + let path = + fs_err::canonicalize(subsubentry.path())?; if !references.contains_key(&path) { - debug!("Removing dangling cache archive: {}", path.display()); + debug!( + "Removing dangling cache archive: {}", + path.display() + ); summary += rm_rf(path)?; } } @@ -659,7 +659,10 @@ impl Cache { } else { let path = fs_err::canonicalize(subentry.path())?; if !references.contains_key(&path) { - debug!("Removing dangling cache archive: {}", path.display()); + debug!( + "Removing dangling cache archive: {}", + path.display() + ); summary += rm_rf(path)?; } } diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 297c0e792..59c9221f1 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -845,7 +845,7 @@ impl TestContext { )); // Filter archive hashes filters.push(( - r"archive-v(\d+)[\\/][0-9a-f]{2}[\\/][0-9a-f]{2}[\\/][0-9a-f]{60}".to_string(), + r"archive-v(\d+)[\\/][0-9a-f]{64}".to_string(), "archive-v$1/[HASH]".to_string(), )); diff --git a/docs/reference/troubleshooting/build-failures.md b/docs/reference/troubleshooting/build-failures.md index d71ca8bef..3f5f8785e 100644 --- a/docs/reference/troubleshooting/build-failures.md +++ b/docs/reference/troubleshooting/build-failures.md @@ -53,10 +53,10 @@ Collecting numpy==1.19.5 ERROR: Exception: Traceback (most recent call last): ... - File "/Users/example/.cache/uv/archive-v1/3783IbOdglemN3ieOULx2/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook + File "/Users/example/.cache/uv/archive-v0/97de8790030bbd5c2d96b7ec782fc2f7820ef8dba6db909ccf95449f2d062d4b/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_impl.py", line 321, in _call_hook raise BackendUnavailable(data.get('traceback', '')) pip._vendor.pyproject_hooks._impl.BackendUnavailable: Traceback (most recent call last): - File "/Users/example/.cache/uv/archive-v1/3783IbOdglemN3ieOULx2/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend + File "/Users/example/.cache/uv/archive-v0/97de8790030bbd5c2d96b7ec782fc2f7820ef8dba6db909ccf95449f2d062d4b/lib/python3.13/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 77, in _build_backend obj = import_module(mod_path) File "/Users/example/.local/share/uv/python/cpython-3.13.0-macos-aarch64-none/lib/python3.13/importlib/__init__.py", line 88, in import_module return _bootstrap._gcd_import(name[level:], package, level)