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