@@ -192,6 +192,11 @@ fn unreferenced_boot_binaries<'a>(
192192 . collect ( )
193193}
194194
195+ pub ( crate ) struct GCOpts {
196+ pub ( crate ) dry_run : bool ,
197+ pub ( crate ) prune_repo : bool ,
198+ }
199+
195200/// 1. List all bootloader entries
196201/// 2. List all EROFS images
197202/// 3. List all state directories
@@ -212,8 +217,7 @@ fn unreferenced_boot_binaries<'a>(
212217pub ( crate ) async fn composefs_gc (
213218 storage : & Storage ,
214219 booted_cfs : & BootedComposefs ,
215- dry_run : bool ,
216- prune_repo : bool ,
220+ gc_opts : GCOpts ,
217221) -> Result < GcResult > {
218222 const COMPOSEFS_GC_JOURNAL_ID : & str = "3b2a1f0e9d8c7b6a5f4e3d2c1b0a9f8e7" ;
219223
@@ -284,12 +288,14 @@ pub(crate) async fn composefs_gc(
284288
285289 for ( ty, verity) in unreferenced_boot_binaries {
286290 match ty {
287- BootType :: Bls => delete_kernel_initrd ( storage, & get_type1_dir_name ( verity) , dry_run) ?,
288- BootType :: Uki => delete_uki ( storage, verity, dry_run) ?,
291+ BootType :: Bls => {
292+ delete_kernel_initrd ( storage, & get_type1_dir_name ( verity) , gc_opts. dry_run ) ?
293+ }
294+ BootType :: Uki => delete_uki ( storage, verity, gc_opts. dry_run ) ?,
289295 }
290296 }
291297
292- if !prune_repo {
298+ if !gc_opts . prune_repo {
293299 return Ok ( GcResult :: default ( ) ) ;
294300 }
295301
@@ -329,13 +335,13 @@ pub(crate) async fn composefs_gc(
329335
330336 for verity in & orphaned_state_dirs {
331337 tracing:: debug!( "Cleaning up orphaned state dir: {verity}" ) ;
332- delete_staged ( staged, & all_orphans, dry_run) ?;
333- delete_state_dir ( & sysroot, verity, dry_run) ?;
338+ delete_staged ( staged, & all_orphans, gc_opts . dry_run ) ?;
339+ delete_state_dir ( & sysroot, verity, gc_opts . dry_run ) ?;
334340 }
335341
336342 for verity in & orphaned_boot_entries {
337343 tracing:: debug!( "Cleaning up orphaned bootloader entry: {verity}" ) ;
338- delete_staged ( staged, & all_orphans, dry_run) ?;
344+ delete_staged ( staged, & all_orphans, gc_opts . dry_run ) ?;
339345 }
340346
341347 // Collect the set of manifest digests referenced by live deployments,
@@ -431,7 +437,7 @@ pub(crate) async fn composefs_gc(
431437 . any ( |( tag_name, _) | tag_name == & expected_tag) ;
432438 if !has_tag {
433439 tracing:: info!( "Creating missing bootc tag for live deployment: {expected_tag}" ) ;
434- if !dry_run {
440+ if !gc_opts . dry_run {
435441 composefs_oci:: tag_image ( & * booted_cfs. repo , manifest_digest, & expected_tag)
436442 . with_context ( || format ! ( "Creating migration tag {expected_tag}" ) ) ?;
437443 }
@@ -450,7 +456,7 @@ pub(crate) async fn composefs_gc(
450456
451457 if !live_manifest_digests. iter ( ) . any ( |d| d == manifest_digest) {
452458 tracing:: debug!( "Removing unreferenced bootc tag: {tag_name}" ) ;
453- if !dry_run {
459+ if !gc_opts . dry_run {
454460 composefs_oci:: untag_image ( & * booted_cfs. repo , tag_name)
455461 . with_context ( || format ! ( "Removing tag {tag_name}" ) ) ?;
456462 }
@@ -463,7 +469,7 @@ pub(crate) async fn composefs_gc(
463469 . collect :: < Vec < _ > > ( ) ;
464470
465471 // Prune containers-storage: remove images not backing any live deployment.
466- if !dry_run && !live_container_images. is_empty ( ) {
472+ if !gc_opts . dry_run && !live_container_images. is_empty ( ) {
467473 let subpath = crate :: podstorage:: CStorage :: subpath ( ) ;
468474 if sysroot. try_exists ( & subpath) . unwrap_or ( false ) {
469475 let run = Dir :: open_ambient_dir ( "/run" , cap_std_ext:: cap_std:: ambient_authority ( ) ) ?;
@@ -482,7 +488,7 @@ pub(crate) async fn composefs_gc(
482488 // images for deployments that predate the manifest→image link;
483489 // once all deployments have been pulled with the new code, these
484490 // become redundant.
485- let gc_result = if dry_run {
491+ let gc_result = if gc_opts . dry_run {
486492 booted_cfs. repo . gc_dry_run ( & additional_roots) ?
487493 } else {
488494 booted_cfs. repo . gc ( & additional_roots) ?
0 commit comments