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 85157e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 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
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn clean_and_parse(target: &TempDir, args: &[&str]) -> Result<u64> {
assert!(output.stderr.is_empty());
let amount = std::str::from_utf8(&output.stdout)?
.lines()
.last()
.nth_back(1)
.unwrap()
.split(clean_msg)
.nth(1)
Expand Down

0 comments on commit 85157e7

Please sign in to comment.