@@ -14,7 +14,7 @@ use crate::container::{COMPONENT_SEPARATOR, CONTENT_ANNOTATION};
1414use crate :: objectsource:: { ContentID , ObjectMeta , ObjectMetaMap , ObjectSourceMeta } ;
1515use crate :: objgv:: * ;
1616use crate :: statistics;
17- use anyhow:: { anyhow, Result } ;
17+ use anyhow:: { anyhow, bail , Result } ;
1818use camino:: { Utf8Path , Utf8PathBuf } ;
1919use containers_image_proxy:: oci_spec;
2020use gvariant:: aligned_bytes:: TryAsAligned ;
@@ -612,7 +612,7 @@ fn basic_packing_with_prior_build<'a>(
612612) -> Result < Vec < Vec < & ' a ObjectSourceMetaSized > > > {
613613 let before_processing_pkgs_len = components. len ( ) ;
614614
615- tracing:: debug!( "Keeping old package structure" ) ;
615+ tracing:: debug!( "Attempting to use old package structure" ) ;
616616
617617 // The first layer is the ostree commit, which will always be different for different builds,
618618 // so we ignore it. For the remaining layers, extract the components/packages in each one.
@@ -634,6 +634,12 @@ fn basic_packing_with_prior_build<'a>(
634634 . collect ( ) ;
635635 let mut curr_build = curr_build?;
636636
637+ if let Ok ( bin_size) = usize:: try_from ( bin_size. get ( ) ) {
638+ if bin_size < curr_build. len ( ) {
639+ bail ! ( "bin_size = {bin_size} is too small to be compatible with the prior build." ) ;
640+ }
641+ }
642+
637643 // View the packages as unordered sets for lookups and differencing
638644 let prev_pkgs_set: BTreeSet < String > = curr_build
639645 . iter ( )
@@ -651,7 +657,7 @@ fn basic_packing_with_prior_build<'a>(
651657 last_bin. retain ( |name| !name. is_empty ( ) ) ;
652658 last_bin. extend ( added. into_iter ( ) . cloned ( ) ) ;
653659 } else {
654- panic ! ( "No empty last bin for added packages" ) ;
660+ bail ! ( "No empty last bin for added packages" ) ;
655661 }
656662
657663 // Handle removed packages
@@ -714,7 +720,18 @@ fn basic_packing<'a>(
714720
715721 // If we have a prior build, then use that
716722 if let Some ( prior_build) = prior_build_metadata {
717- return basic_packing_with_prior_build ( components, bin_size, prior_build) ;
723+ match basic_packing_with_prior_build ( components, bin_size, prior_build) {
724+ Ok ( packing) => {
725+ tracing:: debug!( "Keeping old package structure" ) ;
726+ return Ok ( packing) ;
727+ }
728+ Err ( err) => {
729+ tracing:: trace!( "Error in basic_packing_with_prior_build: {err:?}" ) ;
730+ tracing:: debug!(
731+ "Failed to use old package structure; discarding info from prior build."
732+ ) ;
733+ }
734+ }
718735 }
719736
720737 tracing:: debug!( "Creating new packing structure" ) ;
0 commit comments