Skip to content

Commit 17f4ec7

Browse files
committed
grubconfig: minor changes to replace variables using const
1 parent bdd5120 commit 17f4ec7

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/grubconfigs.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::freezethaw::fsfreeze_thaw_cycle;
1212

1313
/// The subdirectory of /boot we use
1414
const GRUB2DIR: &str = "grub2";
15-
const CONFIGDIR: &str = "/usr/lib/bootupd/grub2-static";
15+
const CONFIGDIR: &str = "usr/lib/bootupd/grub2-static";
1616
const DROPINDIR: &str = "configs.d";
1717
// The related grub files
1818
const GRUBENV: &str = "grubenv";
@@ -43,11 +43,10 @@ pub(crate) fn install(
4343
}
4444

4545
let configdir = if let Some(src_root) = src_root {
46-
// strip the leading `/` to make the path relative to the given
47-
// source root
48-
src_root.sub_dir(Path::new(CONFIGDIR).strip_prefix("/")?)?
46+
src_root.sub_dir(CONFIGDIR)?
4947
} else {
50-
openat::Dir::open(Path::new(CONFIGDIR))?
48+
// Open / if there is no source root
49+
openat::Dir::open("/")?.sub_dir(CONFIGDIR)?
5150
};
5251

5352
let mut config = String::from("# Generated by bootupd / do not edit\n\n");
@@ -58,7 +57,7 @@ pub(crate) fn install(
5857
.read_to_string(&mut pre)?;
5958
config.push_str(pre.as_str());
6059

61-
let dropindir = configdir.sub_dir(Path::new(DROPINDIR))?;
60+
let dropindir = configdir.sub_dir(DROPINDIR)?;
6261
// Sort the files for reproducibility
6362
let mut entries = dropindir
6463
.list_dir(".")?
@@ -85,7 +84,7 @@ pub(crate) fn install(
8584

8685
let grub2dir = bootdir.sub_dir(GRUB2DIR)?;
8786
grub2dir
88-
.write_file_contents("grub.cfg", GRUBCONFIG_FILE_MODE, config.as_bytes())
87+
.write_file_contents(GRUBCONFIG, GRUBCONFIG_FILE_MODE, config.as_bytes())
8988
.context("Copying grub-static.cfg")?;
9089
println!("Installed: grub.cfg");
9190

@@ -113,7 +112,7 @@ pub(crate) fn install(
113112
if let Some(vendordir) = installed_efi_vendor {
114113
log::debug!("vendordir={:?}", &vendordir);
115114
let vendor = PathBuf::from(vendordir);
116-
let target = &vendor.join("grub.cfg");
115+
let target = &vendor.join(GRUBCONFIG);
117116
let dest_efidir = target_root
118117
.sub_dir_optional("boot/efi/EFI")
119118
.context("Opening /boot/efi/EFI")?;

0 commit comments

Comments
 (0)