@@ -70,37 +70,40 @@ impl DiskImageBuilder {
70
70
71
71
/// Add or replace a kernel to be included in the final image.
72
72
pub fn set_kernel ( & mut self , path : & Path ) -> & mut Self {
73
- self . add_or_replace_file ( FileDataSource :: File ( path. to_path_buf ( ) ) , KERNEL_FILE_NAME )
73
+ self . set_file_source ( FileDataSource :: File ( path. to_path_buf ( ) ) , KERNEL_FILE_NAME )
74
74
}
75
75
76
76
/// Add or replace a ramdisk to be included in the final image.
77
77
pub fn set_ramdisk ( & mut self , path : & Path ) -> & mut Self {
78
- self . add_or_replace_file ( FileDataSource :: File ( path. to_path_buf ( ) ) , RAMDISK_FILE_NAME )
78
+ self . set_file_source ( FileDataSource :: File ( path. to_path_buf ( ) ) , RAMDISK_FILE_NAME )
79
79
}
80
80
81
81
/// Configures the runtime behavior of the bootloader.
82
82
pub fn set_boot_config ( & mut self , boot_config : & BootConfig ) -> & mut Self {
83
83
let json =
84
84
serde_json:: to_string_pretty ( boot_config) . expect ( "failed to serialize BootConfig" ) ;
85
85
let bytes = json. as_bytes ( ) ;
86
- self . add_or_replace_file ( FileDataSource :: Data ( bytes. to_vec ( ) ) , CONFIG_FILE_NAME )
86
+ self . set_file_source ( FileDataSource :: Data ( bytes. to_vec ( ) ) , CONFIG_FILE_NAME )
87
+ }
88
+
89
+ pub fn set_file_source ( & mut self , source : FileDataSource , destination : & str , ) -> & mut Self {
90
+ let destination = destination. to_string ( ) ;
91
+ self . files . insert ( 0 , DiskImageFile { source, destination } ) ;
92
+ self
93
+ }
94
+
95
+ pub fn set_file_contents ( & mut self , data : & [ u8 ] , destination : & str , ) -> & mut Self {
96
+ self . set_file_source ( FileDataSource :: Data ( data. to_vec ( ) ) , destination)
87
97
}
88
98
89
- /// Add or replace arbitrary files.
90
- pub fn add_or_replace_file (
99
+ pub fn set_file (
91
100
& mut self ,
92
- file_data_source : FileDataSource ,
93
- target : & str ,
101
+ file_path : & Path ,
102
+ destination : & str ,
94
103
) -> & mut Self {
95
- self . files . insert (
96
- 0 ,
97
- DiskImageFile {
98
- source : file_data_source,
99
- destination : target. to_string ( ) ,
100
- } ,
101
- ) ;
102
- self
104
+ self . set_file_source ( FileDataSource :: File ( file_path. to_path_buf ( ) ) , destination)
103
105
}
106
+
104
107
fn create_fat_filesystem_image (
105
108
& self ,
106
109
internal_files : BTreeMap < & str , FileDataSource > ,
0 commit comments