Skip to content

Commit 4449ca1

Browse files
committed
install: only preserve loader directory on ostree
On none ostree OS, the loader is directory that needs to be removed. Signed-off-by: Huijing Hei <[email protected]>
1 parent d8217cd commit 4449ca1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

crates/lib/src/install.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ fn remove_all_in_dir_no_xdev(d: &Dir, mount_err: bool) -> Result<()> {
18891889
}
18901890

18911891
#[context("Removing boot directory content except loader dir")]
1892-
fn remove_all_except_loader_dirs(bootdir: &Dir) -> Result<()> {
1892+
fn remove_all_except_loader_dirs(bootdir: &Dir, is_ostree: bool) -> Result<()> {
18931893
let entries = bootdir
18941894
.entries()
18951895
.context("Reading boot directory entries")?;
@@ -1903,13 +1903,14 @@ fn remove_all_except_loader_dirs(bootdir: &Dir) -> Result<()> {
19031903
anyhow::bail!("Invalid non-UTF8 filename: {file_name:?} in /boot");
19041904
};
19051905

1906-
// Skip any entry that starts with a protected prefix,
1907-
// as we also need to protect loader.0 or loader.1
1908-
if file_name.starts_with("loader") {
1909-
continue;
1906+
let etype = entry.file_type()?;
1907+
// Only preserve loader directory on ostree
1908+
if is_ostree {
1909+
if file_name.starts_with("loader") {
1910+
continue;
1911+
}
19101912
}
19111913

1912-
let etype = entry.file_type()?;
19131914
if etype == FileType::dir() {
19141915
// Open the directory and remove its contents
19151916
if let Some(subdir) = bootdir.open_dir_noxdev(&file_name)? {
@@ -1926,12 +1927,13 @@ fn remove_all_except_loader_dirs(bootdir: &Dir) -> Result<()> {
19261927
}
19271928

19281929
#[context("Removing boot directory content")]
1929-
fn clean_boot_directories(rootfs: &Dir) -> Result<()> {
1930+
fn clean_boot_directories(rootfs: &Dir, is_ostree: bool) -> Result<()> {
19301931
let bootdir =
19311932
crate::utils::open_dir_remount_rw(rootfs, BOOT.into()).context("Opening /boot")?;
19321933

19331934
// This should not remove /boot/efi note.
1934-
remove_all_except_loader_dirs(&bootdir).context("Emptying /boot but preserve loader")?;
1935+
remove_all_except_loader_dirs(&bootdir, is_ostree)
1936+
.context("Emptying /boot but preserve loader")?;
19351937

19361938
// TODO: Discover the ESP the same way bootupd does it; we should also
19371939
// support not wiping the ESP.
@@ -2145,7 +2147,9 @@ pub(crate) async fn install_to_filesystem(
21452147
tokio::task::spawn_blocking(move || remove_all_in_dir_no_xdev(&rootfs_fd, true))
21462148
.await??;
21472149
}
2148-
Some(ReplaceMode::Alongside) => clean_boot_directories(&target_rootfs_fd)?,
2150+
Some(ReplaceMode::Alongside) => {
2151+
clean_boot_directories(&target_rootfs_fd, is_already_ostree)?
2152+
}
21492153
None => require_empty_rootdir(&rootfs_fd)?,
21502154
}
21512155

0 commit comments

Comments
 (0)