Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ chrono = "0.4.40"
clap = { version = "4.5.31", default-features = false }
clap_complete = "4.5.46"
clap_complete_nushell = "4.5.5"
walkdir = "2.5.0"
# Rattler crates
coalesced_map = "0.1.2"
console = "0.16.1"
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ uv-pep508 = { workspace = true }
uv-pypi-types = { workspace = true }
uv-requirements-txt = { workspace = true }
uv-types = { workspace = true }
walkdir = { workspace = true }
which = { workspace = true }
zip = { workspace = true, features = ["deflate", "time"] }

Expand Down
15 changes: 14 additions & 1 deletion crates/pixi_cli/src/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use pixi_core::WorkspaceLocator;
use pixi_manifest::EnvironmentName;
use std::path::PathBuf;
use std::time::Duration;
use walkdir::WalkDir;

use crate::cli_config::WorkspaceConfig;
use clap::Parser;
Expand Down Expand Up @@ -165,6 +166,18 @@ pub async fn execute(args: Args) -> miette::Result<()> {
}
Ok(())
}
// Helper function for calculating size of cache dirs.
fn dir_size(paths: Vec<PathBuf>) -> f64 {
let size: u64 = paths
.iter()
.flat_map(|path| WalkDir::new(path).into_iter().filter_map(|e| e.ok()))
.filter_map(|e| e.metadata().ok())
.filter(|m| m.is_file())
.map(|m| m.len())
.sum();
let size = size as f64 / 1024.0 / 1024.0;
(size * 100.0).round() / 100.0
}

/// Clean the pixi cache folders.
async fn clean_cache(args: CacheArgs) -> miette::Result<()> {
Expand Down Expand Up @@ -214,7 +227,7 @@ async fn clean_cache(args: CacheArgs) -> miette::Result<()> {
eprintln!("{}", console::style("Nothing to remove.").green());
return Ok(());
}

println!("Freeing {} MB.", dir_size(dirs.clone()));
for dir in dirs {
remove_folder_with_progress(dir, true).await?;
}
Expand Down
Loading