Skip to content

Commit eab5e55

Browse files
committed
check the layer media type before flashing
To avoid flashing non disk layers we need to check the media type Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com> Assisted-by: claude-sonnet-4.6
1 parent 60e5a9b commit eab5e55

1 file changed

Lines changed: 30 additions & 7 deletions

File tree

src/fls/oci/manifest.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ pub struct ImageManifest {
6464
#[serde(default)]
6565
pub media_type: Option<String>,
6666

67+
/// Artifact type (OCI v1.1) - indicates the primary content type
68+
#[serde(default)]
69+
pub artifact_type: Option<String>,
70+
6771
/// Config blob descriptor
6872
pub config: Descriptor,
6973

@@ -135,14 +139,33 @@ impl Manifest {
135139
match self {
136140
Manifest::Image(ref m) => {
137141
if m.layers.is_empty() {
138-
Err("Manifest has no layers".to_string())
139-
} else if m.layers.len() > 1 {
140-
// For multi-layer images, we take the last layer
141-
// which typically contains the actual content
142-
Ok(m.layers.last().unwrap())
143-
} else {
144-
Ok(&m.layers[0])
142+
return Err("Manifest has no layers".to_string());
143+
}
144+
145+
if m.layers.len() == 1 {
146+
return Ok(&m.layers[0]);
145147
}
148+
149+
// If artifactType is set, find the layer matching it
150+
if let Some(ref artifact_type) = m.artifact_type {
151+
if let Some(layer) = m.layers.iter().find(|l| l.media_type == *artifact_type) {
152+
return Ok(layer);
153+
}
154+
}
155+
156+
// Fall back to the first disk image layer
157+
if let Some(layer) = m
158+
.layers
159+
.iter()
160+
.find(|l| l.media_type.starts_with("application/vnd.automotive.disk"))
161+
{
162+
return Ok(layer);
163+
}
164+
165+
Err(format!(
166+
"No disk image layer found among {} layers",
167+
m.layers.len()
168+
))
146169
}
147170
Manifest::Index(_) => Err(
148171
"Cannot get layer from manifest index - need to resolve platform first".to_string(),

0 commit comments

Comments
 (0)