diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index 2f63951c8..270f856a0 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -558,7 +558,19 @@ 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 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(()) => 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)), + } + } + Ok(()) } /// The Minecraft version a Horizon build targets, from its research-lock.json.