From b519fd5b2ddb9b39a69c29c3e8487fc193153a3c Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Wed, 30 Oct 2024 16:17:50 -0600 Subject: [PATCH] Robustify download on remote (#19983) Closes #19976 Closes #19972 We now prefer curl to wget (as it supports socks5:// proxies) and pass -f to curl so it fails; and use sh instead of bash, which should have more consistent behaviour across systems Release Notes: - SSH Remoting: make downloading binary on remote more reliable. --------- Co-authored-by: Will --- crates/remote/src/ssh_session.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/remote/src/ssh_session.rs b/crates/remote/src/ssh_session.rs index d6213a577612be7ae3d3c3252597f432d304b38a..491a0c77f1133aaa87c440a47934855e17012c1e 100644 --- a/crates/remote/src/ssh_session.rs +++ b/crates/remote/src/ssh_session.rs @@ -1853,26 +1853,25 @@ impl SshRemoteConnection { delegate.set_status(Some("Downloading remote development server on host"), cx); + let body = shlex::try_quote(body).unwrap(); + let url = shlex::try_quote(url).unwrap(); + let dst_str = dst_path_gz.to_string_lossy(); + let dst_escaped = shlex::try_quote(&dst_str).unwrap(); + let script = format!( r#" - if command -v wget >/dev/null 2>&1; then - wget --max-redirect=5 --method=GET --header="Content-Type: application/json" --body-data='{}' '{}' -O '{}' && echo "wget" - elif command -v curl >/dev/null 2>&1; then - curl -L -X GET -H "Content-Type: application/json" -d '{}' '{}' -o '{}' && echo "curl" + if command -v curl >/dev/null 2>&1; then + curl -f -L -X GET -H "Content-Type: application/json" -d {body} {url} -o {dst_escaped} && echo "curl" + elif command -v wget >/dev/null 2>&1; then + wget --max-redirect=5 --method=GET --header="Content-Type: application/json" --body-data={body} {url} -O {dst_escaped} && echo "wget" else echo "Neither curl nor wget is available" >&2 exit 1 fi - "#, - body.replace("'", r#"\'"#), - url, - dst_path_gz.display(), - body.replace("'", r#"\'"#), - url, - dst_path_gz.display(), + "# ); - let output = run_cmd(self.socket.ssh_command("bash").arg("-c").arg(script)) + let output = run_cmd(self.socket.ssh_command("sh").arg("-c").arg(script)) .await .context("Failed to download server binary")?;