Skip to content
Open
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
20 changes: 2 additions & 18 deletions src/dist/component/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<RustupError>() {
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]
Expand Down Expand Up @@ -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::<RustupError>() {
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]
Expand Down
31 changes: 20 additions & 11 deletions src/dist/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

@rami3l rami3l Sep 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should keep the API shape (with component: &str). The actual error and this comment line can be converted to warn!() though, where component and path can still be useful.

Same thing for remove_dir() below.

View changes since the review


warn!(
"{}",
RustupError::ComponentMissingFile {
name: component.to_owned(),
path: relpath
}
);
return Ok(());
}

utils::rename("component", &abs_path, &backup, self.permit_copy_rename)?;
Expand All @@ -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(
Expand Down