Skip to content

Commit dd3bbf8

Browse files
Handle older systemd-repart without partno output in JSON
Older systemd-repart versions (ex. the one in c9s) do not include the partno field in the JSON output. Make the field optional and fall back to the array index when absent Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 2fe4924 commit dd3bbf8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

crates/lib/src/install/baseline.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ struct RepartPartition {
210210
#[serde(rename = "type")]
211211
partition_type: String,
212212
/// 0-indexed partition number
213-
partno: u32,
213+
/// absent in older systemd-repart
214+
/// versions, in c9s
215+
#[serde(default)]
216+
partno: Option<u32>,
214217
#[allow(dead_code)]
215218
fs: Option<String>,
216219
}
@@ -338,9 +341,11 @@ fn parse_repart_layout(partitions: &[RepartPartition]) -> Result<PartitionLayout
338341
let mut boot_partno = None;
339342
let mut rootpn = None;
340343

341-
for part in partitions {
344+
for (idx, part) in partitions.iter().enumerate() {
342345
// repart partno is 0-indexed, lsblk/sfdisk use 1-indexed
343-
let partno = part.partno + 1;
346+
// Fall back to array indexing for older systemd-repart without partno
347+
// like the version in c9s
348+
let partno = part.partno.unwrap_or(idx as u32) + 1;
344349

345350
match part.partition_type.as_str() {
346351
"esp" => esp_partno = Some(partno),

0 commit comments

Comments
 (0)