Skip to content

Commit a100398

Browse files
authored
Merge pull request #986 from HuijingHei/add-versions
Add `versions` to `ContentMetadata`
2 parents 12c2362 + 5ad048c commit a100398

File tree

12 files changed

+310
-86
lines changed

12 files changed

+310
-86
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ rustix = { version = "1.0.8", features = ["process", "fs"] }
4646
serde = { version = "^1.0", features = ["derive"] }
4747
serde_json = "^1.0"
4848
tempfile = "^3.21"
49+
uapi-version = "0.4.0"
4950
widestring = "1.2.0"
5051
walkdir = "2.3.2"
5152
signal-hook-registry = "1.4.6"

src/blockdev.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn find_colocated_esps(devices: &Vec<String>) -> Result<Option<Vec<String>>>
6969
}
7070

7171
/// Find bios_boot partition on the same device
72+
#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))]
7273
pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
7374
const BIOS_BOOT_TYPE_GUID: &str = "21686148-6449-6E6F-744E-656564454649";
7475
let device_info = bootc_internal_blockdev::partitions_of(Utf8Path::new(device))?;
@@ -83,6 +84,7 @@ pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
8384
}
8485

8586
/// Find all bios_boot partitions on the devices
87+
#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))]
8688
pub fn find_colocated_bios_boot(devices: &Vec<String>) -> Result<Option<Vec<String>>> {
8789
// look for all bios_boot parts on those devices
8890
let mut bios_boots = Vec::new();

src/bootupd.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn get_static_config_meta() -> Result<ContentMetadata> {
145145
let self_meta = ContentMetadata {
146146
timestamp: self_bin_meta.modified()?.into(),
147147
version: crate_version!().into(),
148+
versions: None,
148149
};
149150
Ok(self_meta)
150151
}
@@ -154,7 +155,7 @@ type Components = BTreeMap<&'static str, Box<dyn Component>>;
154155
#[allow(clippy::box_default)]
155156
/// Return the set of known components; if `auto` is specified then the system
156157
/// filters to the target booted state.
157-
pub(crate) fn get_components_impl(auto: bool) -> Components {
158+
pub(crate) fn get_components_impl(_auto: bool) -> Components {
158159
let mut components = BTreeMap::new();
159160

160161
fn insert_component(components: &mut Components, component: Box<dyn Component>) {
@@ -163,7 +164,7 @@ pub(crate) fn get_components_impl(auto: bool) -> Components {
163164

164165
#[cfg(target_arch = "x86_64")]
165166
{
166-
if auto {
167+
if _auto {
167168
let is_efi_booted = crate::efi::is_efi_booted().unwrap();
168169
log::info!(
169170
"System boot method: {}",

src/component.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ pub(crate) fn query_adopt_state() -> Result<Option<Adoptable>> {
167167
let meta = ContentMetadata {
168168
timestamp: coreos_aleph.ts,
169169
version: coreos_aleph.aleph.version,
170+
versions: None,
170171
};
171172
log::trace!("Adoptable: {:?}", &meta);
172173
return Ok(Some(Adoptable {
@@ -183,6 +184,7 @@ pub(crate) fn query_adopt_state() -> Result<Option<Adoptable>> {
183184
let meta = ContentMetadata {
184185
timestamp,
185186
version: "unknown".to_string(),
187+
versions: None,
186188
};
187189
return Ok(Some(Adoptable {
188190
version: meta,

src/efi.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::model::*;
2828
use crate::ostreeutil;
2929
use crate::util;
3030
use crate::{blockdev, filetree, grubconfigs};
31-
use crate::{component::*, packagesystem};
31+
use crate::{component::*, packagesystem::*};
3232

3333
/// Well-known paths to the ESP that may have been mounted external to us.
3434
pub(crate) const ESP_MOUNTS: &[&str] = &["boot/efi", "efi", "boot"];
@@ -441,6 +441,7 @@ impl Component for Efi {
441441
let efilib_path = sysroot_path.join(EFILIB);
442442
let meta = if efilib_path.exists() {
443443
let mut packages = Vec::new();
444+
let mut modules_vec: Vec<Module> = vec![];
444445
let sysroot_dir = Dir::open_ambient_dir(sysroot_path, cap_std::ambient_authority())?;
445446
let efi_components = get_efi_component_from_usr(&sysroot_path, EFILIB)?;
446447
if efi_components.len() == 0 {
@@ -454,13 +455,19 @@ impl Component for Efi {
454455
.current_dir(format!("/proc/self/fd/{}", sysroot_dir.as_raw_fd()))
455456
.run()?;
456457
packages.push(format!("{}-{}", efi.name, efi.version));
458+
modules_vec.push(Module {
459+
name: efi.name,
460+
rpm_evr: efi.version,
461+
});
457462
}
463+
modules_vec.sort_unstable();
458464

459465
// change to now to workaround https://github.com/coreos/bootupd/issues/933
460466
let timestamp = std::time::SystemTime::now();
461467
ContentMetadata {
462468
timestamp: chrono::DateTime::<Utc>::from(timestamp),
463469
version: packages.join(","),
470+
versions: Some(modules_vec),
464471
}
465472
} else {
466473
let ostreebootdir = sysroot_path.join(ostreeutil::BOOT_PREFIX);
@@ -493,7 +500,7 @@ impl Component for Efi {
493500
f.insert_str(0, "/boot/efi/EFI/");
494501
f
495502
});
496-
packagesystem::query_files(sysroot, files)?
503+
query_files(sysroot, files)?
497504
} else {
498505
anyhow::bail!("Failed to find {ostreebootdir}");
499506
}
@@ -707,8 +714,8 @@ fn find_file_recursive<P: AsRef<Path>>(dir: P, target_file: &str) -> Result<Vec<
707714

708715
#[derive(Debug, PartialEq, Eq)]
709716
pub struct EFIComponent {
710-
name: String,
711-
version: String,
717+
pub name: String,
718+
pub version: String,
712719
path: Utf8PathBuf,
713720
}
714721

src/model.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use serde::{Deserialize, Serialize};
99
use std::cmp::Ordering;
1010
use std::collections::BTreeMap;
1111

12+
use crate::packagesystem::*;
13+
1214
/// The directory where updates are stored
1315
pub(crate) const BOOTUPD_UPDATES_DIR: &str = "usr/lib/bootupd/updates";
1416

@@ -19,11 +21,17 @@ pub(crate) struct ContentMetadata {
1921
pub(crate) timestamp: DateTime<Utc>,
2022
/// Human readable version number, like ostree it is not ever parsed, just displayed
2123
pub(crate) version: String,
24+
/// Transfer version into Module struct list
25+
pub(crate) versions: Option<Vec<Module>>,
2226
}
2327

2428
impl ContentMetadata {
2529
pub(crate) fn can_upgrade_to(&self, target: &Self) -> Ordering {
26-
crate::packagesystem::compare_package_versions(&self.version, &target.version)
30+
if let (Some(self_versions), Some(target_versions)) = (&self.versions, &target.versions) {
31+
compare_package_slices(self_versions, target_versions)
32+
} else {
33+
compare_package_versions(&self.version, &target.version)
34+
}
2735
}
2836
}
2937

@@ -128,10 +136,44 @@ mod test {
128136
let a = ContentMetadata {
129137
timestamp: t,
130138
version: "grub2-efi-ia32-1:2.12-21.fc41.x86_64,grub2-efi-x64-1:2.12-21.fc41.x86_64,shim-ia32-15.8-3.x86_64,shim-x64-15.8-3.x86_64".into(),
139+
versions: None,
131140
};
132141
let b = ContentMetadata {
133142
timestamp: t + Duration::try_seconds(1).unwrap(),
134143
version: "grub2-efi-ia32-1:2.12-28.fc41.x86_64,grub2-efi-x64-1:2.12-28.fc41.x86_64,shim-ia32-15.8-3.x86_64,shim-x64-15.8-3.x86_64".into(),
144+
versions: None,
145+
};
146+
assert_eq!(a.can_upgrade_to(&b), Ordering::Less); // means upgradable
147+
assert_eq!(b.can_upgrade_to(&a), Ordering::Greater);
148+
149+
// Compare versions if it is not none
150+
let a = ContentMetadata {
151+
timestamp: t,
152+
version: "test".into(),
153+
versions: Some(vec![
154+
Module {
155+
name: "grub2".into(),
156+
rpm_evr: "1:2.12-21.fc41".into(),
157+
},
158+
Module {
159+
name: "shim".into(),
160+
rpm_evr: "15.8-3".into(),
161+
},
162+
]),
163+
};
164+
let b = ContentMetadata {
165+
timestamp: t + Duration::try_seconds(1).unwrap(),
166+
version: "test".into(),
167+
versions: Some(vec![
168+
Module {
169+
name: "grub2".into(),
170+
rpm_evr: "1:2.12-28.fc41".into(),
171+
},
172+
Module {
173+
name: "shim".into(),
174+
rpm_evr: "15.8-3".into(),
175+
},
176+
]),
135177
};
136178
assert_eq!(a.can_upgrade_to(&b), Ordering::Less); // means upgradable
137179
assert_eq!(b.can_upgrade_to(&a), Ordering::Greater);
@@ -147,6 +189,26 @@ mod test {
147189
efi.meta.version,
148190
"grub2-efi-x64-1:2.04-23.fc32.x86_64,shim-x64-15-8.x86_64"
149191
);
192+
assert_eq!(efi.meta.versions, None);
193+
194+
// Test the new versions
195+
let data = include_str!("../tests/fixtures/example-state-versions-v0.json");
196+
let state: SavedState = serde_json::from_str(data)?;
197+
let efi = state.installed.get("EFI").expect("EFI");
198+
assert_eq!(efi.meta.version, "grub2-1:2.12-41.fc44,shim-15.8-4");
199+
assert_eq!(
200+
efi.meta.versions,
201+
Some(vec![
202+
Module {
203+
name: "grub2".into(),
204+
rpm_evr: "1:2.12-41.fc44".into(),
205+
},
206+
Module {
207+
name: "shim".into(),
208+
rpm_evr: "15.8-4".into(),
209+
},
210+
])
211+
);
150212
Ok(())
151213
}
152214

@@ -160,6 +222,7 @@ mod test {
160222
efi.installed.version,
161223
"grub2-efi-x64-1:2.04-23.fc32.x86_64,shim-x64-15-8.x86_64"
162224
);
225+
assert_eq!(efi.installed.versions, None);
163226
Ok(())
164227
}
165228
}

src/model_legacy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl ContentMetadata01 {
4949
NewContentMetadata {
5050
timestamp,
5151
version: self.version,
52+
versions: None,
5253
}
5354
}
5455
}

0 commit comments

Comments
 (0)