@@ -7,7 +7,7 @@ An experimental x86_64 bootloader that works on both BIOS and UEFI systems.
7
7
use anyhow:: Context ;
8
8
use std:: {
9
9
collections:: BTreeMap ,
10
- path:: { Path , PathBuf } ,
10
+ path:: { Path , PathBuf , self } , ops :: Deref ,
11
11
} ;
12
12
use tempfile:: NamedTempFile ;
13
13
@@ -38,7 +38,7 @@ impl BiosBoot {
38
38
39
39
pub fn with_ramdisk ( & self , ramdisk_path : & Path ) -> Self {
40
40
Self {
41
- kernel : self . kernel ,
41
+ kernel : self . kernel . to_owned ( ) ,
42
42
ramdisk : Some ( ramdisk_path. to_owned ( ) ) ,
43
43
}
44
44
}
@@ -71,13 +71,17 @@ impl BiosBoot {
71
71
fn create_fat_partition ( & self ) -> anyhow:: Result < NamedTempFile > {
72
72
let stage_3_path = Path :: new ( env ! ( "BIOS_STAGE_3_PATH" ) ) ;
73
73
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 ( ) ;
74
78
75
79
let mut files = BTreeMap :: new ( ) ;
76
- files. insert ( KERNEL_FILE_NAME , self . kernel . as_path ( ) ) ;
80
+ files. insert ( KERNEL_FILE_NAME , kernel_path ) ;
77
81
files. insert ( BIOS_STAGE_3 , stage_3_path) ;
78
82
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 ) ;
81
85
}
82
86
let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
83
87
fat:: create_fat_filesystem ( files, out_file. path ( ) )
@@ -104,7 +108,7 @@ impl UefiBoot {
104
108
105
109
pub fn with_ramdisk ( & self , ramdisk_path : & Path ) -> Self {
106
110
Self {
107
- kernel : self . kernel ,
111
+ kernel : self . kernel . clone ( ) ,
108
112
ramdisk : Some ( ramdisk_path. to_owned ( ) ) ,
109
113
}
110
114
}
@@ -139,17 +143,23 @@ impl UefiBoot {
139
143
Ok ( ( ) )
140
144
}
141
145
146
+
142
147
/// Creates an UEFI-bootable FAT partition with the kernel.
143
148
fn create_fat_partition ( & self ) -> anyhow:: Result < NamedTempFile > {
149
+
144
150
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 ( ) ;
146
155
let mut files = BTreeMap :: new ( ) ;
147
156
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) ;
151
161
}
152
-
162
+
153
163
let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
154
164
fat:: create_fat_filesystem ( files, out_file. path ( ) )
155
165
. context ( "failed to create UEFI FAT filesystem" ) ?;
0 commit comments