diff --git a/lib/Cargo.toml b/lib/Cargo.toml index a9a2d829..ef6f5e42 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -12,7 +12,7 @@ rust-version = "1.74.0" [dependencies] anyhow = "1.0" containers-image-proxy = "0.5.5" -async-compression = { version = "0.4", features = ["gzip", "tokio"] } +async-compression = { version = "0.4", features = ["gzip", "tokio", "zstd"] } camino = "1.0.4" chrono = "0.4.19" olpc-cjson = "0.1.1" diff --git a/lib/src/container/unencapsulate.rs b/lib/src/container/unencapsulate.rs index 11f56c0f..b6efb8d8 100644 --- a/lib/src/container/unencapsulate.rs +++ b/lib/src/container/unencapsulate.rs @@ -198,6 +198,9 @@ fn new_async_decompressor<'a>( oci_image::MediaType::ImageLayerGzip => Ok(Box::new(tokio::io::BufReader::new( async_compression::tokio::bufread::GzipDecoder::new(src), ))), + oci_image::MediaType::ImageLayerZstd => Ok(Box::new(tokio::io::BufReader::new( + async_compression::tokio::bufread::ZstdDecoder::new(src), + ))), oci_image::MediaType::ImageLayer => Ok(Box::new(src)), oci_image::MediaType::Other(t) if t.as_str() == DOCKER_TYPE_LAYER_TAR => Ok(Box::new(src)), o => Err(anyhow::anyhow!("Unhandled layer type: {}", o)), diff --git a/lib/tests/it/main.rs b/lib/tests/it/main.rs index cfd1f271..464cab36 100644 --- a/lib/tests/it/main.rs +++ b/lib/tests/it/main.rs @@ -1261,6 +1261,47 @@ async fn test_container_write_derive() -> Result<()> { Ok(()) } +/// Test for zstd +/// We need to handle the case of modified hardlinks into /sysroot +#[tokio::test] +async fn test_container_zstd() -> Result<()> { + let fixture = Fixture::new_v1()?; + let baseimg = &fixture.export_container().await?.0; + let basepath = &match baseimg.transport { + Transport::OciDir => fixture.path.join(baseimg.name.as_str()), + _ => unreachable!(), + }; + let baseimg_ref = format!("oci:{basepath}"); + let zstd_image_path = &fixture.path.join("zstd.oci"); + let st = tokio::process::Command::new("skopeo") + .args([ + "copy", + "--dest-compress-format=zstd", + baseimg_ref.as_str(), + &format!("oci:{zstd_image_path}"), + ]) + .status() + .await?; + assert!(st.success()); + + let zstdref = &OstreeImageReference { + sigverify: SignatureSource::ContainerPolicyAllowInsecure, + imgref: ImageReference { + transport: Transport::OciDir, + name: zstd_image_path.to_string(), + }, + }; + let mut imp = + store::ImageImporter::new(fixture.destrepo(), zstdref, Default::default()).await?; + let prep = match imp.prepare().await.context("Init prep derived")? { + store::PrepareResult::AlreadyPresent(_) => panic!("should not be already imported"), + store::PrepareResult::Ready(r) => r, + }; + let _ = imp.import(prep).await.unwrap(); + + Ok(()) +} + /// Test for https://github.com/ostreedev/ostree-rs-ext/issues/405 /// We need to handle the case of modified hardlinks into /sysroot #[tokio::test]