use anyhow::Context;
use colored::Colorize;
use crate::{config::Config, state::LocalState};
pub fn gc(config: &Config, state: &LocalState) -> anyhow::Result<()> {
let orphans = crate::publish::unreferenced(&config.midenup_home, state)?;
if orphans.is_empty() {
crate::info!("nothing to reclaim");
return Ok(());
}
for orphan in &orphans {
crate::info!("removing {}", orphan.display());
std::fs::remove_dir_all(orphan)
.with_context(|| format!("failed to remove '{}'", orphan.display()))?;
}
crate::info!(
"reclaimed {} {}",
orphans.len().to_string().bold(),
if orphans.len() == 1 {
"publication"
} else {
"publications"
}
);
Ok(())
}