Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rust/src/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SYSROOT: &str = "sysroot";
const USR: &str = "usr";
const ETC: &str = "etc";
const USR_ETC: &str = "usr/etc";
const OCI_ARCHIVE_TRANSPORT: &str = "oci-archive";

#[derive(clap::ValueEnum, Clone, Debug)]
enum OutputFormat {
Expand Down Expand Up @@ -418,7 +419,7 @@ impl BuildChunkedOCIOpts {
/// Check if there's already an image at the target location and if it's chunked
fn check_existing_image(&self, output: &str) -> Result<Option<oci_spec::image::ImageManifest>> {
// Parse the output reference to determine transport and location
let (_transport, _location) = output
let (transport, _location) = output
.split_once(':')
.ok_or_else(|| anyhow::anyhow!("Invalid output format, expected TRANSPORT:TARGET"))?;

Expand All @@ -428,11 +429,13 @@ impl BuildChunkedOCIOpts {
// The proxy will use default authentication sources (e.g., $XDG_RUNTIME_DIR/containers/auth.json)
let proxy = containers_image_proxy::ImageProxy::new().await?;

// Try to open the image
let img = proxy.open_image_optional(output).await?;
let img = if transport == OCI_ARCHIVE_TRANSPORT {
(proxy.open_image(output).await).ok()
} else {
proxy.open_image_optional(output).await?
};
Comment on lines +432 to +436

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using .ok() here swallows errors from proxy.open_image().await, treating any failure as if the image does not exist. This could mask underlying issues such as permissions errors or invalid paths, leading to unexpected behavior.

It would be more robust to handle only the "not found" case as a non-error condition and propagate other errors. At a minimum, logging the discarded error at a debug level would aid in troubleshooting potential issues in the future.

            let img = if transport == OCI_ARCHIVE_TRANSPORT {
                match proxy.open_image(output).await {
                    Ok(img) => Some(img),
                    Err(e) => {
                        tracing::debug!("Ignoring error opening oci-archive: {e}");
                        None
                    }
                }
            } else {
                proxy.open_image_optional(output).await?
            };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this as a followup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a helper for this bootc-dev/bootc#1464


if let Some(opened_image) = img {
// Fetch the manifest
let (_, manifest) = proxy.fetch_manifest(&opened_image).await?;
anyhow::Ok(Some(manifest))
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/build-chunked-oci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,13 @@ else
fi

echo "ok exclusive layers functionality"

echo "Testing oci-archive output"
podman run --rm --privileged --security-opt=label=disable \
-v /var/lib/containers:/var/lib/containers \
-v /var/tmp:/var/tmp \
-v "$(pwd)":/output \
localhost/builder rpm-ostree compose build-chunked-oci --bootc --from localhost/base --output=oci-archive:/output/test-archive

test -f test-archive
echo "ok oci-archive output"
Loading