@@ -139,17 +139,28 @@ impl Efi {
139
139
log:: debug!( "Not booted via EFI, skipping firmware update" ) ;
140
140
return Ok ( ( ) ) ;
141
141
}
142
- // Read /etc/os-release
143
- let release: OsRelease = OsRelease :: new ( ) ?;
144
- let product_name: & str = & release. name ;
142
+ let product_name = get_product_name ( ) ?;
145
143
log:: debug!( "Get product name: {product_name}" ) ;
146
144
assert ! ( product_name. len( ) > 0 ) ;
147
145
// clear all the boot entries that match the target name
148
- clear_efi_target ( product_name) ?;
149
- create_efi_boot_entry ( device, espdir, vendordir, product_name)
146
+ clear_efi_target ( & product_name) ?;
147
+ create_efi_boot_entry ( device, espdir, vendordir, & product_name)
150
148
}
151
149
}
152
150
151
+ #[ context( "Get product name" ) ]
152
+ fn get_product_name ( ) -> Result < String > {
153
+ let file_path = Path :: new ( "/etc/system-release" ) ;
154
+ if file_path. exists ( ) {
155
+ let content = std:: fs:: read_to_string ( file_path) ?;
156
+ let re = regex:: Regex :: new ( r" *release.*" ) . unwrap ( ) ;
157
+ return Ok ( re. replace_all ( & content, "" ) . to_string ( ) ) ;
158
+ }
159
+ // Read /etc/os-release
160
+ let release: OsRelease = OsRelease :: new ( ) ?;
161
+ Ok ( release. name )
162
+ }
163
+
153
164
/// Convert a nul-terminated UTF-16 byte array to a String.
154
165
fn string_from_utf16_bytes ( slice : & [ u8 ] ) -> String {
155
166
// For some reason, systemd appends 3 nul bytes after the string.
@@ -659,4 +670,10 @@ Boot0003* test";
659
670
) ;
660
671
Ok ( ( ) )
661
672
}
673
+ #[ test]
674
+ fn test_get_product_name ( ) -> Result < ( ) > {
675
+ let name = get_product_name ( ) ?;
676
+ assert ! ( name. len( ) > 0 ) ;
677
+ Ok ( ( ) )
678
+ }
662
679
}
0 commit comments