diff --git a/crates/puffin-cli/src/commands/clean.rs b/crates/puffin-cli/src/commands/clean.rs index c81a3aaad..d25be4b4e 100644 --- a/crates/puffin-cli/src/commands/clean.rs +++ b/crates/puffin-cli/src/commands/clean.rs @@ -1,6 +1,6 @@ use std::path::Path; -use anyhow::Result; +use anyhow::{Context, Result}; use tracing::info; use crate::commands::ExitStatus; @@ -11,7 +11,32 @@ pub(crate) async fn clean(cache: Option<&Path>) -> Result { return Err(anyhow::anyhow!("No cache found")); }; + if !cache.exists() { + return Ok(ExitStatus::Success); + } + info!("Clearing cache at {}", cache.display()); - cacache::clear(cache).await?; + + for entry in cache + .read_dir() + .with_context(|| { + format!( + "Failed to read directory contents while clearing {}", + cache.display() + ) + })? + .flatten() + { + if entry.file_type()?.is_dir() { + tokio::fs::remove_dir_all(entry.path()) + .await + .with_context(|| format!("Failed to clear cache at {}", cache.display()))?; + } else { + tokio::fs::remove_file(entry.path()) + .await + .with_context(|| format!("Failed to clear cache at {}", cache.display()))?; + } + } + Ok(ExitStatus::Success) }