Skip to content

Commit ac249c8

Browse files
manyinsectsrami3l
authored andcommitted
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 6f630cf commit ac249c8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cli/self_update.rs

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

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

933+
check_proxy_sanity(process, components, desc)?;
934+
910935
cfg.set_default(Some(&desc.into()))?;
911936
writeln!(process.stdout().lock())?;
912937
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+
"rustup executable proxies don't seem to work\n\
146+
help: this might be a bug in rustup, please open a new issue here:\n\
147+
help: https://github.com/rust-lang/rustup/issues/new"
148+
)]
149+
BrokenProxy,
144150
#[error("unknown metadata version: '{0}'")]
145151
UnknownMetadataVersion(String),
146152
#[error("manifest version '{0}' is not supported")]

0 commit comments

Comments
 (0)