From b803d8a8fd6b1587449e869b3a7a1ac687cf630b Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 15 Jul 2024 10:55:06 +0800 Subject: [PATCH] chore: remove unix ref --- appflowy-plugin/src/core/plugin.rs | 79 +++++++++++++++--------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/appflowy-plugin/src/core/plugin.rs b/appflowy-plugin/src/core/plugin.rs index 29ecf2c..57a410a 100644 --- a/appflowy-plugin/src/core/plugin.rs +++ b/appflowy-plugin/src/core/plugin.rs @@ -213,6 +213,8 @@ pub(crate) async fn start_plugin_process( .name(format!("<{}> core host thread", &plugin_info.name)) .spawn(move || { info!("Load {} plugin", &plugin_info.name); + + #[cfg(target_os = "macos")] handle_macos_security_check(&plugin_info); let child = std::process::Command::new(&plugin_info.exec_path) @@ -284,50 +286,49 @@ async fn ensure_executable(exec_path: &Path) -> Result<(), anyhow::Error> { Ok(()) } +#[cfg(target_os = "macos")] pub fn handle_macos_security_check(plugin_info: &PluginInfo) { - if cfg!(target_os = "macos") { - trace!("macos security check: {:?}", plugin_info.exec_path); - let mut open_manually = false; - match xattr::list(&plugin_info.exec_path) { - Ok(list) => { - let mut has_quarantine = false; - let mut has_lastuseddate = false; - - // https://eclecticlight.co/2023/03/16/what-is-macos-ventura-doing-tracking-provenance/ - // The com.apple.quarantine attribute is used by macOS to mark files that have been downloaded from - // the internet or received via other potentially unsafe methods. When this attribute is set, macOS - // employs additional security checks before allowing the file to be opened or executed - // The presence of this attribute can cause the system to display a permission error, such as: - // code: 1, kind: PermissionDenied, message: "Operation not permitted" - for attr in list { - if attr == "com.apple.quarantine" { - has_quarantine = true; - } - if attr == "com.apple.lastuseddate#PS" { - has_lastuseddate = true; - } - if cfg!(debug_assertions) { - trace!("{:?}: xattr: {:?}", plugin_info.exec_path, attr); - } + trace!("macos security check: {:?}", plugin_info.exec_path); + let mut open_manually = false; + match xattr::list(&plugin_info.exec_path) { + Ok(list) => { + let mut has_quarantine = false; + let mut has_lastuseddate = false; + + // https://eclecticlight.co/2023/03/16/what-is-macos-ventura-doing-tracking-provenance/ + // The com.apple.quarantine attribute is used by macOS to mark files that have been downloaded from + // the internet or received via other potentially unsafe methods. When this attribute is set, macOS + // employs additional security checks before allowing the file to be opened or executed + // The presence of this attribute can cause the system to display a permission error, such as: + // code: 1, kind: PermissionDenied, message: "Operation not permitted" + for attr in list { + if attr == "com.apple.quarantine" { + has_quarantine = true; } - - if has_quarantine && !has_lastuseddate { - open_manually = true; + if attr == "com.apple.lastuseddate#PS" { + has_lastuseddate = true; } - }, - Err(err) => { - error!("Failed to list xattr: {:?}", err); - open_manually = true; - }, - } + if cfg!(debug_assertions) { + trace!("{:?}: xattr: {:?}", plugin_info.exec_path, attr); + } + } - if open_manually { - trace!("Open plugin file manually: {:?}", plugin_info.exec_path); - // Using 'open' to trigger the macOS security check. After the user allows opening the binary, - // any subsequent 'open' command will not trigger the security check and the binary will run with permission. - if let Err(err) = Command::new("open").arg(&plugin_info.exec_path).output() { - error!("Failed to open plugin file: {:?}", err); + if has_quarantine && !has_lastuseddate { + open_manually = true; } + }, + Err(err) => { + error!("Failed to list xattr: {:?}", err); + open_manually = true; + }, + } + + if open_manually { + trace!("Open plugin file manually: {:?}", plugin_info.exec_path); + // Using 'open' to trigger the macOS security check. After the user allows opening the binary, + // any subsequent 'open' command will not trigger the security check and the binary will run with permission. + if let Err(err) = Command::new("open").arg(&plugin_info.exec_path).output() { + error!("Failed to open plugin file: {:?}", err); } } }