@@ -24,7 +24,7 @@ pub use bios::BiosBoot;
24
24
mod fat;
25
25
mod file_data_source;
26
26
27
- use std:: { collections:: BTreeMap , fs, io :: Write , path:: Path } ;
27
+ use std:: { collections:: BTreeMap , fs, path:: Path } ;
28
28
29
29
use anyhow:: Context ;
30
30
@@ -37,16 +37,10 @@ const KERNEL_FILE_NAME: &str = "kernel-x86_64";
37
37
const RAMDISK_FILE_NAME : & str = "ramdisk" ;
38
38
const CONFIG_FILE_NAME : & str = "boot.json" ;
39
39
40
- #[ derive( Clone ) ]
41
- struct DiskImageFile {
42
- source : FileDataSource ,
43
- destination : String ,
44
- }
45
-
46
40
/// DiskImageBuilder helps create disk images for a specified set of files.
47
41
/// It can currently create MBR (BIOS), GPT (UEFI), and TFTP (UEFI) images.
48
42
pub struct DiskImageBuilder {
49
- files : Vec < DiskImageFile > ,
43
+ files : BTreeMap < String , FileDataSource > ,
50
44
}
51
45
52
46
impl DiskImageBuilder {
@@ -59,7 +53,9 @@ impl DiskImageBuilder {
59
53
60
54
/// Create a new, empty instance of DiskImageBuilder
61
55
pub fn empty ( ) -> Self {
62
- Self { files : Vec :: new ( ) }
56
+ Self {
57
+ files : BTreeMap :: new ( ) ,
58
+ }
63
59
}
64
60
65
61
/// Add or replace a kernel to be included in the final image.
@@ -83,13 +79,7 @@ impl DiskImageBuilder {
83
79
/// Add a file source to the disk image
84
80
pub fn set_file_source ( & mut self , destination : & str , source : FileDataSource ) -> & mut Self {
85
81
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) ;
93
83
self
94
84
}
95
85
@@ -111,8 +101,8 @@ impl DiskImageBuilder {
111
101
) -> anyhow:: Result < NamedTempFile > {
112
102
let mut local_map = BTreeMap :: new ( ) ;
113
103
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 ( ) ) ;
116
106
}
117
107
118
108
for k in internal_files {
@@ -205,8 +195,8 @@ impl DiskImageBuilder {
205
195
)
206
196
} ) ?;
207
197
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 ( ) ) ;
210
200
211
201
let mut new_file = fs:: OpenOptions :: new ( )
212
202
. read ( true )
@@ -215,7 +205,7 @@ impl DiskImageBuilder {
215
205
. truncate ( true )
216
206
. open ( to) ?;
217
207
218
- f. source . copy_to ( & mut new_file) ?;
208
+ f. 1 . copy_to ( & mut new_file) ?;
219
209
}
220
210
221
211
Ok ( ( ) )
0 commit comments