Skip to content

Commit 2df4be5

Browse files
committed
ostree-ext: Make new packing if using prior build fails
Under some circumstances--for example, if a new exclusive component has been added since the prior build--packing with a prior build structure can fail. When this happens, we can simply discard the prior build data and make a new packing structure, rather than having chunking fail entirely. Signed-off-by: Daniel Hast <hast.daniel@protonmail.com>
1 parent 5ec2c5c commit 2df4be5

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

crates/ostree-ext/src/chunking.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::container::{COMPONENT_SEPARATOR, CONTENT_ANNOTATION};
1414
use crate::objectsource::{ContentID, ObjectMeta, ObjectMetaMap, ObjectSourceMeta};
1515
use crate::objgv::*;
1616
use crate::statistics;
17-
use anyhow::{anyhow, Result};
17+
use anyhow::{anyhow, bail, Result};
1818
use camino::{Utf8Path, Utf8PathBuf};
1919
use containers_image_proxy::oci_spec;
2020
use 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

Comments
 (0)