Skip to content

Commit

Permalink
Change upstream via $RUSTUP_DIST_SERVER
Browse files Browse the repository at this point in the history
  • Loading branch information
Knight authored and Knight committed Jun 11, 2016
1 parent 3bae543 commit a4aa240
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 21 additions & 1 deletion src/rustup-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ use rustup_utils::utils;
use prefix::InstallPrefix;
use sha2::{Sha256, Digest};
use std::path::Path;
use std::env;
use std::borrow::Cow;

pub const DIST_MANIFEST: &'static str = "multirust-channel-manifest.toml";
pub const CONFIG_FILE: &'static str = "multirust-config.toml";
pub const DEFAULT_STATIC_SITE: &'static str = "https://static.rust-lang.org";

#[derive(Debug)]
pub struct Manifestation {
Expand Down Expand Up @@ -122,13 +125,24 @@ impl Manifestation {
components_urls_and_hashes.push(c_u_h);
}

let static_site = env::var("RUSTUP_DIST_SERVER")
.ok()
.map_or(DEFAULT_STATIC_SITE.into(), Cow::Owned);
let altered = !static_site.is_empty() && static_site != DEFAULT_STATIC_SITE;

// Download component packages and validate hashes
let mut things_to_install: Vec<(Component, temp::File)> = Vec::new();
for (component, url, hash) in components_urls_and_hashes {

notify_handler(Notification::DownloadingComponent(&component.pkg,
&self.target_triple,
&component.target));
let url = if altered {
// Replace DEFAULT_STATIC_SITE if possible
url.replace(DEFAULT_STATIC_SITE, static_site.as_ref())
} else {
url
};

// Download each package to temp file
let temp_file = try!(temp_cfg.new_file());
Expand Down Expand Up @@ -301,7 +315,13 @@ impl Manifestation {
return Err(format!("binary package was not provided for '{}'",
self.target_triple.to_string()).into());
}
let url = url.unwrap();
let static_site = env::var("RUSTUP_DIST_SERVER")
.into_iter()
.filter(|s| !s.is_empty())
.next()
.map_or(DEFAULT_STATIC_SITE.into(), Cow::Owned);
// Only replace once. The cost is inexpensive.
let url = url.unwrap().replace(DEFAULT_STATIC_SITE, static_site.as_ref());

notify_handler(Notification::DownloadingComponent("rust",
&self.target_triple,
Expand Down
20 changes: 16 additions & 4 deletions src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,22 @@ impl Cfg {
.ok()
.and_then(utils::if_not_empty);

let dist_root_url = env::var("RUSTUP_DIST_ROOT")
.ok()
.and_then(utils::if_not_empty)
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned);
let dist_root_url = match env::var("RUSTUP_DIST_SERVER") {
Ok(ref s) if !s.is_empty() => {
let mut res = String::with_capacity(s.len() + 5);
// RUSTUP_DIST_SERVER only contains the server name
res.push_str(s);
res.push_str("/dist");
Cow::Owned(res)
}
_ => {
// For backward compatibility
env::var("RUSTUP_DIST_ROOT")
.ok()
.and_then(utils::if_not_empty)
.map_or(Cow::Borrowed(dist::DEFAULT_DIST_ROOT), Cow::Owned)
}
};

Ok(Cfg {
multirust_dir: multirust_dir,
Expand Down

0 comments on commit a4aa240

Please sign in to comment.