DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/NativeHost/
UninstallShellCommand.rs1#![allow(non_snake_case)]
2
3use std::path::PathBuf;
7
8use serde_json::Value;
9
10use crate::dev_log;
11
12const CLI_NAME:&str = "land";
13
14const SYMLINK_DIR:&str = "/usr/local/bin";
15
16pub async fn UninstallShellCommand(_Arguments:Vec<Value>) -> Result<Value, String> {
17 let Target = PathBuf::from(SYMLINK_DIR).join(CLI_NAME);
18
19 dev_log!("shell-cmd", "uninstallShellCommand: removing {}", Target.display());
20
21 match std::fs::remove_file(&Target) {
22 Ok(()) => {
23 dev_log!("shell-cmd", "uninstallShellCommand: removed");
24
25 Ok(Value::Bool(true))
26 },
27
28 Err(E) if E.kind() == std::io::ErrorKind::NotFound => Ok(Value::Bool(true)),
29
30 Err(E) if E.kind() == std::io::ErrorKind::PermissionDenied => {
31 #[cfg(target_os = "macos")]
32 {
33 let Script = format!("do shell script \"rm -f '{}'\" with administrator privileges", Target.display());
34
35 let Status = tokio::process::Command::new("osascript")
36 .args(["-e", &Script])
37 .status()
38 .await
39 .map_err(|E| format!("uninstallShellCommand: osascript failed: {E}"))?;
40
41 if Status.success() {
42 return Ok(Value::Bool(true));
43 }
44 }
45
46 Err(format!("uninstallShellCommand: permission denied"))
47 },
48
49 Err(E) => Err(format!("uninstallShellCommand: {E}")),
50 }
51}