@@ -26,20 +26,21 @@ const KERNEL_FILE_NAME: &str = "kernel-x86_64";
2626const RAMDISK_FILE_NAME : & str = "ramdisk" ;
2727const CONFIG_FILE_NAME : & str = "boot.json" ;
2828
29- struct DiskImageFile < ' a > {
30- source : & ' a PathBuf ,
31- destination : & ' a str ,
29+ #[ derive( Clone ) ]
30+ struct DiskImageFile {
31+ source : PathBuf ,
32+ destination : String ,
3233}
3334
3435/// DiskImageBuilder helps create disk images for a specified set of files.
3536/// 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 > ,
3839}
3940
40- impl < ' a > DiskImageBuilder < ' a > {
41+ impl DiskImageBuilder {
4142 /// 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 {
4344 let mut obj = Self :: empty ( ) ;
4445 obj. set_kernel ( kernel) ;
4546 obj
@@ -51,31 +52,31 @@ impl<'a> DiskImageBuilder<'a> {
5152 }
5253
5354 /// 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 {
5556 self . add_or_replace_file ( path, KERNEL_FILE_NAME )
5657 }
5758
5859 /// 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 {
6061 self . add_or_replace_file ( & path, RAMDISK_FILE_NAME )
6162 }
6263
6364 /// Add or replace arbitrary files.
6465 /// NOTE: You can overwrite internal files if you choose, such as EFI/BOOT/BOOTX64.EFI
6566 /// 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 {
6768 self . files . insert (
6869 0 ,
69- DiskImageFile :: < ' a > {
70- source : & path,
71- destination : & target,
70+ DiskImageFile {
71+ source : path. clone ( ) . to_path_buf ( ) ,
72+ destination : target. to_string ( ) ,
7273 } ,
7374 ) ;
7475 self
7576 }
7677 fn create_fat_filesystem_image (
7778 & self ,
78- internal_files : BTreeMap < & ' a str , & ' a Path > ,
79+ internal_files : BTreeMap < & str , & Path > ,
7980 ) -> anyhow:: Result < NamedTempFile > {
8081 let mut local_map = BTreeMap :: new ( ) ;
8182
@@ -84,7 +85,7 @@ impl<'a> DiskImageBuilder<'a> {
8485 }
8586
8687 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 ( ) ) ;
8889 }
8990
9091 let out_file = NamedTempFile :: new ( ) . context ( "failed to create temp file" ) ?;
@@ -160,8 +161,8 @@ impl<'a> DiskImageBuilder<'a> {
160161 } ) ?;
161162
162163 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) ;
165166 if result. is_err ( ) {
166167 return Err ( anyhow:: Error :: from ( result. unwrap_err ( ) ) ) ;
167168 }
0 commit comments