fix: get win node path from registry (#5731)

Signed-off-by: V. Lascik <vlascik@users.noreply.github.com>
This commit is contained in:
vlascik
2025-11-17 20:12:56 +01:00
committed by GitHub
parent 63e9a37b13
commit a885f5c3b9
3 changed files with 52 additions and 5 deletions
Generated
+12 -1
View File
@@ -2874,6 +2874,7 @@ dependencies = [
"tracing-subscriber",
"utoipa",
"uuid",
"winreg 0.55.0",
]
[[package]]
@@ -5489,7 +5490,7 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"winreg",
"winreg 0.50.0",
]
[[package]]
@@ -8484,6 +8485,16 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "winreg"
version = "0.55.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97"
dependencies = [
"cfg-if",
"windows-sys 0.59.0",
]
[[package]]
name = "winsafe"
version = "0.0.19"
+4
View File
@@ -39,6 +39,10 @@ reqwest = { version = "0.12.9", features = ["json", "rustls-tls", "blocking", "m
tokio-util = "0.7.15"
uuid = { version = "1.11", features = ["v4"] }
serde_path_to_error = "0.1.20"
winreg = { version = "0.55.0", optional = true }
[target.'cfg(windows)'.dependencies]
winreg = { version = "0.55.0" }
[[bin]]
name = "goosed"
+36 -4
View File
@@ -482,13 +482,45 @@ async fn agent_add_extension(
State(state): State<Arc<AppState>>,
Json(request): Json<AddExtensionRequest>,
) -> Result<StatusCode, ErrorResponse> {
if cfg!(target_os = "windows") {
#[cfg(windows)]
{
use winreg::enums::{HKEY_LOCAL_MACHINE, KEY_READ};
use winreg::RegKey;
if let ExtensionConfig::Stdio { cmd, .. } = &request.config {
if cmd.ends_with("npx.cmd") || cmd.ends_with("npx") {
let node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe")
let mut node_exists = std::path::Path::new(r"C:\Program Files\nodejs\node.exe")
.exists()
|| std::path::Path::new(r"C:\Program Files (x86)\nodejs\node.exe").exists();
// Also check Windows registry: HKEY_LOCAL_MACHINE\\SOFTWARE\\Node.js InstallPath
if !node_exists {
// Try 64-bit view first, then 32-bit. Use open_subkey_with_flags to avoid WOW64 redirection issues.
let install_path_from_reg: Option<String> = (|| {
let hk_local_machine = RegKey::predef(HKEY_LOCAL_MACHINE);
// Common keys to try
let keys = vec!["SOFTWARE\\Node.js", "SOFTWARE\\WOW6432Node\\Node.js"];
for k in keys.iter() {
if let Ok(subkey) = hk_local_machine.open_subkey_with_flags(k, KEY_READ)
{
if let Ok(val) = subkey.get_value::<String, _>("InstallPath") {
if !val.trim().is_empty() {
return Some(val);
}
}
}
}
None
})();
if let Some(path_str) = install_path_from_reg {
let node_path = std::path::Path::new(&path_str).join("node.exe");
if node_path.exists() {
node_exists = true;
}
}
}
if !node_exists {
let cmd_path = std::path::Path::new(&cmd);
let script_dir = cmd_path
@@ -497,7 +529,7 @@ async fn agent_add_extension(
let install_script = script_dir.join("install-node.cmd");
if install_script.exists() {
eprintln!("Installing Node.js...");
eprintln!("Node.js not found on the system, installing Node.js...");
let output = std::process::Command::new(&install_script)
.arg("https://nodejs.org/dist/v23.10.0/node-v23.10.0-x64.msi")
.output()
@@ -513,7 +545,7 @@ async fn agent_add_extension(
}
} else {
return Err(ErrorResponse::internal(format!(
"Node.js not detected and no installer script not found at: {}",
"Node.js not found on the system, and no installer script found at: {}",
install_script.display()
)));
}