Skip to content

Commit 2b7c96f

Browse files
committed
Merge pull request #400 from brson/hyperstuff
Various networking fixes
2 parents 96fca4c + 13ba54d commit 2b7c96f

25 files changed

+1004
-340
lines changed

Cargo.lock

Lines changed: 126 additions & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ rustup-utils = { path = "src/rustup-utils", version = "0.1.9" }
2323
error-chain = { path = "src/error-chain", version = "0.1.9" }
2424
clap = "2.2.4"
2525
regex = "0.1.41"
26-
openssl = "0.7.2"
27-
hyper = "0.7.0"
26+
url = "1.1.0"
2827
term = "0.4.4"
2928
itertools = "0.4.1"
3029
time = "0.1.34"
@@ -34,25 +33,7 @@ rand = "0.3.11"
3433
scopeguard = "0.1.2"
3534
rustc-serialize = "0.3"
3635

37-
[target.x86_64-pc-windows-gnu.dependencies]
38-
winapi = "0.2.4"
39-
winreg = "0.3.2"
40-
user32-sys = "0.1.2"
41-
kernel32-sys = "0.2.1"
42-
43-
[target.x86_64-pc-windows-msvc.dependencies]
44-
winapi = "0.2.4"
45-
winreg = "0.3.2"
46-
user32-sys = "0.1.2"
47-
kernel32-sys = "0.2.1"
48-
49-
[target.i686-pc-windows-gnu.dependencies]
50-
winapi = "0.2.4"
51-
winreg = "0.3.2"
52-
user32-sys = "0.1.2"
53-
kernel32-sys = "0.2.1"
54-
55-
[target.i686-pc-windows-msvc.dependencies]
36+
[target."cfg(windows)".dependencies]
5637
winapi = "0.2.4"
5738
winreg = "0.3.2"
5839
user32-sys = "0.1.2"

appveyor.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,11 @@ install:
2121
.\rust-nightly.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null
2222
$env:PATH="$env:PATH;C:\rust\bin"
2323
24-
New-Item .cargo -type directory
25-
Copy-Item ci/appveyor-cargo-config.toml .cargo/config
26-
2724
# For -gnu builds
2825
if ($env:TARGET -match "-gnu$") {
2926
$env:PATH="$env:PATH;C:\msys64\mingw${env:BITS}\bin"
3027
}
3128
32-
# For -msvc builds
33-
if ($env:TARGET -match "-msvc$") {
34-
Start-FileDownload "http://www.npcglib.org/~stathis/downloads/openssl-1.0.2d-vs2015.7z" -FileName "openssl.7z"
35-
7z x openssl.7z -o"C:\OpenSSL" | Out-Null
36-
}
37-
3829
# Print version info
3930
rustc -vV
4031
cargo -vV

ci/appveyor-cargo-config.toml

Lines changed: 0 additions & 19 deletions
This file was deleted.

ci/run-docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export LD_LIBRARY_PATH=/travis-rust/lib:$LD_LIBRARY_PATH
1818
# distribute (this can be changed by others of course).
1919
# ==============================================================================
2020

21-
OPENSSL_VERS=1.0.2g
22-
OPENSSL_SHA256=b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33
21+
OPENSSL_VERS=1.0.2h
22+
OPENSSL_SHA256=1d4007e53aad94a5b2002fe045ee7bb0b3d98f1a47f8b2bc851dcd1c74332919
2323

2424
case $TARGET in
2525
x86_64-*-linux-*)

src/rustup-cli/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ extern crate error_chain;
99
#[macro_use]
1010
extern crate clap;
1111
extern crate regex;
12-
extern crate hyper;
1312
#[macro_use]
1413
extern crate rustup;
1514
extern crate term;
16-
extern crate openssl;
1715
extern crate itertools;
1816
extern crate time;
1917
extern crate rand;

src/rustup-cli/self_update.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ use rustup::{NotifyHandler};
3636
use errors::*;
3737
use rustup_dist::dist;
3838
use rustup_utils::utils;
39-
use openssl::crypto::hash::{Type, Hasher};
39+
use rustup_utils::sha2::{Sha256, Digest};
4040
use std::env;
4141
use std::env::consts::EXE_SUFFIX;
4242
use std::path::{Path, PathBuf};
4343
use std::process::{self, Command};
44-
use std::fs;
44+
use std::fs::{self, File};
45+
use std::io::Read;
4546
use tempdir::TempDir;
4647

4748
pub struct InstallOpts {
@@ -1038,12 +1039,18 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
10381039
let url = format!("{}/{}/rustup-init{}", update_root, triple, EXE_SUFFIX);
10391040

10401041
// Calculate own hash
1041-
let mut hasher = Hasher::new(Type::SHA256);
1042-
try!(utils::tee_file("self", multirust_path, &mut hasher));
1043-
let current_hash = hasher.finish()
1044-
.iter()
1045-
.map(|b| format!("{:02x}", b))
1046-
.join("");
1042+
let mut hasher = Sha256::new();
1043+
let mut self_exe = try!(File::open(multirust_path)
1044+
.chain_err(|| "can't open self exe to calculate hash"));
1045+
let ref mut buf = [0; 4096];
1046+
loop {
1047+
let bytes = try!(self_exe.read(buf)
1048+
.chain_err(|| "failed to read from self exe while calculating hash"));
1049+
if bytes == 0 { break; }
1050+
hasher.input(&buf[0..bytes]);
1051+
}
1052+
let current_hash = hasher.result_str();
1053+
drop(self_exe);
10471054

10481055
// Download latest hash
10491056
info!("checking for self-updates");
@@ -1064,15 +1071,12 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
10641071

10651072
// Download new version
10661073
info!("downloading self-update");
1067-
let mut hasher = Hasher::new(Type::SHA256);
1074+
let mut hasher = Sha256::new();
10681075
try!(utils::download_file(download_url,
10691076
&setup_path,
10701077
Some(&mut hasher),
10711078
ntfy!(&NotifyHandler::none())));
1072-
let download_hash = hasher.finish()
1073-
.iter()
1074-
.map(|b| format!("{:02x}", b))
1075-
.join("");
1079+
let download_hash = hasher.result_str();
10761080

10771081
// Check that hash is correct
10781082
if latest_hash != download_hash {

src/rustup-dist/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ license = "MIT OR Apache-2.0"
1414

1515
[dependencies]
1616
regex = "0.1.41"
17-
hyper = "0.7.0"
18-
openssl = "0.7.2"
1917
itertools = "0.4.1"
2018
ole32-sys = "0.2.0"
19+
url = "1.1.0"
2120
tar = "0.4.0"
2221
flate2 = "0.2.9"
2322
tempdir = "0.3.4"

src/rustup-dist/src/dist.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::path::Path;
1212
use std::fmt;
1313

1414
use regex::Regex;
15-
use openssl::crypto::hash::{Type, Hasher};
15+
use rustup_utils::sha2::{Sha256, Digest};
1616
use itertools::Itertools;
1717

1818
pub const DEFAULT_DIST_ROOT: &'static str = "https://static.rust-lang.org/dist";
@@ -341,12 +341,9 @@ pub fn download_and_check<'a>(url_str: &str,
341341
let url = try!(utils::parse_url(url_str));
342342
let file = try!(cfg.temp_cfg.new_file_with_ext("", ext));
343343

344-
let mut hasher = Hasher::new(Type::SHA256);
344+
let mut hasher = Sha256::new();
345345
try!(utils::download_file(url, &file, Some(&mut hasher), ntfy!(&cfg.notify_handler)));
346-
let actual_hash = hasher.finish()
347-
.iter()
348-
.map(|b| format!("{:02x}", b))
349-
.join("");
346+
let actual_hash = hasher.result_str();
350347

351348
if hash != actual_hash {
352349
// Incorrect hash

src/rustup-dist/src/download.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use notifications::*;
33
use rustup_utils::utils;
44
use temp;
55

6-
use openssl::crypto::hash::{Type, Hasher};
7-
use itertools::Itertools;
6+
use rustup_utils::sha2::{Sha256, Digest};
87

98
use std::path::Path;
109
use std::process::Command;
@@ -66,7 +65,7 @@ impl<'a> DownloadCfg<'a> {
6665
try!(utils::download_file(hash_url, &hash_file, None, ntfy!(&self.notify_handler)));
6766

6867
let hash = try!(utils::read_file("hash", &hash_file).map(|s| s[0..64].to_owned()));
69-
let mut hasher = Hasher::new(Type::SHA256);
68+
let mut hasher = Sha256::new();
7069

7170
let target_url = try!(utils::parse_url(url));
7271
let target_file = try!(self.temp_cfg.new_file());
@@ -75,10 +74,7 @@ impl<'a> DownloadCfg<'a> {
7574
Some(&mut hasher),
7675
ntfy!(&self.notify_handler)));
7776

78-
let actual_hash = hasher.finish()
79-
.iter()
80-
.map(|b| format!("{:02x}", b))
81-
.join("");
77+
let actual_hash = hasher.result_str();
8278

8379
if hash != actual_hash {
8480
// Incorrect hash

src/rustup-dist/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![recursion_limit = "1024"]
22

3-
extern crate hyper;
43
extern crate regex;
5-
extern crate openssl;
64
extern crate itertools;
75
extern crate tempdir;
86
extern crate walkdir;

src/rustup-dist/src/manifestation.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use errors::*;
1010
use notifications::*;
1111
use rustup_utils::utils;
1212
use prefix::InstallPrefix;
13-
use openssl::crypto::hash::{Type, Hasher};
13+
use rustup_utils::sha2::{Sha256, Digest};
1414
use itertools::Itertools;
1515
use std::path::Path;
1616

@@ -135,14 +135,11 @@ impl Manifestation {
135135
let temp_file = try!(temp_cfg.new_file());
136136
let url_url = try!(utils::parse_url(&url));
137137

138-
let mut hasher = Hasher::new(Type::SHA256);
138+
let mut hasher = Sha256::new();
139139
try!(utils::download_file(url_url, &temp_file, Some(&mut hasher), ntfy!(&notify_handler))
140140
.chain_err(|| ErrorKind::ComponentDownloadFailed(component.clone())));
141141

142-
let actual_hash = hasher.finish()
143-
.iter()
144-
.map(|b| format!("{:02x}", b))
145-
.join("");
142+
let actual_hash = hasher.result_str();
146143

147144
if hash != actual_hash {
148145
// Incorrect hash

src/rustup-dist/tests/dist.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ extern crate rustup_utils;
66
extern crate rustup_mock;
77
extern crate tempdir;
88
extern crate tar;
9-
extern crate openssl;
109
extern crate toml;
1110
extern crate flate2;
1211
extern crate walkdir;
1312
extern crate itertools;
14-
extern crate hyper;
13+
extern crate url;
1514

1615
use rustup_mock::dist::*;
1716
use rustup_mock::{MockCommand, MockInstallerBuilder};
@@ -25,7 +24,7 @@ use rustup_utils::raw as utils_raw;
2524
use rustup_dist::temp;
2625
use rustup_dist::manifestation::{Manifestation, UpdateStatus, Changes};
2726
use rustup_dist::manifest::{Manifest, Component};
28-
use hyper::Url;
27+
use url::Url;
2928
use std::fs;
3029
use std::io::Write;
3130
use std::path::Path;
@@ -278,7 +277,7 @@ fn update_from_dist(dist_server: &Url,
278277
notify_handler: notify_handler.clone(),
279278
gpg_key: None,
280279
};
281-
let manifest_file = try!(download.get(&manifest_url.serialize()));
280+
let manifest_file = try!(download.get(manifest_url.as_str()));
282281
let manifest_str = try!(utils::read_file("manifest", &manifest_file));
283282
let manifest = try!(Manifest::parse(&manifest_str));
284283

@@ -295,15 +294,9 @@ fn update_from_dist(dist_server: &Url,
295294
}
296295

297296
fn make_manifest_url(dist_server: &Url, toolchain: &ToolchainDesc) -> Result<Url> {
298-
let mut url = dist_server.clone();
299-
if let Some(mut p) = url.path_mut() {
300-
p.push(format!("dist/channel-rust-{}.toml", toolchain.channel));
301-
} else {
302-
// FIXME
303-
panic!()
304-
}
297+
let url = format!("{}/dist/channel-rust-{}.toml", dist_server, toolchain.channel);
305298

306-
Ok(url)
299+
Ok(Url::parse(&url).unwrap())
307300
}
308301

309302
fn uninstall(toolchain: &ToolchainDesc, prefix: &InstallPrefix, temp_cfg: &temp::Cfg,

src/rustup-mock/Cargo.toml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,17 @@ homepage = "https://github.com/rust-lang-nursery/rustup.rs"
1010
repository = "https://github.com/rust-lang-nursery/rustup.rs"
1111

1212
[dependencies]
13-
hyper = "0.7.0"
13+
url = "1.1.0"
1414
scopeguard = "0.1.2"
1515
lazy_static = "0.1.15"
1616
walkdir = "0.1.5"
1717
flate2 = "0.2.9"
1818
tempdir = "0.3.4"
19-
openssl = "0.7.2"
2019
itertools = "0.4.1"
2120
tar = "0.4.0"
2221
toml = "0.1.27"
22+
rustup-utils = { path = "../rustup-utils", version = "0.1.9" }
2323

24-
[target.x86_64-pc-windows-gnu.dependencies]
25-
winapi = "0.2.4"
26-
winreg = "0.3.2"
27-
28-
[target.x86_64-pc-windows-msvc.dependencies]
29-
winapi = "0.2.4"
30-
winreg = "0.3.2"
31-
32-
[target.i686-pc-windows-gnu.dependencies]
33-
winapi = "0.2.4"
34-
winreg = "0.3.2"
35-
36-
[target.i686-pc-windows-msvc.dependencies]
24+
[target."cfg(windows)".dependencies]
3725
winapi = "0.2.4"
3826
winreg = "0.3.2"

src/rustup-mock/src/clitools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use {MockInstallerBuilder, MockCommand};
1313
use dist::{MockDistServer, MockChannel, MockPackage,
1414
MockTargettedPackage, MockComponent, change_channel_date,
1515
ManifestVersion};
16-
use hyper::Url;
16+
use url::Url;
1717
use scopeguard;
1818

1919
/// The configuration used by the tests in this module

src/rustup-mock/src/dist.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
//! distribution server, with v1 and v2 manifests.
33
44
use MockInstallerBuilder;
5-
use hyper::Url;
5+
use url::Url;
66
use std::path::{PathBuf, Path};
77
use std::fs::{self, File};
88
use std::collections::HashMap;
99
use std::io::{Read, Write};
1010
use tempdir::TempDir;
11-
use openssl::crypto::hash;
11+
use rustup_utils::sha2::{Sha256, Digest};
1212
use itertools::Itertools;
1313
use toml;
1414
use flate2;
@@ -304,9 +304,9 @@ fn create_tarball(relpath: &Path, src: &Path, dst: &Path) {
304304
pub fn calc_hash(src: &Path) -> String {
305305
let ref mut buf = Vec::new();
306306
File::open(src).unwrap().read_to_end(buf).unwrap();
307-
let mut hasher = hash::Hasher::new(hash::Type::SHA256);
308-
hasher.write_all(&buf).unwrap();
309-
let hex = hasher.finish().iter().map(|b| format!("{:02x}", b)).join("");
307+
let mut hasher = Sha256::new();
308+
hasher.input(buf);
309+
let hex = hasher.result_str();
310310

311311
hex
312312
}

0 commit comments

Comments
 (0)