From 16e7e66230b83c496d6468a3d4676695407b01e5 Mon Sep 17 00:00:00 2001 From: Walnut <39544927+Walnut356@users.noreply.github.com> Date: Sun, 6 Sep 2026 01:43:50 -0500 Subject: [PATCH] don't return an error when trying to delete a file/dir that doesn't exist --- src/dist/component/tests.rs | 20 ++------------------ src/dist/component/transaction.rs | 31 ++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/dist/component/tests.rs b/src/dist/component/tests.rs index b5a5a2b6fc..170d10ae85 100644 --- a/src/dist/component/tests.rs +++ b/src/dist/component/tests.rs @@ -206,15 +206,7 @@ fn remove_file_that_not_exists() { let cx = DistContext::new(None).unwrap(); let mut tx = cx.transaction(); - let err = tx.remove_file("c", PathBuf::from("foo")).unwrap_err(); - - match err.downcast_ref::() { - Some(RustupError::ComponentMissingFile { name, path }) => { - assert_eq!(name, "c"); - assert_eq!(path.clone(), PathBuf::from("foo")); - } - _ => panic!(), - } + tx.remove_file("c", PathBuf::from("foo")).unwrap(); } #[test] @@ -252,15 +244,7 @@ fn remove_dir_that_not_exists() { let cx = DistContext::new(None).unwrap(); let mut tx = cx.transaction(); - let err = tx.remove_dir("c", PathBuf::from("foo")).unwrap_err(); - - match err.downcast_ref::() { - Some(RustupError::ComponentMissingDir { name, path }) => { - assert_eq!(name, "c"); - assert_eq!(path.clone(), PathBuf::from("foo")); - } - _ => panic!(), - } + tx.remove_dir("c", PathBuf::from("foo")).unwrap(); } #[test] diff --git a/src/dist/component/transaction.rs b/src/dist/component/transaction.rs index c1cafa3e8b..fa210df464 100644 --- a/src/dist/component/transaction.rs +++ b/src/dist/component/transaction.rs @@ -14,7 +14,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use anyhow::{Context, Result, anyhow}; -use tracing::{error, info}; +use tracing::{error, info, warn}; use crate::dist::prefix::InstallPrefix; use crate::dist::temp; @@ -97,11 +97,16 @@ impl Transaction { let abs_path = self.prefix.abs_path(&relpath); let backup = self.tmp_cx.new_file()?; if !utils::path_exists(&abs_path) { - return Err(RustupError::ComponentMissingFile { - name: component.to_owned(), - path: relpath, - } - .into()); + // If the file doesn't exist, that's fine, since we would just be deleting it anyway + + warn!( + "{}", + RustupError::ComponentMissingFile { + name: component.to_owned(), + path: relpath + } + ); + return Ok(()); } utils::rename("component", &abs_path, &backup, self.permit_copy_rename)?; @@ -116,11 +121,15 @@ impl Transaction { let abs_path = self.prefix.abs_path(&relpath); let backup = self.tmp_cx.new_directory()?; if !utils::path_exists(&abs_path) { - return Err(RustupError::ComponentMissingDir { - name: component.to_owned(), - path: relpath, - } - .into()); + warn!( + "{}", + RustupError::ComponentMissingDir { + name: component.to_owned(), + path: relpath + } + ); + // If the dir doesn't exist, that's fine, since we would just be deleting it anyway + return Ok(()); } utils::rename(