Skip to content

Commit c5a462b

Browse files
authored
Merge pull request #44 from dsteeley/ocispec_update
Updates for oci-spec 0.8.2
2 parents 5ffd1e7 + 0a06783 commit c5a462b

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "ocidir"
33
description = "A Rust library for reading and writing OCI (opencontainers) layout directories"
4-
version = "0.5.0"
5-
edition = "2021"
4+
version = "0.6.0"
5+
edition = "2024"
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/containers/ocidir-rs"
88
keywords = ["oci", "opencontainers", "docker", "podman", "containers"]

examples/custom_compressor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::{env, io, path::PathBuf};
44

55
use oci_spec::image::Platform;
6-
use ocidir::{cap_std::fs::Dir, BlobWriter, OciDir, WriteComplete};
6+
use ocidir::{BlobWriter, OciDir, WriteComplete, cap_std::fs::Dir};
77

88
struct NoCompression<'a>(BlobWriter<'a>);
99

examples/ocidir-import-tar.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ fn import(oci_dir: &OciDir, name: &str, src: File) -> anyhow::Result<()> {
4242
.created_by(name.to_string())
4343
.build()
4444
.unwrap();
45-
config.history_mut().push(h);
45+
match config.history_mut() {
46+
Some(v) => v.push(h),
47+
None => {
48+
config.set_history(Some(vec![h]));
49+
}
50+
}
4651

4752
println!(
4853
"Created image with manifest: {}",

src/lib.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};
1616
use std::collections::{HashMap, HashSet};
1717
use std::fmt::Debug;
1818
use std::fs::File;
19-
use std::io::{prelude::*, BufReader, BufWriter};
19+
use std::io::{BufReader, BufWriter, prelude::*};
2020
use std::marker::PhantomData;
2121
use std::path::{Path, PathBuf};
2222
use std::str::FromStr;
@@ -287,7 +287,7 @@ impl OciDir {
287287
}
288288

289289
/// Create a blob (can be anything).
290-
pub fn create_blob(&self) -> Result<BlobWriter> {
290+
pub fn create_blob(&self) -> Result<BlobWriter<'_>> {
291291
BlobWriter::new(&self.dir)
292292
}
293293

@@ -314,9 +314,9 @@ impl OciDir {
314314

315315
/// Create a tar output stream, backed by a blob
316316
pub fn create_layer(
317-
&self,
317+
&'_ self,
318318
c: Option<flate2::Compression>,
319-
) -> Result<tar::Builder<LayerWriter<GzEncoder<BlobWriter>>>> {
319+
) -> Result<tar::Builder<LayerWriter<'_, GzEncoder<BlobWriter<'_>>>>> {
320320
Ok(tar::Builder::new(self.create_gzip_layer(c)?))
321321
}
322322

@@ -429,7 +429,12 @@ impl OciDir {
429429
} else {
430430
oci_image::HistoryBuilder::default().build().unwrap()
431431
};
432-
config.history_mut().push(history);
432+
match config.history_mut() {
433+
Some(h) => h.push(history),
434+
None => {
435+
config.set_history(Some(vec![history]));
436+
}
437+
}
433438
}
434439

435440
/// Add a layer to the top of the image stack with desired history entry.
@@ -642,7 +647,7 @@ impl OciDir {
642647
media_type => {
643648
return Err(Error::UnexpectedMediaType {
644649
media_type: media_type.clone(),
645-
})
650+
});
646651
}
647652
}
648653
validated.insert(config_digest.into());
@@ -915,13 +920,14 @@ mod tests {
915920
assert!(w.has_blob(&root_layer_desc).unwrap());
916921

917922
// Check that we don't find nonexistent blobs
918-
assert!(!w
919-
.has_blob(&Descriptor::new(
923+
assert!(
924+
!w.has_blob(&Descriptor::new(
920925
MediaType::ImageLayerGzip,
921926
root_layer.blob.size,
922927
root_layer.uncompressed_sha256.clone()
923928
))
924-
.unwrap());
929+
.unwrap()
930+
);
925931

926932
let mut manifest = w.new_empty_manifest()?.build()?;
927933
let mut config = oci_image::ImageConfigurationBuilder::default()
@@ -930,7 +936,7 @@ mod tests {
930936
let annotations: Option<HashMap<String, String>> = None;
931937
w.push_layer(&mut manifest, &mut config, root_layer, "root", annotations);
932938
{
933-
let history = config.history().first().unwrap();
939+
let history = config.history().as_ref().unwrap().first().unwrap();
934940
assert_eq!(history.created_by().as_ref().unwrap(), "root");
935941
let created = history.created().as_deref().unwrap();
936942
let ts = chrono::DateTime::parse_from_rfc3339(created)
@@ -1077,7 +1083,7 @@ mod tests {
10771083
.unwrap();
10781084
w.push_layer_with_history(&mut manifest, &mut config, root_layer, Some(history));
10791085
{
1080-
let history = config.history().first().unwrap();
1086+
let history = config.history().as_ref().unwrap().first().unwrap();
10811087
assert_eq!(history.created_by().as_deref().unwrap(), "/bin/pretend-tar");
10821088
assert_eq!(history.created().as_ref(), None);
10831089
}

0 commit comments

Comments
 (0)