Skip to content

Commit

Permalink
Show total cleaned/to clean amount
Browse files Browse the repository at this point in the history
fixes holmgr#43
  • Loading branch information
birkenfeld committed Dec 3, 2022
1 parent 95fce4a commit 4d0a722
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ fn main() -> anyhow::Result<()> {

let dry_run = matches.is_present("dry-run");

let mut total_cleaned = 0;

// Default to current invocation path.
let path = match matches.value_of("path") {
Some(p) => PathBuf::from(p),
Expand Down Expand Up @@ -251,9 +253,13 @@ fn main() -> anyhow::Result<()> {
for project_path in &paths {
match remove_not_built_with(project_path, matches.value_of("toolchains"), dry_run) {
Ok(cleaned_amount) if dry_run => {
total_cleaned += cleaned_amount;
info!("Would clean: {}", format_bytes(cleaned_amount))
}
Ok(cleaned_amount) => info!("Cleaned {}", format_bytes(cleaned_amount)),
Ok(cleaned_amount) => {
total_cleaned += cleaned_amount;
info!("Cleaned {}", format_bytes(cleaned_amount))
}
Err(e) => error!(
"{:?}",
e.context(format!("Failed to clean {:?}", project_path))
Expand All @@ -275,9 +281,13 @@ fn main() -> anyhow::Result<()> {
for project_path in &paths {
match remove_older_until_fits(project_path, size, dry_run) {
Ok(cleaned_amount) if dry_run => {
total_cleaned += cleaned_amount;
info!("Would clean: {}", format_bytes(cleaned_amount))
}
Ok(cleaned_amount) => info!("Cleaned {}", format_bytes(cleaned_amount)),
Ok(cleaned_amount) => {
total_cleaned += cleaned_amount;
info!("Cleaned {}", format_bytes(cleaned_amount))
}
Err(e) => error!("Failed to clean {:?}: {:?}", project_path, e),
};
}
Expand All @@ -297,13 +307,19 @@ fn main() -> anyhow::Result<()> {
for project_path in &paths {
match remove_older_than(project_path, &keep_duration, dry_run) {
Ok(cleaned_amount) if dry_run => {
total_cleaned += cleaned_amount;
info!("Would clean: {}", format_bytes(cleaned_amount))
}
Ok(cleaned_amount) => info!("Cleaned {}", format_bytes(cleaned_amount)),
Ok(cleaned_amount) => {
total_cleaned += cleaned_amount;
info!("Cleaned {}", format_bytes(cleaned_amount))
}
Err(e) => error!("Failed to clean {:?}: {:?}", project_path, e),
};
}
}

info!("Total amount: {}", format_bytes(total_cleaned));
}

Ok(())
Expand Down

0 comments on commit 4d0a722

Please sign in to comment.