From 78c63544262b98d7a80d3191cdcce9c28109c02b Mon Sep 17 00:00:00 2001 From: Pseudo Nymm <72524237+SkippyNet@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:16:43 -0500 Subject: [PATCH] Remove the old executable reliably after an update restart (v0.3.1) The restarted app tried once to delete usb-forge.exe.old while the previous process was still exiting, so the delete failed and the file stayed until the next launch. Retry for up to 15 seconds in the background. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/platform/windows.rs | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d68d8e..4787a6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2921,7 +2921,7 @@ dependencies = [ [[package]] name = "usb-forge" -version = "0.3.0" +version = "0.3.1" dependencies = [ "ed25519-dalek", "eframe", diff --git a/Cargo.toml b/Cargo.toml index 154f5f5..ca8f4f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "3" [package] name = "usb-forge" -version = "0.3.0" +version = "0.3.1" edition = "2024" rust-version = "1.92" description = "Build a verified multi-boot USB thumb drive from official ISOs on Windows and Linux" diff --git a/src/platform/windows.rs b/src/platform/windows.rs index 6132870..c8536a2 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -308,9 +308,22 @@ pub fn swap_executable(new_exe: &Path) -> Result { Ok(current) } -/// Remove the previous executable left behind by an update. +/// Remove the previous executable left behind by an update. Right after an update restart the +/// old process may still be exiting and hold the file, so keep retrying briefly in the background. pub fn cleanup_after_update() { - if let Ok(current) = std::env::current_exe() { - let _ = std::fs::remove_file(current.with_extension("exe.old")); + let Ok(current) = std::env::current_exe() else { + return; + }; + let old = current.with_extension("exe.old"); + if !old.exists() { + return; } + std::thread::spawn(move || { + for _ in 0..30 { + if std::fs::remove_file(&old).is_ok() || !old.exists() { + return; + } + std::thread::sleep(Duration::from_millis(500)); + } + }); }