Add local CAS cleanup policy

This commit is contained in:
Eric Wendland 2026-05-16 21:10:25 +02:00
commit 21920b51b5
10 changed files with 184 additions and 8 deletions

View file

@ -185,6 +185,10 @@ pub enum CasCommand {
Unpin {
hash: String,
},
Cleanup {
#[arg(long)]
dry_run: bool,
},
List,
}
@ -400,6 +404,7 @@ fn request_for_command(command: Command) -> Result<ControlRequest> {
CasCommand::Has { hash } => ControlRequest::CasHas { hash: hash.into() },
CasCommand::Pin { hash } => ControlRequest::CasPin { hash: hash.into() },
CasCommand::Unpin { hash } => ControlRequest::CasUnpin { hash: hash.into() },
CasCommand::Cleanup { dry_run } => ControlRequest::CasCleanup { dry_run },
CasCommand::List => ControlRequest::CasList,
},
Command::Kv { command } => ControlRequest::ModuleStub {
@ -596,6 +601,21 @@ fn print_response(response: ControlResponse, json: bool) -> Result<()> {
ControlResponse::CasPinned { hash, pinned } => {
println!("{hash}: pinned={pinned}");
}
ControlResponse::CasCleanup {
removed,
retained_pinned,
dry_run,
} => {
let action = if dry_run { "would remove" } else { "removed" };
println!("{action}: {}", removed.len());
for hash in removed {
println!(" {hash}");
}
println!("retained_pinned: {}", retained_pinned.len());
for hash in retained_pinned {
println!(" {hash}");
}
}
ControlResponse::CasList { blobs } => {
for blob in blobs {
let pin = if blob.pinned { "pinned" } else { "unpinned" };