Gather all bound images in all deployments, then prune the image store, using the gathered images as the roots (that will not be GC'd).
(sysroot: &Storage)
| 396 | /// Gather all bound images in all deployments, then prune the image store, |
| 397 | /// using the gathered images as the roots (that will not be GC'd). |
| 398 | pub(crate) async fn prune_container_store(sysroot: &Storage) -> Result<()> { |
| 399 | let ostree = sysroot.get_ostree()?; |
| 400 | let deployments = ostree.deployments(); |
| 401 | let mut all_bound_images = Vec::new(); |
| 402 | for deployment in deployments { |
| 403 | let bound = crate::boundimage::query_bound_images_for_deployment(ostree, &deployment)?; |
| 404 | all_bound_images.extend(bound.into_iter()); |
| 405 | // Also include the host image itself |
| 406 | // Note: Use just the image name (not the full transport:image format) because |
| 407 | // podman's image names don't include the transport prefix. |
| 408 | if let Some(host_image) = crate::status::boot_entry_from_deployment(ostree, &deployment)? |
| 409 | .image |
| 410 | .map(|i| i.image) |
| 411 | { |
| 412 | all_bound_images.push(crate::boundimage::BoundImage { |
| 413 | image: host_image.image.clone(), |
| 414 | auth_file: None, |
| 415 | }); |
| 416 | } |
| 417 | } |
| 418 | // Convert to a hashset of just the image names |
| 419 | let image_names = HashSet::from_iter(all_bound_images.iter().map(|img| img.image.as_str())); |
| 420 | let pruned = sysroot |
| 421 | .get_ensure_imgstore()? |
| 422 | .prune_except_roots(&image_names) |
| 423 | .await?; |
| 424 | tracing::debug!("Pruned images: {}", pruned.len()); |
| 425 | Ok(()) |
| 426 | } |
| 427 | |
| 428 | /// Core disk space check: verify that `bytes_to_fetch` fits within available space, |
| 429 | /// leaving at least `min_free` bytes reserved. |
no test coverage detected