mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix(upgrade): stop running deno lsp
processes on windows before attempting to replace executable (#26542)
This commit is contained in:
parent
494bcfab20
commit
1dff19aeb1
1 changed files with 32 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue