Skip to content

Commit e50f288

Browse files
committed
Copy unmanaged BLS entries to staging dir on upgrade
1 parent f48158e commit e50f288

1 file changed

Lines changed: 65 additions & 2 deletions

File tree

crates/lib/src/bootc_composefs/backwards_compat/bcompat_boot.rs

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use crate::{
1313
},
1414
},
1515
composefs_consts::{
16-
ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX,
17-
TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED,
16+
BLS_ENTRY_PREFIX, ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX, TYPE1_ENT_PATH, TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED
1817
},
1918
parsers::bls_config::{BLSConfig, BLSConfigType},
2019
spec::Bootloader,
@@ -240,6 +239,15 @@ fn create_staged_bls_entries(boot_dir: &Dir, entries: &Vec<(String, BLSConfig)>)
240239
staged_entries.atomic_write(filename, new_entry.to_string().as_bytes())?;
241240
}
242241

242+
let original_entries = boot_dir.open_dir(TYPE1_ENT_PATH)?;
243+
for entry in original_entries.entries()? {
244+
let entry = entry?;
245+
let entry_name = entry.file_name();
246+
if entry.file_type()?.is_file() && !entry_name.to_string_lossy().starts_with(BLS_ENTRY_PREFIX) {
247+
original_entries.copy(entry.file_name(), &staged_entries, entry_name)?;
248+
}
249+
}
250+
243251
fsync(staged_entries.reopen_as_ownedfd()?).context("fsync")
244252
}
245253

@@ -394,3 +402,58 @@ pub(crate) async fn prepend_custom_prefix(
394402

395403
Ok(())
396404
}
405+
406+
#[cfg(test)]
407+
mod tests {
408+
use anyhow::Result;
409+
use cap_std_ext::{cap_std, dirext::CapStdExtDirExt};
410+
use crate::bootc_composefs::backwards_compat::bcompat_boot::*;
411+
use crate::parsers::bls_config::parse_bls_config;
412+
413+
#[test]
414+
fn test_create_staged_bls_entries() -> Result<()> {
415+
let tempdir = cap_std_ext::cap_tempfile::tempdir(cap_std::ambient_authority())?;
416+
417+
let entry1 = r#"
418+
title Fedora 42.20250623.3.1 (CoreOS)
419+
version fedora-42.0
420+
sort-key 1
421+
linux /boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/vmlinuz-5.14.10
422+
initrd /boot/7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6/initramfs-5.14.10.img
423+
options root=UUID=abc123 rw composefs=7e11ac46e3e022053e7226a20104ac656bf72d1a84e3a398b7cce70e9df188b6
424+
"#;
425+
let entry2 = r#"
426+
title Fedora 41.20250214.2.0 (CoreOS)
427+
version fedora-42.0
428+
sort-key 2
429+
efi /EFI/Linux/f7415d75017a12a387a39d2281e033a288fc15775108250ef70a01dcadb93346.efi
430+
options root=UUID=abc123 rw composefs=febdf62805de2ae7b6b597f2a9775d9c8a753ba1e5f09298fc8fbe0b0d13bf01
431+
"#;
432+
let entry3 = r#"
433+
title Test
434+
version 1
435+
sort-key 9
436+
efi /EFI/boot/test.efi
437+
"#;
438+
439+
tempdir.create_dir_all("loader/entries")?;
440+
tempdir.atomic_write("loader/entries/bootc_entry1.conf", entry1)?;
441+
tempdir.atomic_write("loader/entries/bootc_entry2.conf", entry2)?;
442+
tempdir.atomic_write("loader/entries/entry3.conf", entry3)?;
443+
444+
let entries = vec![
445+
("bootc_entry1.conf".to_string(), parse_bls_config(entry1).unwrap()),
446+
("bootc_entry2.conf".to_string(), parse_bls_config(entry2).unwrap()),
447+
];
448+
449+
create_staged_bls_entries(&tempdir, &entries).unwrap();
450+
451+
assert!(tempdir.exists("loader/entries.staged/bootc_entry1.conf"));
452+
assert!(tempdir.exists("loader/entries.staged/bootc_entry2.conf"));
453+
assert!(tempdir.exists("loader/entries.staged/entry3.conf"));
454+
455+
assert_eq!(str::from_utf8(&tempdir.read("loader/entries.staged/entry3.conf")?[..])?, entry3);
456+
457+
Ok(())
458+
}
459+
}

0 commit comments

Comments
 (0)