Skip to content

Commit 432d56e

Browse files
committed
grubconfigs: cleanup install()
Instead of joining and spliting paths (with an unwrap), open the grub2 directory and use that directly.
1 parent b525379 commit 432d56e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/grubconfigs.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ pub(crate) fn install(
6060
println!("Added {name}");
6161
}
6262

63-
bootdir
64-
.write_file_contents(format!("{GRUB2DIR}/grub.cfg"), 0o644, config.as_bytes())
63+
let grub2dir = bootdir.sub_dir(GRUB2DIR)?;
64+
grub2dir
65+
.write_file_contents("grub.cfg", 0o644, config.as_bytes())
6566
.context("Copying grub-static.cfg")?;
6667
println!("Installed: grub.cfg");
6768

@@ -74,10 +75,11 @@ pub(crate) fn install(
7475
.uuid
7576
.ok_or_else(|| anyhow::anyhow!("Failed to find UUID for boot"))?;
7677
let grub2_uuid_contents = format!("set BOOT_UUID=\"{bootfs_uuid}\"\n");
77-
let uuid_path = format!("{GRUB2DIR}/bootuuid.cfg");
78-
bootdir
79-
.write_file_contents(&uuid_path, 0o644, grub2_uuid_contents)
78+
let uuid_path = "bootuuid.cfg";
79+
grub2dir
80+
.write_file_contents(uuid_path, 0o644, grub2_uuid_contents)
8081
.context("Writing bootuuid.cfg")?;
82+
println!("Installed: bootuuid.cfg");
8183
Some(uuid_path)
8284
} else {
8385
None
@@ -96,12 +98,11 @@ pub(crate) fn install(
9698
.context("Copying static EFI")?;
9799
println!("Installed: {target:?}");
98100
if let Some(uuid_path) = uuid_path {
99-
// SAFETY: we always have a filename
100-
let filename = Path::new(&uuid_path).file_name().unwrap();
101-
let target = &vendor.join(filename);
102-
bootdir
101+
let target = &vendor.join(uuid_path);
102+
grub2dir
103103
.copy_file_at(uuid_path, &efidir, target)
104104
.context("Writing bootuuid.cfg to efi dir")?;
105+
println!("Installed: {target:?}");
105106
}
106107
}
107108
}

0 commit comments

Comments
 (0)