mirror of https://github.com/astral-sh/uv
Remove prefix
This commit is contained in:
parent
936b1cff03
commit
d111e5ccf3
|
|
@ -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<Path> for ArchiveId {
|
||||
fn as_ref(&self) -> &Path {
|
||||
self.0.as_ref().as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ArchiveId> {
|
||||
// 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)?;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue