diff --git a/src/errors.rs b/src/errors.rs index d8273c1bac..df95c75b55 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -2,7 +2,6 @@ use std::ffi::OsString; use std::fmt::Debug; -#[cfg(not(windows))] use std::io; use std::io::Write; use std::path::PathBuf; @@ -77,6 +76,13 @@ pub enum RustupError { RemovingDirectory { name: &'static str, path: PathBuf }, #[error("could not remove '{name}' file: '{}'", .path.display())] RemovingFile { name: &'static str, path: PathBuf }, + #[error("could not rename '{name}' file from '{src}' to '{dest}': {source}")] + RenamingFile { + name: &'static str, + src: PathBuf, + dest: PathBuf, + source: io::Error, + }, #[error("{}", component_unavailable_msg(.components, .manifest, .toolchain))] RequestedComponentsUnavailable { components: Vec, diff --git a/src/utils/mod.rs b/src/utils/mod.rs index a3639cc978..d1973706a8 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -471,13 +471,14 @@ where }, }, ) - .with_context(|| { - format!( - "could not rename {} file from '{}' to '{}'", + .map_err(|e| { + RustupError::RenamingFile { name, - src.display(), - dest.display() - ) + src: PathBuf::from(src), + dest: PathBuf::from(dest), + source: e.error, + } + .into() }) }