@@ -26,20 +26,21 @@ const KERNEL_FILE_NAME: &str = "kernel-x86_64";
26
26
const RAMDISK_FILE_NAME : & str = "ramdisk" ;
27
27
const CONFIG_FILE_NAME : & str = "boot.json" ;
28
28
29
- struct DiskImageFile < ' a > {
30
- source : & ' a PathBuf ,
31
- destination : & ' a str ,
29
+ #[ derive( Clone ) ]
30
+ struct DiskImageFile {
31
+ source : PathBuf ,
32
+ destination : String ,
32
33
}
33
34
34
35
/// DiskImageBuilder helps create disk images for a specified set of files.
35
36
/// It can currently create MBR (BIOS), GPT (UEFI), and TFTP (UEFI) images.
36
- pub struct DiskImageBuilder < ' a > {
37
- files : Vec < DiskImageFile < ' a > > ,
37
+ pub struct DiskImageBuilder {
38
+ files : Vec < DiskImageFile > ,
38
39
}
39
40
40
- impl < ' a > DiskImageBuilder < ' a > {
41
+ impl DiskImageBuilder {
41
42
/// Create a new instance of DiskImageBuilder, with the specified kernel.
42
- pub fn new ( kernel : & ' a PathBuf ) -> Self {
43
+ pub fn new ( kernel : & Path ) -> Self {
43
44
let mut obj = Self :: empty ( ) ;
44
45
obj. set_kernel ( kernel) ;
45
46
obj
@@ -51,31 +52,31 @@ impl<'a> DiskImageBuilder<'a> {
51
52
}
52
53
53
54
/// Add or replace a kernel to be included in the final image.
54
- pub fn set_kernel ( & mut self , path : & ' a PathBuf ) -> & mut Self {
55
+ pub fn set_kernel ( & mut self , path : & Path ) -> & mut Self {
55
56
self . add_or_replace_file ( path, KERNEL_FILE_NAME )
56
57
}
57
58
58
59
/// Add or replace a ramdisk to be included in the final image.
59
- pub fn set_ramdisk ( & mut self , path : & ' a PathBuf ) -> & mut Self {
60
+ pub fn set_ramdisk ( & mut self , path : & Path ) -> & mut Self {
60
61
self . add_or_replace_file ( & path, RAMDISK_FILE_NAME )
61
62
}
62
63
63
64
/// Add or replace arbitrary files.
64
65
/// NOTE: You can overwrite internal files if you choose, such as EFI/BOOT/BOOTX64.EFI
65
66
/// This can be useful in situations where you want to generate an image, but not use the provided bootloader.
66
- pub fn add_or_replace_file ( & mut self , path : & ' a PathBuf , target : & ' a str ) -> & mut Self {
67
+ pub fn add_or_replace_file ( & mut self , path : & Path , target : & str ) -> & mut Self {
67
68
self . files . insert (
68
69
0 ,
69
- DiskImageFile :: < ' a > {
70
- source : & path,
71
- destination : & target,
70
+ DiskImageFile {
71
+ source : path. clone ( ) . to_path_buf ( ) ,
72
+ destination : target. to_string ( ) ,
72
73
} ,
73
74
) ;
74
75
self
75
76
}
76
77
fn create_fat_filesystem_image (
77
78
& self ,
78
- internal_files : BTreeMap < & ' a str , & ' a Path > ,
79
+ internal_files : BTreeMap < & str , & Path > ,
79
80
) -> anyhow:: Result < NamedTempFile > {
80
81
let mut local_map = BTreeMap :: new ( ) ;
81
82
@@ -84,7 +85,7 @@ impl<'a> DiskImageBuilder<'a> {
84
85
}
85
86
86
87
for f in self . files . as_slice ( ) {
87
- local_map. insert ( f. destination , & f. source . as_path ( ) ) ;
88
+ local_map. insert ( & f. destination , & f. source . as_path ( ) ) ;
88
89
}
89
90
90
91
let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
@@ -160,8 +161,8 @@ impl<'a> DiskImageBuilder<'a> {
160
161
} ) ?;
161
162
162
163
for f in self . files . as_slice ( ) {
163
- let to = tftp_path. join ( f. destination ) ;
164
- let result = std:: fs:: copy ( f. source , to) ;
164
+ let to = tftp_path. join ( f. destination . clone ( ) ) ;
165
+ let result = std:: fs:: copy ( f. source . clone ( ) , to) ;
165
166
if result. is_err ( ) {
166
167
return Err ( anyhow:: Error :: from ( result. unwrap_err ( ) ) ) ;
167
168
}
0 commit comments