Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ pub(crate) fn uninstall(

// Delete rustup.
#[cfg(unix)]
clean_cargo_home(no_modify_path, process)?;
clean_cargo_home(no_modify_path, process, &cargo_home)?;
// NOTE: On windows, this is tricky because this is *probably*
// the running executable and on Windows can't be unlinked until
// the process exits.
Expand All @@ -1003,20 +1003,23 @@ pub(crate) fn uninstall(
/// This removes non-`bin` entries in `$CARGO_HOME`, removes rustup tool links and executable from
/// `$CARGO_HOME/bin`, then removes `$CARGO_HOME/bin` and `$CARGO_HOME` only if they are empty.
/// Nonempty directories are left in place.
fn clean_cargo_home(no_modify_path: bool, process: &Process) -> anyhow::Result<()> {
let cargo_home = process.cargo_home()?;
fn clean_cargo_home(
no_modify_path: bool,
process: &Process,
cargo_home: &Path,
) -> anyhow::Result<()> {
let cargo_bin = cargo_home.join("bin");

info!("removing cargo home");

// Delete everything in CARGO_HOME except the bin directory first.
let diriter = fs::read_dir(&cargo_home).map_err(|e| CliError::ReadDirError {
p: cargo_home.clone(),
let diriter = fs::read_dir(cargo_home).map_err(|e| CliError::ReadDirError {
p: cargo_home.to_owned(),
source: e,
})?;
for dirent in diriter {
let dirent = dirent.map_err(|e| CliError::ReadDirError {
p: cargo_home.clone(),
p: cargo_home.to_owned(),
source: e,
})?;
if dirent.file_name().to_str() != Some("bin") {
Expand Down Expand Up @@ -1070,7 +1073,7 @@ fn clean_cargo_home(no_modify_path: bool, process: &Process) -> anyhow::Result<(
let cargo_home_display = cargo_home.display();
info!("removing empty cargo home directory `{cargo_home_display}`");

match fs::remove_dir(&cargo_home) {
match fs::remove_dir(cargo_home) {
Err(e) if e.kind() == io::ErrorKind::DirectoryNotEmpty => {
warn!("keeping non-empty cargo home directory `{cargo_home_display}`");
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/self_update/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ pub fn complete_windows_uninstall(process: &Process) -> anyhow::Result<utils::Ex
let no_modify_path = process.var_os(GC_MODIFY_PATH).as_deref() != Some(OsStr::new("1"));

// Now that the parent has exited there are hopefully no more files open in CARGO_HOME.
super::clean_cargo_home(no_modify_path, process)?;
let cargo_home = process.cargo_home()?;
super::clean_cargo_home(no_modify_path, process, &cargo_home)?;

// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
// handle to *this* process, then exit. The OS will delete the gc
Expand Down
Loading