mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
uv cache prune
removes all cached environments (#4845)
## Summary Resolves #4802 ## Test Plan - `cargo test` ```sh ❯ cargo run -- cache prune -v Pruning cache at: /Users/ahmedilyas/Library/Caches/uv No unused entries found ❯ cargo run -- tool run cowsay warning: `uv tool run` is experimental and may change without warning. Resolved 1 package in 182ms Installed 1 package in 20ms + cowsay==6.1 usage: Cowsay [-h] [-c CHARACTER] -t TEXT [-v] Cowsay: error: the following arguments are required: -t/--text ❯ cargo run -- cache prune -v Pruning cache at: /Users/ahmedilyas/Library/Caches/uv 0.793440s DEBUG uv_cache Removing dangling cache entry: /Users/ahmedilyas/Library/Caches/uv/environments-v1/095cd7c4c298a0d8 Removed 41 files (143.5KiB) ```
This commit is contained in:
parent
798ec373c0
commit
6c8ce1d013
3 changed files with 84 additions and 6 deletions
|
@ -388,13 +388,34 @@ impl Cache {
|
|||
}
|
||||
}
|
||||
|
||||
for entry in fs::read_dir(self.bucket(CacheBucket::Archive))? {
|
||||
let entry = entry?;
|
||||
let path = entry.path().canonicalize()?;
|
||||
if !references.contains(&path) {
|
||||
debug!("Removing dangling cache entry: {}", path.display());
|
||||
summary += rm_rf(path)?;
|
||||
match fs::read_dir(self.bucket(CacheBucket::Archive)) {
|
||||
Ok(entries) => {
|
||||
for entry in entries {
|
||||
let entry = entry?;
|
||||
let path = entry.path().canonicalize()?;
|
||||
if !references.contains(&path) {
|
||||
debug!("Removing dangling cache entry: {}", path.display());
|
||||
summary += rm_rf(path)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
|
||||
// Third, remove any cached environments. These are never referenced by symlinks, so we can
|
||||
// remove them directly.
|
||||
match fs::read_dir(self.bucket(CacheBucket::Environments)) {
|
||||
Ok(entries) => {
|
||||
for entry in entries {
|
||||
let entry = entry?;
|
||||
let path = entry.path().canonicalize()?;
|
||||
debug!("Removing dangling cache entry: {}", path.display());
|
||||
summary += rm_rf(path)?;
|
||||
}
|
||||
}
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => (),
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
|
||||
Ok(summary)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue