diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-10-25 15:58:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-25 19:58:28 +0000 |
commit | a01edb394d2785b7d37da6435bb37381efc376ea (patch) | |
tree | 2d2445191185b2246c140ae580798edbc30bd1b9 /cli/tools | |
parent | e70341e65e9f4e44811210c9b24e67a29b2c497a (diff) |
fix(upgrade): stop running `deno lsp` processes on windows before attempting to replace executable (#26542)
Diffstat (limited to 'cli/tools')
-rw-r--r-- | cli/tools/upgrade.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index b1b09d1a6..77a9f72b8 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -579,6 +579,10 @@ pub async fn upgrade( let output_exe_path = full_path_output_flag.as_ref().unwrap_or(¤t_exe_path); + + #[cfg(windows)] + kill_running_deno_lsp_processes(); + let output_result = if *output_exe_path == current_exe_path { replace_exe(&new_exe_path, output_exe_path) } else { @@ -966,6 +970,34 @@ fn check_windows_access_denied_error( }) } +#[cfg(windows)] +fn kill_running_deno_lsp_processes() { + // limit this to `deno lsp` invocations to avoid killing important programs someone might be running + let is_debug = log::log_enabled!(log::Level::Debug); + let get_pipe = || { + if is_debug { + std::process::Stdio::inherit() + } else { + std::process::Stdio::null() + } + }; + let _ = Command::new("powershell.exe") + .args([ + "-Command", + r#"Get-WmiObject Win32_Process | Where-Object { + $_.Name -eq 'deno.exe' -and + $_.CommandLine -match '^(?:\"[^\"]+\"|\S+)\s+lsp\b' +} | ForEach-Object { + if ($_.Terminate()) { + Write-Host 'Terminated:' $_.ProcessId + } +}"#, + ]) + .stdout(get_pipe()) + .stderr(get_pipe()) + .output(); +} + fn set_exe_permissions( current_exe_path: &Path, output_exe_path: &Path, |