Skip to content

Commit 31d95a3

Browse files
Revert "util: Check whether discovered powershell is actually executable" (#43247) (cherry-pick to stable) (#43249)
Cherry-pick of #43247 to stable ---- Reverts #43044 Closes #43224 This slows down startup on windows significantly Release Notes: - Fixed slow startup on Windows Co-authored-by: Lukas Wirth <lukas@zed.dev>
1 parent f6f228d commit 31d95a3

File tree

3 files changed

+36
-55
lines changed

3 files changed

+36
-55
lines changed

crates/askpass/src/askpass.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ impl PasswordProxy {
254254
.await
255255
.with_context(|| format!("creating askpass script at {askpass_script_path:?}"))?;
256256
make_file_executable(&askpass_script_path).await?;
257-
// todo(shell): There might be no powershell on the system
258257
#[cfg(target_os = "windows")]
259258
let askpass_helper = format!(
260259
"powershell.exe -ExecutionPolicy Bypass -File {}",

crates/gpui/src/platform/windows/platform.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,10 @@ impl Platform for WindowsPlatform {
390390
clippy::disallowed_methods,
391391
reason = "We are restarting ourselves, using std command thus is fine"
392392
)]
393-
// todo(shell): There might be no powershell on the system
394-
let restart_process =
395-
util::command::new_std_command(util::shell::get_windows_system_shell())
396-
.arg("-command")
397-
.arg(script)
398-
.spawn();
393+
let restart_process = util::command::new_std_command("powershell.exe")
394+
.arg("-command")
395+
.arg(script)
396+
.spawn();
399397

400398
match restart_process {
401399
Ok(_) => self.quit(),

crates/util/src/shell.rs

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use schemars::JsonSchema;
22
use serde::{Deserialize, Serialize};
33
use std::{borrow::Cow, fmt, path::Path, sync::LazyLock};
44

5-
use crate::command::new_std_command;
6-
75
/// Shell configuration to open the terminal with.
86
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema, Hash)]
97
#[serde(rename_all = "snake_case")]
@@ -110,12 +108,16 @@ pub fn get_windows_system_shell() -> String {
110108
use std::path::PathBuf;
111109

112110
fn find_pwsh_in_programfiles(find_alternate: bool, find_preview: bool) -> Option<PathBuf> {
111+
#[cfg(target_pointer_width = "64")]
113112
let env_var = if find_alternate {
114-
if cfg!(target_pointer_width = "64") {
115-
"ProgramFiles(x86)"
116-
} else {
117-
"ProgramW6432"
118-
}
113+
"ProgramFiles(x86)"
114+
} else {
115+
"ProgramFiles"
116+
};
117+
118+
#[cfg(target_pointer_width = "32")]
119+
let env_var = if find_alternate {
120+
"ProgramW6432"
119121
} else {
120122
"ProgramFiles"
121123
};
@@ -163,19 +165,23 @@ pub fn get_windows_system_shell() -> String {
163165
} else {
164166
"Microsoft.PowerShell_"
165167
};
166-
msix_app_dir.read_dir().ok()?.find_map(|entry| {
167-
let entry = entry.ok()?;
168-
if !matches!(entry.file_type(), Ok(ft) if ft.is_dir()) {
169-
return None;
170-
}
168+
msix_app_dir
169+
.read_dir()
170+
.ok()?
171+
.filter_map(|entry| {
172+
let entry = entry.ok()?;
173+
if !matches!(entry.file_type(), Ok(ft) if ft.is_dir()) {
174+
return None;
175+
}
171176

172-
if !entry.file_name().to_string_lossy().starts_with(prefix) {
173-
return None;
174-
}
177+
if !entry.file_name().to_string_lossy().starts_with(prefix) {
178+
return None;
179+
}
175180

176-
let exe_path = entry.path().join("pwsh.exe");
177-
exe_path.exists().then_some(exe_path)
178-
})
181+
let exe_path = entry.path().join("pwsh.exe");
182+
exe_path.exists().then_some(exe_path)
183+
})
184+
.next()
179185
}
180186

181187
fn find_pwsh_in_scoop() -> Option<PathBuf> {
@@ -184,37 +190,15 @@ pub fn get_windows_system_shell() -> String {
184190
pwsh_exe.exists().then_some(pwsh_exe)
185191
}
186192

187-
// check whether the found powershell is executable for us
188193
static SYSTEM_SHELL: LazyLock<String> = LazyLock::new(|| {
189-
let can_execute_pwsh = |p: &PathBuf| {
190-
#[allow(clippy::disallowed_methods)]
191-
let status = new_std_command(p).arg("-NoProfile").arg("-Help").status();
192-
let success = status.as_ref().is_ok_and(|status| status.success());
193-
if !success {
194-
log::warn!(
195-
"Powershell found at `{}` is not executable: {status:?}",
196-
p.display()
197-
);
198-
}
199-
success
200-
};
201-
202-
let locations = [
203-
|| find_pwsh_in_programfiles(false, false),
204-
|| find_pwsh_in_programfiles(true, false),
205-
|| find_pwsh_in_msix(false),
206-
|| find_pwsh_in_programfiles(false, true),
207-
|| find_pwsh_in_msix(true),
208-
|| find_pwsh_in_programfiles(true, true),
209-
|| find_pwsh_in_scoop(),
210-
|| which::which_global("pwsh.exe").ok(),
211-
|| which::which_global("powershell.exe").ok(),
212-
];
213-
locations
214-
.into_iter()
215-
.filter_map(|f| f())
216-
.find(|p| can_execute_pwsh(&p))
217-
.map(|p| p.to_string_lossy().trim().to_owned())
194+
find_pwsh_in_programfiles(false, false)
195+
.or_else(|| find_pwsh_in_programfiles(true, false))
196+
.or_else(|| find_pwsh_in_msix(false))
197+
.or_else(|| find_pwsh_in_programfiles(false, true))
198+
.or_else(|| find_pwsh_in_msix(true))
199+
.or_else(|| find_pwsh_in_programfiles(true, true))
200+
.or_else(find_pwsh_in_scoop)
201+
.map(|p| p.to_string_lossy().into_owned())
218202
.inspect(|shell| log::info!("Found powershell in: {}", shell))
219203
.unwrap_or_else(|| {
220204
log::warn!("Powershell not found, falling back to `cmd`");

0 commit comments

Comments
 (0)