Use PowerShell for Windows update probes
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s

This commit is contained in:
DuProcess
2026-07-16 20:19:14 -04:00
parent 6666965128
commit b6256eb322
+97 -20
View File
@@ -4330,20 +4330,34 @@ fn latest_release_tag(repo: &str) -> Result<Option<String>> {
if !web.starts_with("http://") && !web.starts_with("https://") { if !web.starts_with("http://") && !web.starts_with("https://") {
return Ok(None); return Ok(None);
} }
let output = Command::new("curl") let latest_url = format!("{web}/releases/latest");
.arg("-fsSL") let output = if cfg!(windows) {
.arg("-o") Command::new("powershell.exe")
.arg("/dev/null") .arg("-NoProfile")
.arg("-w") .arg("-ExecutionPolicy")
.arg("%{url_effective}") .arg("Bypass")
.arg(format!("{web}/releases/latest")) .arg("-Command")
.stdin(Stdio::null()) .arg(windows_effective_url_script(&latest_url))
.output() .stdin(Stdio::null())
.with_context(|| format!("resolve latest release for {web}"))?; .output()
.with_context(|| format!("resolve latest release for {web}"))?
} else {
Command::new("curl")
.arg("-fsSL")
.arg("-o")
.arg("/dev/null")
.arg("-w")
.arg("%{url_effective}")
.arg(latest_url)
.stdin(Stdio::null())
.output()
.with_context(|| format!("resolve latest release for {web}"))?
};
if !output.status.success() { if !output.status.success() {
return Ok(None); return Ok(None);
} }
let effective = String::from_utf8_lossy(&output.stdout); let effective = String::from_utf8_lossy(&output.stdout);
let effective = effective.trim();
Ok(release_tag_from_effective_url(web, &effective)) Ok(release_tag_from_effective_url(web, &effective))
} }
@@ -4359,14 +4373,28 @@ fn release_tag_download_url(repo: &str, tag: &str, artifact: &str) -> Option<Str
} }
fn url_reachable(url: &str) -> Result<bool> { fn url_reachable(url: &str) -> Result<bool> {
let status = Command::new("curl") let status = if cfg!(windows) {
.arg("-fsIL") Command::new("powershell.exe")
.arg(url) .arg("-NoProfile")
.stdin(Stdio::null()) .arg("-ExecutionPolicy")
.stdout(Stdio::null()) .arg("Bypass")
.stderr(Stdio::null()) .arg("-Command")
.status() .arg(windows_url_reachable_script(url))
.with_context(|| format!("check {url}"))?; .stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.with_context(|| format!("check {url}"))?
} else {
Command::new("curl")
.arg("-fsIL")
.arg(url)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.with_context(|| format!("check {url}"))?
};
Ok(status.success()) Ok(status.success())
} }
@@ -4570,6 +4598,36 @@ fn windows_update_script(
script script
} }
fn windows_effective_url_script(url: &str) -> String {
let url = powershell_string(url);
format!(
"$ErrorActionPreference='Stop';\
$ProgressPreference='SilentlyContinue';\
$response=Invoke-WebRequest -UseBasicParsing -Uri {url} -MaximumRedirection 5;\
if ($response.BaseResponse.ResponseUri) {{ \
$response.BaseResponse.ResponseUri.AbsoluteUri \
}} elseif ($response.BaseResponse.RequestMessage -and $response.BaseResponse.RequestMessage.RequestUri) {{ \
$response.BaseResponse.RequestMessage.RequestUri.AbsoluteUri \
}} else {{ \
{url} \
}}"
)
}
fn windows_url_reachable_script(url: &str) -> String {
format!(
"$ErrorActionPreference='Stop';\
$ProgressPreference='SilentlyContinue';\
try {{ \
Invoke-WebRequest -UseBasicParsing -Uri {} -Method Head -MaximumRedirection 5 | Out-Null;\
exit 0 \
}} catch {{ \
exit 1 \
}}",
powershell_string(url)
)
}
fn windows_deferred_update_script(parent_pid: u32, installer_script: &str) -> String { fn windows_deferred_update_script(parent_pid: u32, installer_script: &str) -> String {
format!( format!(
"$ErrorActionPreference='Stop';\ "$ErrorActionPreference='Stop';\
@@ -10190,8 +10248,8 @@ mod tests {
trace_report_warnings, unix_update_script, update_binary_version_for_installer, trace_report_warnings, unix_update_script, update_binary_version_for_installer,
update_installer_url, update_version_status, upsert_managed_block, valid_forward_host, update_installer_url, update_version_status, upsert_managed_block, valid_forward_host,
vscode_safe_alias, wake_repaint_retry_deadline, windows_command_word, vscode_safe_alias, wake_repaint_retry_deadline, windows_command_word,
windows_deferred_update_script, windows_mode_from_readonly, windows_readonly_from_mode, windows_deferred_update_script, windows_effective_url_script, windows_mode_from_readonly,
windows_update_script, windows_readonly_from_mode, windows_update_script, windows_url_reachable_script,
}; };
use dosh::config::{ClientConfig, CommandExtension, HostConfig}; use dosh::config::{ClientConfig, CommandExtension, HostConfig};
use dosh::native::EnvVar; use dosh::native::EnvVar;
@@ -12464,6 +12522,25 @@ mod tests {
); );
} }
#[test]
fn windows_update_probes_are_powershell_native() {
let latest =
windows_effective_url_script("https://git.palav.dev/Palav/dosh/releases/latest");
assert!(latest.contains("Invoke-WebRequest -UseBasicParsing"));
assert!(latest.contains("-MaximumRedirection 5"));
assert!(latest.contains("$response.BaseResponse.ResponseUri.AbsoluteUri"));
assert!(!latest.contains("curl"));
let reachable = windows_url_reachable_script(
"https://git.palav.dev/Palav/dosh/releases/latest/download/dosh-windows-x86_64.zip",
);
assert!(reachable.contains("Invoke-WebRequest -UseBasicParsing"));
assert!(reachable.contains("-Method Head"));
assert!(reachable.contains("exit 0"));
assert!(reachable.contains("exit 1"));
assert!(!reachable.contains("curl"));
}
#[test] #[test]
fn update_uses_local_tag_when_release_latest_is_older() { fn update_uses_local_tag_when_release_latest_is_older() {
assert_eq!( assert_eq!(