Skip to content

Commit ca35070

Browse files
detect with winreg instead of pathsearch
1 parent 3921a42 commit ca35070

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ mockall = "0.13.1"
6161
notify = "8.2.0"
6262
p256 = { version = "0.13.2", features = ["pem", "pkcs8", "std"] }
6363
pathdiff = { version = "0.2.3", features = ["camino"] }
64-
pathsearch = "0.2.0"
6564
pem = "3.0.5"
6665
phf = { version = "0.13.1", features = ["macros"] }
6766
pkcs8 = { version = "0.10.2", features = ["encryption", "std"] }
@@ -86,6 +85,7 @@ tracing = "0.1.41"
8685
tracing-subscriber = "0.3.20"
8786
url = "2.5.4"
8887
uuid = { version = "1.16.0", features = ["serde", "v4"] }
88+
winreg = "0.55"
8989
zeroize = "1.8.1"
9090

9191
[workspace.dependencies.reqwest]

crates/icp/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ k256 = { workspace = true }
3939
keyring = { workspace = true }
4040
notify = { workspace = true }
4141
p256 = { workspace = true }
42-
pathsearch = { workspace = true }
4342
pem = { workspace = true }
4443
pkcs8 = { workspace = true }
4544
rand = { workspace = true }
@@ -65,5 +64,8 @@ url = { workspace = true }
6564
uuid = { workspace = true }
6665
zeroize = { workspace = true }
6766

67+
[target.'cfg(windows)'.dependencies]
68+
winreg = { workspace = true }
69+
6870
[dev-dependencies]
6971
jsonschema = { workspace = true }

crates/icp/src/canister/script.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,24 @@ fn shell_command(s: &str, cwd: &Path) -> Result<Command, ScriptError> {
172172
#[cfg(unix)]
173173
let mut cmd = Command::new("sh");
174174
#[cfg(windows)]
175-
let mut cmd = if let Some(_) = std::env::var_os("BASH_VERSION") {
175+
let mut cmd = if let Some(_) = std::env::var_os("MSYSTEM") {
176176
Command::new("bash")
177177
} else {
178-
if let Some(git_path) = pathsearch::find_executable_in_path("git") {
179-
let git_path =
180-
PathBuf::try_from(git_path.clone()).context(BadPathSnafu { path: git_path })?;
181-
if let Some(cmd_path) = git_path.parent()
182-
&& cmd_path.ends_with("cmd")
183-
{
184-
Command::new(cmd_path.parent().unwrap().join("bin/bash.exe"))
185-
} else {
186-
return LocateBashSnafu { git_path }.fail();
187-
}
178+
use winreg::{RegKey, enums::*};
179+
let git_for_windows_path = if let Ok(lm_path) = RegKey::predef(HKEY_LOCAL_MACHINE)
180+
.open_subkey(r"SOFTWARE\GitForWindows")
181+
.and_then(|key| key.get_value::<String, _>("InstallPath"))
182+
{
183+
lm_path
184+
} else if let Ok(cu_path) = RegKey::predef(HKEY_CURRENT_USER)
185+
.open_subkey(r"SOFTWARE\GitForWindows")
186+
.and_then(|key| key.get_value::<String, _>("InstallPath"))
187+
{
188+
cu_path
188189
} else {
189190
return LocateGitSnafu.fail();
190-
}
191+
};
192+
Command::new(git_for_windows_path.join("bin/bash.exe"))
191193
};
192194
cmd.args(["-c", s]);
193195
cmd.current_dir(cwd);

0 commit comments

Comments
 (0)