Skip to content

Commit aacbb09

Browse files
committed
efi: update validate() according to the split change
1 parent 45dcab6 commit aacbb09

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/efi.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,7 @@ pub(crate) struct Efi {
6161
}
6262

6363
impl Efi {
64-
fn esp_path(&self) -> Result<PathBuf> {
65-
self.ensure_mounted_esp(Path::new("/"))
66-
.map(|v| v.join("EFI"))
67-
}
68-
69-
fn open_esp_optional(&self) -> Result<Option<openat::Dir>> {
70-
if !is_efi_booted()? && self.get_esp_device().is_none() {
71-
log::debug!("Skip EFI");
72-
return Ok(None);
73-
}
74-
let sysroot = openat::Dir::open("/")?;
75-
let esp = sysroot.sub_dir_optional(&self.esp_path()?)?;
76-
Ok(esp)
77-
}
78-
79-
fn open_esp(&self) -> Result<openat::Dir> {
80-
self.ensure_mounted_esp(Path::new("/"))?;
81-
let sysroot = openat::Dir::open("/")?;
82-
let esp = sysroot.sub_dir(&self.esp_path()?)?;
83-
Ok(esp)
84-
}
85-
64+
// Get esp device via EFI partlabel
8665
fn get_esp_device(&self) -> Option<PathBuf> {
8766
let esp_devices = [COREOS_ESP_PART_LABEL, ANACONDA_ESP_PART_LABEL]
8867
.into_iter()
@@ -452,15 +431,33 @@ impl Component for Efi {
452431
}
453432

454433
fn validate(&self, current: &InstalledContent) -> Result<ValidationResult> {
455-
if !is_efi_booted()? && self.get_esp_device().is_none() {
434+
let devices = crate::blockdev::get_devices("/").context("get parent devices")?;
435+
let esp_devices = blockdev::find_colocated_esps(&devices)?;
436+
if !is_efi_booted()? && esp_devices.is_none() {
456437
return Ok(ValidationResult::Skip);
457438
}
458439
let currentf = current
459440
.filetree
460441
.as_ref()
461442
.ok_or_else(|| anyhow::anyhow!("No filetree for installed EFI found!"))?;
462-
self.ensure_mounted_esp(Path::new("/"))?;
463-
let efidir = self.open_esp()?;
443+
444+
// Confirm that esp_devices is Some(value)
445+
let esp_devices = esp_devices.unwrap();
446+
let mut devices = esp_devices.iter();
447+
let Some(esp) = devices.next() else {
448+
anyhow::bail!("Failed to find esp device");
449+
};
450+
451+
if let Some(next_esp) = devices.next() {
452+
anyhow::bail!(
453+
"Found multiple esp devices {esp} and {next_esp}; not currently supported"
454+
);
455+
}
456+
let destpath = &self.ensure_mounted_esp(Path::new("/"), Path::new(&esp))?;
457+
458+
let efidir = &openat::Dir::open(&destpath.join("EFI"))
459+
.with_context(|| format!("opening EFI dir {}", destpath.display()))?;
460+
464461
let diff = currentf.relative_diff_to(&efidir)?;
465462
let mut errs = Vec::new();
466463
for f in diff.changes.iter() {

0 commit comments

Comments
 (0)