Skip to content

Commit 538570e

Browse files
committed
Fix build errors
1 parent f656591 commit 538570e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/lib.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ An experimental x86_64 bootloader that works on both BIOS and UEFI systems.
77
use anyhow::Context;
88
use std::{
99
collections::BTreeMap,
10-
path::{Path, PathBuf},
10+
path::{Path, PathBuf, self}, ops::Deref,
1111
};
1212
use tempfile::NamedTempFile;
1313

@@ -38,7 +38,7 @@ impl BiosBoot {
3838

3939
pub fn with_ramdisk(&self, ramdisk_path: &Path) -> Self {
4040
Self {
41-
kernel: self.kernel,
41+
kernel: self.kernel.to_owned(),
4242
ramdisk: Some(ramdisk_path.to_owned()),
4343
}
4444
}
@@ -71,13 +71,17 @@ impl BiosBoot {
7171
fn create_fat_partition(&self) -> anyhow::Result<NamedTempFile> {
7272
let stage_3_path = Path::new(env!("BIOS_STAGE_3_PATH"));
7373
let stage_4_path = Path::new(env!("BIOS_STAGE_4_PATH"));
74+
let has_rd_path = self.ramdisk.is_some();
75+
let binding = self.ramdisk.as_deref();
76+
let ramdisk_path = binding.unwrap_or(Path::new("no-such-file"));
77+
let kernel_path = self.kernel.as_path();
7478

7579
let mut files = BTreeMap::new();
76-
files.insert(KERNEL_FILE_NAME, self.kernel.as_path());
80+
files.insert(KERNEL_FILE_NAME, kernel_path);
7781
files.insert(BIOS_STAGE_3, stage_3_path);
7882
files.insert(BIOS_STAGE_4, stage_4_path);
79-
if self.ramdisk.is_some() {
80-
files.insert(RAMDISK_FILE_NAME, self.ramdisk.unwrap().as_path());
83+
if has_rd_path {
84+
files.insert(RAMDISK_FILE_NAME, ramdisk_path);
8185
}
8286
let out_file = NamedTempFile::new().context("failed to create temp file")?;
8387
fat::create_fat_filesystem(files, out_file.path())
@@ -104,7 +108,7 @@ impl UefiBoot {
104108

105109
pub fn with_ramdisk(&self, ramdisk_path: &Path) -> Self {
106110
Self {
107-
kernel: self.kernel,
111+
kernel: self.kernel.clone(),
108112
ramdisk: Some(ramdisk_path.to_owned()),
109113
}
110114
}
@@ -139,17 +143,23 @@ impl UefiBoot {
139143
Ok(())
140144
}
141145

146+
142147
/// Creates an UEFI-bootable FAT partition with the kernel.
143148
fn create_fat_partition(&self) -> anyhow::Result<NamedTempFile> {
149+
144150
let bootloader_path = Path::new(env!("UEFI_BOOTLOADER_PATH"));
145-
151+
let has_rd_path = self.ramdisk.is_some();
152+
let binding = self.ramdisk.as_deref();
153+
let ramdisk_path = binding.unwrap_or(Path::new("no-such-file"));
154+
let kernel_path = self.kernel.as_path();
146155
let mut files = BTreeMap::new();
147156
files.insert("efi/boot/bootx64.efi", bootloader_path);
148-
files.insert(KERNEL_FILE_NAME, self.kernel.as_path());
149-
if self.ramdisk.is_some() {
150-
files.insert(RAMDISK_FILE_NAME, self.ramdisk.unwrap().as_path());
157+
files.insert(KERNEL_FILE_NAME, kernel_path);
158+
159+
if has_rd_path {
160+
files.insert(RAMDISK_FILE_NAME, ramdisk_path);
151161
}
152-
162+
153163
let out_file = NamedTempFile::new().context("failed to create temp file")?;
154164
fat::create_fat_filesystem(files, out_file.path())
155165
.context("failed to create UEFI FAT filesystem")?;

0 commit comments

Comments
 (0)