@@ -22,41 +22,45 @@ const BUNDLE_VAR_TOKEN: &[u8] = b"__TAURI_BUNDLE_TYPE_VAR_UNK";
2222/// Patch a binary with bundle type information
2323#[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
2424fn patch_binary ( binary : & PathBuf , package_type : & PackageType ) -> crate :: Result < ( ) > {
25+ log:: info!(
26+ "Patching {} with bundle type information: {}" ,
27+ display_path( binary) ,
28+ package_type. short_name( )
29+ ) ;
30+
2531 let mut file_data = std:: fs:: read ( binary) . expect ( "Could not read binary file." ) ;
2632
27- if let Some ( bundle_var_index) = kmp:: index_of ( BUNDLE_VAR_TOKEN , & file_data) {
28- #[ cfg( target_os = "linux" ) ]
29- let bundle_type = match package_type {
30- crate :: PackageType :: Deb => b"__TAURI_BUNDLE_TYPE_VAR_DEB" ,
31- crate :: PackageType :: Rpm => b"__TAURI_BUNDLE_TYPE_VAR_RPM" ,
32- crate :: PackageType :: AppImage => b"__TAURI_BUNDLE_TYPE_VAR_APP" ,
33- _ => {
34- return Err ( crate :: Error :: InvalidPackageType (
35- package_type. short_name ( ) . to_owned ( ) ,
36- "Linux" . to_owned ( ) ,
37- ) )
38- }
39- } ;
40- #[ cfg( target_os = "windows" ) ]
41- let bundle_type = match package_type {
42- crate :: PackageType :: Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS" ,
43- crate :: PackageType :: WindowsMsi => b"__TAURI_BUNDLE_TYPE_VAR_MSI" ,
44- _ => {
45- return Err ( crate :: Error :: InvalidPackageType (
46- package_type. short_name ( ) . to_owned ( ) ,
47- "Windows" . to_owned ( ) ,
48- ) )
49- }
50- } ;
33+ let bundle_var_index =
34+ kmp:: index_of ( BUNDLE_VAR_TOKEN , & file_data) . ok_or ( crate :: Error :: MissingBundleTypeVar ) ?;
35+ #[ cfg( target_os = "linux" ) ]
36+ let bundle_type = match package_type {
37+ crate :: PackageType :: Deb => b"__TAURI_BUNDLE_TYPE_VAR_DEB" ,
38+ crate :: PackageType :: Rpm => b"__TAURI_BUNDLE_TYPE_VAR_RPM" ,
39+ crate :: PackageType :: AppImage => b"__TAURI_BUNDLE_TYPE_VAR_APP" ,
40+ _ => {
41+ return Err ( crate :: Error :: InvalidPackageType (
42+ package_type. short_name ( ) . to_owned ( ) ,
43+ "Linux" . to_owned ( ) ,
44+ ) )
45+ }
46+ } ;
47+ #[ cfg( target_os = "windows" ) ]
48+ let bundle_type = match package_type {
49+ crate :: PackageType :: Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS" ,
50+ crate :: PackageType :: WindowsMsi => b"__TAURI_BUNDLE_TYPE_VAR_MSI" ,
51+ _ => {
52+ return Err ( crate :: Error :: InvalidPackageType (
53+ package_type. short_name ( ) . to_owned ( ) ,
54+ "Windows" . to_owned ( ) ,
55+ ) )
56+ }
57+ } ;
5158
52- file_data[ bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN . len ( ) ]
53- . copy_from_slice ( bundle_type) ;
59+ file_data[ bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN . len ( ) ]
60+ . copy_from_slice ( bundle_type) ;
61+
62+ std:: fs:: write ( binary, & file_data) . map_err ( |e| crate :: Error :: BinaryWriteError ( e. to_string ( ) ) ) ?;
5463
55- std:: fs:: write ( binary, & file_data)
56- . map_err ( |e| crate :: Error :: BinaryWriteError ( e. to_string ( ) ) ) ?;
57- } else {
58- return Err ( crate :: Error :: MissingBundleTypeVar ) ;
59- }
6064 Ok ( ( ) )
6165}
6266
0 commit comments