Skip to content

Commit 780a1e1

Browse files
committed
feat(self_update): add proxy sanity checks
Sometimes, proxies can be incorrectly installed for whatever reason. This adds a new check after initial component installation to call all proxies with --version, and to fail if one of them doesn't report success.
1 parent 7ba0abf commit 780a1e1

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/cli/self_update.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,33 @@ fn install_proxies_with_opts(process: &Process, force_hard_links: bool) -> Resul
853853
Ok(())
854854
}
855855

856+
fn check_proxy_sanity(
857+
process: &Process,
858+
components: &[&str],
859+
toolchain: &ToolchainDesc,
860+
) -> Result<()> {
861+
let bin_path = process.cargo_home()?.join("bin");
862+
863+
// Sometimes linking a proxy produces an unpredictable result, where the proxy
864+
// is in place, but manages to not call rustup correctly. One way to make sure we
865+
// don't run headfirst into the wall is to at least try and run our freshly
866+
// installed proxies, to see if they return some manner of reasonable output.
867+
// We limit ourselves to the most common two installed components (cargo and rustc),
868+
// because their binary names also happen to match up, which is not necessarily
869+
// a given.
870+
for component in components.iter().filter(|c| ["cargo", "rustc"].contains(c)) {
871+
let cmd = Command::new(bin_path.join(format!("{}{EXE_SUFFIX}", component)))
872+
.args([&format!("+{}", toolchain), "--version"])
873+
.status();
874+
875+
if !cmd.is_ok_and(|status| status.success()) {
876+
return Err(RustupError::InvalidProxyInstall.into());
877+
}
878+
}
879+
880+
Ok(())
881+
}
882+
856883
async fn maybe_install_rust(
857884
current_dir: PathBuf,
858885
quiet: bool,
@@ -907,6 +934,8 @@ async fn maybe_install_rust(
907934
.0
908935
};
909936

937+
check_proxy_sanity(process, components, desc)?;
938+
910939
cfg.set_default(Some(&desc.into()))?;
911940
writeln!(process.stdout().lock())?;
912941
common::show_channel_update(&cfg, PackageUpdate::Toolchain(desc.clone()), Ok(status))?;

src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ pub enum RustupError {
141141
target: TargetTriple,
142142
suggestion: Option<String>,
143143
},
144+
#[error(
145+
"unable to correctly link proxies\n\
146+
this might be a bug in rustup, please open a new issue here:\n\
147+
https://github.com/rust-lang/rustup/issues/new"
148+
)]
149+
InvalidProxyInstall,
144150
#[error("unknown metadata version: '{0}'")]
145151
UnknownMetadataVersion(String),
146152
#[error("manifest version '{0}' is not supported")]

0 commit comments

Comments
 (0)