Skip to content

Commit

Permalink
fix(upgrade): stop running deno lsp processes on windows before att…
Browse files Browse the repository at this point in the history
…empting to replace executable (#26542)
  • Loading branch information
dsherret authored and bartlomieju committed Oct 29, 2024
1 parent 494bcfa commit 1dff19a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cli/tools/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ pub async fn upgrade(

let output_exe_path =
full_path_output_flag.as_ref().unwrap_or(&current_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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1dff19a

Please sign in to comment.