about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPietro Albini <pietro.albini@ferrous-systems.com>2022-06-07 14:50:14 +0200
committerPietro Albini <pietro.albini@ferrous-systems.com>2022-06-09 19:43:23 +0200
commit2f44813511277b6d15dc993bd79e7432dec334e1 (patch)
tree018f3882f1e90152db24a4bfae9eeb99bb0edaba
parent77097c5da87338e4964b8a717466beb2346f480c (diff)
downloadrust-2f44813511277b6d15dc993bd79e7432dec334e1.tar.gz
rust-2f44813511277b6d15dc993bd79e7432dec334e1.zip
future-proof adding more protocols
-rw-r--r--src/bootstrap/builder.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index abd99233e0c..7b74c5ccdbb 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -873,11 +873,20 @@ impl<'a> Builder<'a> {
     pub(crate) fn download_component(&self, url: &str, dest_path: &Path, help_on_error: &str) {
         // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
         let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
-        self.download_with_retries(&tempfile, url, help_on_error);
+        // While bootstrap itself only supports http and https downloads, downstream forks might
+        // need to download components from other protocols. The match allows them adding more
+        // protocols without worrying about merge conficts if we change the HTTP implementation.
+        match url.split_once("://").map(|(proto, _)| proto) {
+            Some("http") | Some("https") => {
+                self.download_http_with_retries(&tempfile, url, help_on_error)
+            }
+            Some(other) => panic!("unsupported protocol {other} in {url}"),
+            None => panic!("no protocol in {url}"),
+        }
         t!(std::fs::rename(&tempfile, dest_path));
     }
 
-    fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
+    fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
         println!("downloading {}", url);
         // Try curl. If that fails and we are on windows, fallback to PowerShell.
         let mut curl = Command::new("curl");