@@ -24,7 +24,7 @@ pub use bios::BiosBoot;
2424mod fat;
2525mod file_data_source;
2626
27- use std:: { collections:: BTreeMap , fs, io :: Write , path:: Path } ;
27+ use std:: { collections:: BTreeMap , fs, path:: Path } ;
2828
2929use anyhow:: Context ;
3030
@@ -37,16 +37,10 @@ const KERNEL_FILE_NAME: &str = "kernel-x86_64";
3737const RAMDISK_FILE_NAME : & str = "ramdisk" ;
3838const CONFIG_FILE_NAME : & str = "boot.json" ;
3939
40- #[ derive( Clone ) ]
41- struct DiskImageFile {
42- source : FileDataSource ,
43- destination : String ,
44- }
45-
4640/// DiskImageBuilder helps create disk images for a specified set of files.
4741/// It can currently create MBR (BIOS), GPT (UEFI), and TFTP (UEFI) images.
4842pub struct DiskImageBuilder {
49- files : Vec < DiskImageFile > ,
43+ files : BTreeMap < String , FileDataSource > ,
5044}
5145
5246impl DiskImageBuilder {
@@ -59,7 +53,9 @@ impl DiskImageBuilder {
5953
6054 /// Create a new, empty instance of DiskImageBuilder
6155 pub fn empty ( ) -> Self {
62- Self { files : Vec :: new ( ) }
56+ Self {
57+ files : BTreeMap :: new ( ) ,
58+ }
6359 }
6460
6561 /// Add or replace a kernel to be included in the final image.
@@ -83,13 +79,7 @@ impl DiskImageBuilder {
8379 /// Add a file source to the disk image
8480 pub fn set_file_source ( & mut self , destination : & str , source : FileDataSource ) -> & mut Self {
8581 let destination = destination. to_string ( ) ;
86- self . files . insert (
87- 0 ,
88- DiskImageFile {
89- source,
90- destination,
91- } ,
92- ) ;
82+ self . files . insert ( destination, source) ;
9383 self
9484 }
9585
@@ -111,8 +101,8 @@ impl DiskImageBuilder {
111101 ) -> anyhow:: Result < NamedTempFile > {
112102 let mut local_map = BTreeMap :: new ( ) ;
113103
114- for f in self . files . as_slice ( ) {
115- local_map. insert ( f. destination . as_str ( ) , f. source . clone ( ) ) ;
104+ for f in & self . files {
105+ local_map. insert ( f. 0 . as_str ( ) , f. 1 . clone ( ) ) ;
116106 }
117107
118108 for k in internal_files {
@@ -205,8 +195,8 @@ impl DiskImageBuilder {
205195 )
206196 } ) ?;
207197
208- for f in self . files . as_slice ( ) {
209- let to = tftp_path. join ( f. destination . clone ( ) ) ;
198+ for f in & self . files {
199+ let to = tftp_path. join ( f. 0 . clone ( ) ) ;
210200
211201 let mut new_file = fs:: OpenOptions :: new ( )
212202 . read ( true )
@@ -215,7 +205,7 @@ impl DiskImageBuilder {
215205 . truncate ( true )
216206 . open ( to) ?;
217207
218- f. source . copy_to ( & mut new_file) ?;
208+ f. 1 . copy_to ( & mut new_file) ?;
219209 }
220210
221211 Ok ( ( ) )
0 commit comments