Skip to content

Commit

Permalink
Use find_manifest_descriptor_with_tag from ocidir-rs
Browse files Browse the repository at this point in the history
Now that [1] was merged, we can use find_manifest_descriptor_with_tag
and remove copy-pasted code from ocidir-rs.

[1] containers/ocidir-rs#28

Signed-off-by: Ariel Miculas-Trif <amiculas@cisco.com>
  • Loading branch information
ariel-miculas committed Oct 14, 2024
1 parent 0b5a961 commit 0e4e627
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions puzzlefs-lib/src/oci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use std::str::FromStr;
use std::io::Cursor;

pub mod media_types;
const OCI_TAG_ANNOTATION: &str = "org.opencontainers.image.ref.name";

pub struct Image(pub OciDir);

Expand Down Expand Up @@ -204,21 +203,10 @@ impl Image {
Ok(file)
}

// TODO: export this function from ocidr / find another way to avoid code duplication
fn descriptor_is_tagged(d: &Descriptor, tag: &str) -> bool {
d.annotations()
.as_ref()
.and_then(|annos| annos.get(OCI_TAG_ANNOTATION))
.filter(|tagval| tagval.as_str() == tag)
.is_some()
}

pub fn get_image_manifest_fd(&self, tag: &str) -> Result<cap_std::fs::File> {
let index = self.get_index()?;
let image_manifest = index
.manifests()
.iter()
.find(|desc| Self::descriptor_is_tagged(desc, tag))
let image_manifest = self
.0
.find_manifest_descriptor_with_tag(tag)?
.ok_or_else(|| {
WireFormatError::MissingManifest(tag.to_string(), Backtrace::capture())
})?;
Expand Down

0 comments on commit 0e4e627

Please sign in to comment.