Skip to content

Add support for XZ-compressed packages #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rustup-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ole32-sys = "0.2.0"
url = "1.1.0"
tar = "0.4.0"
flate2 = "0.2.9"
xz2 = "0.1.3"
tempdir = "0.3.4"
walkdir = "0.1.5"
toml = "0.1.27"
Expand Down
33 changes: 33 additions & 0 deletions src/rustup-dist/src/component/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

extern crate tar;
extern crate flate2;
extern crate xz2;

use component::components::*;
use component::transaction::*;
Expand Down Expand Up @@ -261,3 +262,35 @@ impl<'a> Package for TarGzPackage<'a> {
self.0.components()
}
}

#[derive(Debug)]
pub struct TarXzPackage<'a>(TarPackage<'a>);

impl<'a> TarXzPackage<'a> {
pub fn new<R: Read>(stream: R, temp_cfg: &'a temp::Cfg) -> Result<Self> {
let stream = xz2::read::XzDecoder::new(stream);

Ok(TarXzPackage(try!(TarPackage::new(stream, temp_cfg))))
}
pub fn new_file(path: &Path, temp_cfg: &'a temp::Cfg) -> Result<Self> {
let file = try!(File::open(path).chain_err(|| ErrorKind::ExtractingPackage));
Self::new(file, temp_cfg)
}
}

impl<'a> Package for TarXzPackage<'a> {
fn contains(&self, component: &str, short_name: Option<&str>) -> bool {
self.0.contains(component, short_name)
}
fn install<'b>(&self,
target: &Components,
component: &str,
short_name: Option<&str>,
tx: Transaction<'b>)
-> Result<Transaction<'b>> {
self.0.install(target, component, short_name, tx)
}
fn components(&self) -> Vec<String> {
self.0.components()
}
}
4 changes: 4 additions & 0 deletions src/rustup-dist/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub struct TargetedPackage {
pub available: bool,
pub url: String,
pub hash: String,
pub xz_url: Option<String>,
pub xz_hash: Option<String>,
pub components: Vec<Component>,
pub extensions: Vec<Component>,
}
Expand Down Expand Up @@ -230,6 +232,8 @@ impl TargetedPackage {
available: try!(get_bool(&mut table, "available", path)),
url: try!(get_string(&mut table, "url", path)),
hash: try!(get_string(&mut table, "hash", path)),
xz_url: get_string(&mut table, "xz_url", path).ok(),
xz_hash: get_string(&mut table, "xz_hash", path).ok(),
components: try!(Self::toml_to_components(components,
&format!("{}{}.", path, "components"))),
extensions: try!(Self::toml_to_components(extensions,
Expand Down
38 changes: 30 additions & 8 deletions src/rustup-dist/src/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use config::Config;
use manifest::{Component, Manifest, TargetedPackage};
use dist::{TargetTriple, DEFAULT_DIST_SERVER};
use component::{Components, Transaction, TarGzPackage, Package};
use component::{Components, Transaction, TarGzPackage, TarXzPackage, Package};
use temp;
use errors::*;
use notifications::*;
Expand All @@ -16,6 +16,11 @@ use std::path::Path;
pub const DIST_MANIFEST: &'static str = "multirust-channel-manifest.toml";
pub const CONFIG_FILE: &'static str = "multirust-config.toml";

enum Format {
Gz,
Xz,
}

#[derive(Debug)]
pub struct Manifestation {
installation: Components,
Expand Down Expand Up @@ -115,20 +120,26 @@ impl Manifestation {
}

// Map components to urls and hashes
let mut components_urls_and_hashes: Vec<(Component, String, String)> = Vec::new();
let mut components_urls_and_hashes: Vec<(Component, Format, String, String)> = Vec::new();
for component in components_to_install {
let package = try!(new_manifest.get_package(&component.pkg));
let target_package = try!(package.get_target(component.target.as_ref()));
let c_u_h = (component, target_package.url.clone(), target_package.hash.clone());
let c_u_h =
if let (Some(url), Some(hash)) = (target_package.xz_url.clone(),
target_package.xz_hash.clone()) {
(component, Format::Xz, url, hash)
} else {
(component, Format::Gz, target_package.url.clone(), target_package.hash.clone())
};
components_urls_and_hashes.push(c_u_h);
}

let altered = temp_cfg.dist_server != DEFAULT_DIST_SERVER;

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

notify_handler(Notification::DownloadingComponent(&component.pkg,
&self.target_triple,
Expand All @@ -146,7 +157,7 @@ impl Manifestation {
}));
things_downloaded.push(hash);

things_to_install.push((component, dowloaded_file));
things_to_install.push((component, format, dowloaded_file));
}

// Begin transaction
Expand All @@ -167,13 +178,24 @@ impl Manifestation {
}

// Install components
for (component, installer_file) in things_to_install {
for (component, format, installer_file) in things_to_install {

notify_handler(Notification::InstallingComponent(&component.pkg,
&self.target_triple,
component.target.as_ref()));

let package = try!(TarGzPackage::new_file(&installer_file, temp_cfg));
let gz;
let xz;
let package: &Package = match format {
Format::Gz => {
gz = try!(TarGzPackage::new_file(&installer_file, temp_cfg));
&gz
}
Format::Xz => {
xz = try!(TarXzPackage::new_file(&installer_file, temp_cfg));
&xz
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite a fascinating pattern, leaving one local uninitialized. I did not know that was possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustc does not complain, but I guess it might be regarded as bad practice.
It is easy to transform this in a single local that is always assigned by wrapping the two cases in an enum, if it is preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good as is, thanks.


// For historical reasons, the rust-installer component
// names are not the same as the dist manifest component
Expand Down
Loading