Skip to content

Commit 6cd83a6

Browse files
committed
fix(windows): attempt GC cleanup after uninstall errors
Attempt the existing GC self-cleanup even if waiting for the parent or removing cargo-home state fails. Preserve the original uninstall error when starting cleanup also fails; report the cleanup error when uninstalling succeeded.
1 parent 03257d2 commit 6cd83a6

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/cli/self_update/windows.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,27 @@ fn has_windows_sdk_libs(process: &Process) -> bool {
380380
/// Run by rustup-gc-$num.exe to delete CARGO_HOME
381381
#[tracing::instrument(level = "trace")]
382382
pub fn complete_windows_uninstall(process: &Process) -> anyhow::Result<utils::ExitCode> {
383-
wait_for_parent()?;
384-
385-
let no_modify_path = process.var_os(GC_MODIFY_PATH).as_deref() != Some(OsStr::new("1"));
383+
let uninstall = wait_for_parent().and_then(|()| {
384+
let no_modify_path = process.var_os(GC_MODIFY_PATH).as_deref() != Some(OsStr::new("1"));
386385

387-
// Now that the parent has exited there are hopefully no more files open in CARGO_HOME.
388-
super::clean_cargo_home(no_modify_path, process)?;
386+
// Now that the parent has exited there are hopefully no more files open in CARGO_HOME.
387+
super::clean_cargo_home(no_modify_path, process)
388+
});
389389

390390
// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
391391
// handle to *this* process, then exit. The OS will delete the gc
392-
// exe when it exits.
392+
// exe when it exits. Do this even if uninstalling failed.
393393
// Leave stdin inherited so the standard library passes GC's delete-on-close
394394
// handle to the cleanup child without raw handle APIs.
395-
Command::new("net")
395+
let cleanup = Command::new("net")
396396
.stdout(Stdio::null())
397397
.stderr(Stdio::null())
398398
.spawn()
399-
.context(CliError::WindowsUninstallMadness)?;
399+
.context(CliError::WindowsUninstallMadness);
400400

401+
// Preserve the original uninstall error if starting cleanup also failed.
402+
uninstall?;
403+
cleanup?;
401404
Ok(utils::ExitCode(0))
402405
}
403406

0 commit comments

Comments
 (0)