From 3a9c071e6e1cbdc24cd8b3d0a479d61a1b669ca9 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 24 Oct 2024 14:37:02 -0600 Subject: [PATCH] Fix partial downloads of ssh remote server (#19700) Release Notes: - SSH Remoting: fix a bug where inerrrupting ssh connecting could leave your local binary cached in an invalid state --- crates/auto_update/src/auto_update.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 57286e673c..a45eb3a05b 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -11,6 +11,7 @@ use gpui::{ }; use markdown_preview::markdown_preview_view::{MarkdownPreviewMode, MarkdownPreviewView}; +use paths::remote_servers_dir; use schemars::JsonSchema; use serde::Deserialize; use serde_derive::Serialize; @@ -661,12 +662,15 @@ async fn download_remote_server_binary( client: Arc, cx: &AsyncAppContext, ) -> Result<()> { - let mut target_file = File::create(&target_path).await?; + let temp = tempfile::Builder::new().tempfile_in(remote_servers_dir())?; + let mut temp_file = File::create(&temp).await?; let update_request_body = build_remote_server_update_request_body(cx)?; let request_body = AsyncBody::from(serde_json::to_string(&update_request_body)?); let mut response = client.get(&release.url, request_body, true).await?; - smol::io::copy(response.body_mut(), &mut target_file).await?; + smol::io::copy(response.body_mut(), &mut temp_file).await?; + smol::fs::rename(&temp, &target_path).await?; + Ok(()) }