Skip to content

Commit 48ca3d5

Browse files
committed
Remove prefix
1 parent 936b1cf commit 48ca3d5

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

crates/uv-cache/src/archive.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::PathBuf;
1+
use std::path::{Path, };
22
use std::str::FromStr;
33

44
use uv_pypi_types::{HashAlgorithm, HashDigest};
@@ -35,20 +35,9 @@ impl FromStr for ArchiveVersion {
3535
#[derive(Debug, Clone, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)]
3636
pub struct ArchiveId(SmallString);
3737

38-
impl ArchiveId {
39-
/// Return the content-addressed path for the [`ArchiveId`].
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
51-
}
38+
impl AsRef<Path> for ArchiveId {
39+
fn as_ref(&self) -> &Path {
40+
self.0.as_ref().as_ref()
5241
}
5342
}
5443

crates/uv-cache/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl Cache {
263263

264264
/// Return the path to an archive in the cache.
265265
pub fn archive(&self, id: &ArchiveId) -> PathBuf {
266-
self.bucket(CacheBucket::Archive).join(id.to_path_buf())
266+
self.bucket(CacheBucket::Archive).join(id)
267267
}
268268

269269
/// Create a temporary directory to be used as a Python virtual environment.
@@ -352,7 +352,7 @@ impl Cache {
352352
) -> io::Result<ArchiveId> {
353353
// Move the temporary directory into the directory store.
354354
let id = ArchiveId::from(hash);
355-
let archive_entry = self.bucket(CacheBucket::Archive).join(id.to_path_buf());
355+
let archive_entry = self.bucket(CacheBucket::Archive).join(id.as_ref());
356356
if let Some(parent) = archive_entry.parent() {
357357
fs_err::create_dir_all(parent)?;
358358
}

crates/uv/tests/it/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ impl TestContext {
845845
));
846846
// Filter archive hashes
847847
filters.push((
848-
r"archive-v(\d+)[\\/][0-9a-f]{2}[\\/][0-9a-f]{2}[\\/][0-9a-f]{60}".to_string(),
848+
r"archive-v(\d+)[\\/][0-9a-f]{64}".to_string(),
849849
"archive-v$1/[HASH]".to_string(),
850850
));
851851

0 commit comments

Comments
 (0)