@@ -70,37 +70,40 @@ impl DiskImageBuilder {
7070
7171 /// Add or replace a kernel to be included in the final image.
7272 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 )
7474 }
7575
7676 /// Add or replace a ramdisk to be included in the final image.
7777 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 )
7979 }
8080
8181 /// Configures the runtime behavior of the bootloader.
8282 pub fn set_boot_config ( & mut self , boot_config : & BootConfig ) -> & mut Self {
8383 let json =
8484 serde_json:: to_string_pretty ( boot_config) . expect ( "failed to serialize BootConfig" ) ;
8585 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)
8797 }
8898
89- /// Add or replace arbitrary files.
90- pub fn add_or_replace_file (
99+ pub fn set_file (
91100 & mut self ,
92- file_data_source : FileDataSource ,
93- target : & str ,
101+ file_path : & Path ,
102+ destination : & str ,
94103 ) -> & 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)
103105 }
106+
104107 fn create_fat_filesystem_image (
105108 & self ,
106109 internal_files : BTreeMap < & str , FileDataSource > ,
0 commit comments