prune,docs: group the prune report by kind with sizes

The prune output spammed one line per path. The report now groups
entries by artifact kind with their total size, and the size is
measured before removal whatever the mode, so --dry-run prints a
digest ("24 residual build directories for 1.2 GiB") and both modes
end with the freed total. The size walk never crosses a mount point:
residual chroots hold bind-mounted /proc trees whose virtual files
(/proc/kcore alone reports 128 TiB) would poison the total.

--all is also honest now: it removes recent build records and staged
trees (that is where the space is), and the flag description says so.
One behavior fix rides along: a record or lock a live build holds was
previously prunable with --all, which would wreck a running build;
held locks are now out of bounds whatever the policy.
This commit is contained in:
vhaudiquet committed 2026-10-02 23:22:14 +02:00
1 parent 8485e7272b
commit 2991237c91
3 files changed
+327 -60

No files matched your search

+16 -21
View File
@@ -549,7 +549,8 @@ fn main() {
clap::Arg::new("all")
.long("all")
.action(clap::ArgAction::SetTrue)
.help("Also remove cached chroot tarballs (expensive to re-download)"),
.help("Remove everything, including recent build records and staged trees")
.long_help("Remove everything, whatever its age: recent build records and their staged trees (the incremental bases `pkh deb --incremental` forks) included, plus the cached chroot tarballs, which are expensive to re-download. Records and locks a live build holds are never touched."),
)
)
.get_matches();
@@ -1208,33 +1209,27 @@ fn main() {
if report.is_empty() {
info!("Nothing to prune.");
} else {
let action = if report.dry_run {
"Would remove"
if report.dry_run {
info!("Dry run - would remove:");
} else {
"Removed"
};
for path in &report.removed {
info!("{} {}", action, path.display());
info!("Removing:");
}
for group in &report.groups {
let size = if group.bytes > 0 {
format!(" for {}", pkh::prune::format_bytes(group.bytes))
} else {
String::new()
};
info!("{} {}{size}", group.count, group.label());
}
for (path, err) in &report.failed {
error!("Failed to remove {}: {}", path.display(), err);
}
let total = pkh::prune::format_bytes(report.total_bytes);
if report.dry_run {
info!(
"(dry run) {} item(s) would be removed.",
report.removed.len()
);
info!("Would have freed {total} total.");
} else {
info!(
"Pruned {} item(s){} ({} failure(s)).",
report.removed.len(),
if all {
" including cached chroot tarballs"
} else {
""
},
report.failed.len()
);
info!("Freed {total} total.");
}
}
if !report.failed.is_empty() {