Skip to content

Commit 6a38d69

Browse files
authored
Fix autoupdate nuking the app on Windows (#41571)
Closes #41477 Release Notes: - N/A
1 parent 95feefc commit 6a38d69

File tree

4 files changed

+334
-191
lines changed

4 files changed

+334
-191
lines changed

Cargo.lock

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

crates/auto_update/src/auto_update.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ impl AutoUpdater {
331331

332332
pub fn start_polling(&self, cx: &mut Context<Self>) -> Task<Result<()>> {
333333
cx.spawn(async move |this, cx| {
334+
#[cfg(target_os = "windows")]
335+
{
336+
use util::ResultExt;
337+
338+
cleanup_windows()
339+
.await
340+
.context("failed to cleanup old directories")
341+
.log_err();
342+
}
343+
334344
loop {
335345
this.update(cx, |this, cx| this.poll(UpdateCheckType::Automatic, cx))?;
336346
cx.background_executor().timer(POLL_INTERVAL).await;
@@ -923,6 +933,32 @@ async fn install_release_macos(
923933
Ok(None)
924934
}
925935

936+
#[cfg(target_os = "windows")]
937+
async fn cleanup_windows() -> Result<()> {
938+
use util::ResultExt;
939+
940+
let parent = std::env::current_exe()?
941+
.parent()
942+
.context("No parent dir for Zed.exe")?
943+
.to_owned();
944+
945+
// keep in sync with crates/auto_update_helper/src/updater.rs
946+
smol::fs::remove_dir(parent.join("updates"))
947+
.await
948+
.context("failed to remove updates dir")
949+
.log_err();
950+
smol::fs::remove_dir(parent.join("install"))
951+
.await
952+
.context("failed to remove install dir")
953+
.log_err();
954+
smol::fs::remove_dir(parent.join("old"))
955+
.await
956+
.context("failed to remove old version dir")
957+
.log_err();
958+
959+
Ok(())
960+
}
961+
926962
async fn install_release_windows(downloaded_installer: PathBuf) -> Result<Option<PathBuf>> {
927963
let output = Command::new(downloaded_installer)
928964
.arg("/verysilent")

crates/auto_update_helper/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ simplelog.workspace = true
2121
[target.'cfg(target_os = "windows")'.dependencies]
2222
windows.workspace = true
2323

24+
[target.'cfg(target_os = "windows")'.dev-dependencies]
25+
tempfile.workspace = true
26+
2427
[target.'cfg(target_os = "windows")'.build-dependencies]
2528
winresource = "0.1"
2629

0 commit comments

Comments
 (0)