From a93c1507f9ff1ee64b33f0298913ee7947ae2f5d Mon Sep 17 00:00:00 2001 From: Alexander Krylov Date: Sun, 25 Oct 2026 03:16:56 +0300 Subject: [PATCH 1/2] Launcher: a version removal retries a locked file and leaves the UI thread remove_dir_all stops at the first file another process still holds and leaves the rest deleted, so a removal that worked reported os error 5. Retry five times 250ms apart and treat a missing folder as done. The window froze because the deletion ran from the update loop; it now runs on a thread and reports back with Msg::Removed, as install already did. --- launcher/src/backend.rs | 23 ++++++++++++++++++++++- launcher/src/main.rs | 31 ++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index d12dcd13c..02131cb42 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -558,7 +558,26 @@ pub fn install(release: &Release, progress: impl Fn(f32)) -> Result<(), String> } pub fn remove(tag: &str) -> Result<(), String> { - fs::remove_dir_all(version_dir(tag)).map_err(|e| e.to_string()) + let dir = version_dir(tag); + // Windows keeps a handle on a file for a moment after the game, a scan or the launcher's own + // reader lets go of it, and remove_dir_all stops at the first one: a removal that already + // took most of the folder reported os error 5 while the rest of it did go. Retry, and treat a + // folder that is already gone as done. + let mut last = None; + for attempt in 0..5 { + match fs::remove_dir_all(&dir) { + Ok(()) => return Ok(()), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(()), + Err(e) => last = Some(e), + } + if attempt < 4 { + std::thread::sleep(std::time::Duration::from_millis(250)); + } + } + Err(match last { + Some(e) => e.to_string(), + None => format!("could not remove {}", dir.display()), + }) } /// The Minecraft version a Horizon build targets, from its research-lock.json. @@ -2170,6 +2189,8 @@ pub enum Msg { Links(Links), Progress(String, f32), Installed(String, Result<(), String>), + /// A removal finished off the UI thread. + Removed(String, Result<(), String>), Line(Job, String), Exit(Job, Result<(), String>), Updates(Result), diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 4a68ecdef..fd7e3d343 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -144,6 +144,9 @@ struct Launcher { releases: Load>, installed: Vec, installing: Option<(String, f32)>, + /// The version being deleted: the removal runs off the UI thread, so the window has to know + /// which row is busy until `Msg::Removed` arrives. + removing: Option, install_error: Option<(String, String)>, confirm_remove: Option, picker_open: bool, @@ -286,6 +289,7 @@ impl Launcher { releases: Load::Loading, installed, installing: None, + removing: None, install_error: None, confirm_remove: None, picker_open: false, @@ -516,6 +520,16 @@ impl Launcher { self.bar = (self.bar.1, p); self.installing = Some((tag, p)); } + Msg::Removed(tag, result) => { + self.removing = None; + self.installed = backend::installed(); + self.settings.selected = Settings::load() + .selected + .or_else(|| self.installed.first().cloned()); + if let Err(e) = result { + self.install_error = Some((tag, e)); + } + } Msg::Installed(tag, result) => { self.installing = None; self.bar = (0., 0.); @@ -725,14 +739,16 @@ impl Launcher { } fn remove(&mut self, tag: &str) { - if let Err(e) = backend::remove_version(tag) { - self.install_error = Some((tag.to_string(), e)); - } + // Same shape as install: the folder is hundreds of megabytes and Windows may hold a file + // for a moment, so the deletion goes to a thread instead of stalling the window. + let (tag, tx) = (tag.to_string(), self.tx.clone()); + self.removing = Some(tag.clone()); self.confirm_remove = None; - self.installed = backend::installed(); - self.settings.selected = Settings::load() - .selected - .or_else(|| self.installed.first().cloned()); + self.install_error = None; + std::thread::spawn(move || { + let result = backend::remove_version(&tag); + let _ = tx.send(Msg::Removed(tag, result)); + }); } fn prepare(&mut self) { @@ -2921,6 +2937,7 @@ impl Launcher { let keep = |i: usize| { let tag = &releases[i].tag; self.installing.as_ref().is_some_and(|(t, _)| t == tag) + || self.removing.as_deref() == Some(tag.as_str()) || self.install_error.as_ref().is_some_and(|(t, _)| t == tag) || self.confirm_remove.as_ref() == Some(tag) }; From a61c7faa230357ab24c512c1d456ac95e5c8300c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 09:34:02 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Launcher:=20a=20version=20being=20removed?= =?UTF-8?q?=20shows=20Removing=E2=80=A6=20instead=20of=20its=20buttons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the removal off the UI thread, the row kept its Use and Remove buttons, so a second Remove or Use could race the deletion. The retry loop also reads as one match now. Co-Authored-By: Claude Opus 5.5 --- launcher/src/backend.rs | 25 +++++++++---------------- launcher/src/main.rs | 6 ++++++ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index 02131cb42..256867383 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -559,25 +559,18 @@ pub fn install(release: &Release, progress: impl Fn(f32)) -> Result<(), String> pub fn remove(tag: &str) -> Result<(), String> { let dir = version_dir(tag); - // Windows keeps a handle on a file for a moment after the game, a scan or the launcher's own - // reader lets go of it, and remove_dir_all stops at the first one: a removal that already - // took most of the folder reported os error 5 while the rest of it did go. Retry, and treat a - // folder that is already gone as done. - let mut last = None; - for attempt in 0..5 { + // Windows holds a file for a moment after the game, a scan or the launcher's own reader lets + // go of it, and remove_dir_all stops at the first one. Retry for a second; a folder that is + // already gone is removed. + for attempt in 1.. { match fs::remove_dir_all(&dir) { - Ok(()) => return Ok(()), - Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(()), - Err(e) => last = Some(e), - } - if attempt < 4 { - std::thread::sleep(std::time::Duration::from_millis(250)); + Ok(()) => break, + Err(e) if e.kind() == std::io::ErrorKind::NotFound => break, + Err(e) if attempt == 5 => return Err(e.to_string()), + Err(_) => std::thread::sleep(std::time::Duration::from_millis(250)), } } - Err(match last { - Some(e) => e.to_string(), - None => format!("could not remove {}", dir.display()), - }) + Ok(()) } /// The Minecraft version a Horizon build targets, from its research-lock.json. diff --git a/launcher/src/main.rs b/launcher/src/main.rs index fd7e3d343..5e1498fd6 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -2976,6 +2976,12 @@ impl Launcher { .child(format!("{:.0}%", p * 100.)), ) .into_any_element() + } else if self.removing.as_deref() == Some(tag.as_str()) { + // No Use or Remove while the folder is going. + text(theme::CAPTION) + .text_color(t.muted) + .child("Removing…") + .into_any_element() } else if installed { let confirming = self.confirm_remove.as_ref() == Some(&tag); let (t1, t2) = (tag.clone(), tag.clone());