Skip to content

Commit 2f44813

Browse files
committed
future-proof adding more protocols
1 parent 77097c5 commit 2f44813

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/bootstrap/builder.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -873,11 +873,20 @@ impl<'a> Builder<'a> {
873873
pub(crate) fn download_component(&self, url: &str, dest_path: &Path, help_on_error: &str) {
874874
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
875875
let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
876-
self.download_with_retries(&tempfile, url, help_on_error);
876+
// While bootstrap itself only supports http and https downloads, downstream forks might
877+
// need to download components from other protocols. The match allows them adding more
878+
// protocols without worrying about merge conficts if we change the HTTP implementation.
879+
match url.split_once("://").map(|(proto, _)| proto) {
880+
Some("http") | Some("https") => {
881+
self.download_http_with_retries(&tempfile, url, help_on_error)
882+
}
883+
Some(other) => panic!("unsupported protocol {other} in {url}"),
884+
None => panic!("no protocol in {url}"),
885+
}
877886
t!(std::fs::rename(&tempfile, dest_path));
878887
}
879888

880-
fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
889+
fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
881890
println!("downloading {}", url);
882891
// Try curl. If that fails and we are on windows, fallback to PowerShell.
883892
let mut curl = Command::new("curl");

0 commit comments

Comments
 (0)