Skip to content
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
19 changes: 8 additions & 11 deletions Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ path = "src/cargo/lib.rs"
advapi32-sys = "0.1"
crates-io = { path = "src/crates-io", version = "0.2" }
crossbeam = "0.2"
curl = "0.2"
curl-sys = "0.1"
curl = "0.3"
docopt = "0.6"
env_logger = "0.3"
filetime = "0.1"
flate2 = "0.2"
fs2 = "0.2"
git2 = "0.4"
git2-curl = "0.4"
libgit2-sys = "0.4"
git2-curl = "0.5"
glob = "0.2"
kernel32-sys = "0.2"
libc = "0.2"
libgit2-sys = "0.4"
log = "0.3"
num_cpus = "0.2"
regex = "0.1"
Expand Down
1 change: 0 additions & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
extern crate crates_io as registry;
extern crate crossbeam;
extern crate curl;
extern crate curl_sys;
extern crate docopt;
extern crate filetime;
extern crate flate2;
Expand Down
29 changes: 14 additions & 15 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::env;
use std::fs::{self, File};
use std::iter::repeat;
use std::path::{Path, PathBuf};
use std::time::Duration;

use curl::http;
use curl::easy::Easy;
use git2;
use registry::{Registry, NewCrate, NewCrateDependency};
use term::color::BLACK;
Expand Down Expand Up @@ -156,24 +157,22 @@ pub fn registry(config: &Config,
}

/// Create a new HTTP handle with appropriate global configuration for cargo.
pub fn http_handle(config: &Config) -> CargoResult<http::Handle> {
pub fn http_handle(config: &Config) -> CargoResult<Easy> {
// The timeout option for libcurl by default times out the entire transfer,
// but we probably don't want this. Instead we only set timeouts for the
// connect phase as well as a "low speed" timeout so if we don't receive
// many bytes in a large-ish period of time then we time out.
let handle = http::handle().timeout(0)
.connect_timeout(30_000 /* milliseconds */)
.low_speed_limit(10 /* bytes per second */)
.low_speed_timeout(30 /* seconds */);
let handle = match try!(http_proxy(config)) {
Some(proxy) => handle.proxy(proxy),
None => handle,
};
let handle = match try!(http_timeout(config)) {
Some(timeout) => handle.connect_timeout(timeout as usize)
.low_speed_timeout((timeout as usize) / 1000),
None => handle,
};
let mut handle = Easy::new();
try!(handle.connect_timeout(Duration::new(30, 0)));
try!(handle.low_speed_limit(10 /* bytes per second */));
try!(handle.low_speed_time(Duration::new(30, 0)));
if let Some(proxy) = try!(http_proxy(config)) {
try!(handle.proxy(&proxy));
}
if let Some(timeout) = try!(http_timeout(config)) {
try!(handle.connect_timeout(Duration::new(timeout as u64, 0)));
try!(handle.low_speed_time(Duration::new(timeout as u64, 0)));
}
Ok(handle)
}

Expand Down
38 changes: 24 additions & 14 deletions src/cargo/sources/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ use std::io::SeekFrom;
use std::io::prelude::*;
use std::path::{PathBuf, Path};

use curl::http;
use curl::easy::Easy;
use flate2::read::GzDecoder;
use git2;
use rustc_serialize::hex::ToHex;
Expand All @@ -188,7 +188,7 @@ pub struct RegistrySource<'cfg> {
cache_path: Filesystem,
src_path: Filesystem,
config: &'cfg Config,
handle: Option<http::Handle>,
handle: Option<Easy>,
hashes: HashMap<(String, String), String>, // (name, vers) => cksum
cache: HashMap<String, Vec<(Summary, bool)>>,
updated: bool,
Expand Down Expand Up @@ -300,24 +300,34 @@ impl<'cfg> RegistrySource<'cfg> {
self.handle.as_mut().unwrap()
}
};
// TODO: don't download into memory (curl-rust doesn't expose it)
let resp = try!(handle.get(url.to_string()).follow_redirects(true).exec());
if resp.get_code() != 200 && resp.get_code() != 0 {
return Err(internal(format!("failed to get 200 response from {}\n{}",
url, resp)))
// TODO: don't download into memory, but ensure that if we ctrl-c a
// download we should resume either from the start or the middle
// on the next time
try!(handle.get(true));
try!(handle.url(&url.to_string()));
try!(handle.follow_location(true));
let mut state = Sha256::new();
let mut body = Vec::new();
{
let mut handle = handle.transfer();
try!(handle.write_function(|buf| {
state.update(buf);
body.extend_from_slice(buf);
Ok(buf.len())
}));
try!(handle.perform());
}
let code = try!(handle.response_code());
if code != 200 && code != 0 {
bail!("failed to get 200 response from `{}`, got {}", url, code)
}

// Verify what we just downloaded
let actual = {
let mut state = Sha256::new();
state.update(resp.get_body());
state.finish()
};
if actual.to_hex() != expected_hash {
if state.finish().to_hex() != expected_hash {
bail!("failed to verify the checksum of `{}`", pkg)
}

try!(dst.write_all(resp.get_body()));
try!(dst.write_all(&body));
try!(dst.seek(SeekFrom::Start(0)));
Ok(dst)
}
Expand Down
21 changes: 8 additions & 13 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::str;
use std::string;

use curl;
use curl_sys;
use git2;
use rustc_serialize::json;
use semver;
Expand Down Expand Up @@ -302,17 +301,13 @@ impl NetworkError for git2::Error {
}
}
}
impl NetworkError for curl::ErrCode {
impl NetworkError for curl::Error {
fn maybe_spurious(&self) -> bool {
match self.code() {
curl_sys::CURLcode::CURLE_COULDNT_CONNECT |
curl_sys::CURLcode::CURLE_COULDNT_RESOLVE_PROXY |
curl_sys::CURLcode::CURLE_COULDNT_RESOLVE_HOST |
curl_sys::CURLcode::CURLE_OPERATION_TIMEDOUT |
curl_sys::CURLcode::CURLE_RECV_ERROR
=> true,
_ => false
}
self.is_couldnt_connect() ||
self.is_couldnt_resolve_proxy() ||
self.is_couldnt_resolve_host() ||
self.is_operation_timedout() ||
self.is_recv_error()
}
}

Expand All @@ -334,7 +329,7 @@ from_error! {
git2::Error,
json::DecoderError,
json::EncoderError,
curl::ErrCode,
curl::Error,
CliError,
toml::Error,
url::ParseError,
Expand All @@ -360,7 +355,7 @@ impl CargoError for io::Error {}
impl CargoError for git2::Error {}
impl CargoError for json::DecoderError {}
impl CargoError for json::EncoderError {}
impl CargoError for curl::ErrCode {}
impl CargoError for curl::Error {}
impl CargoError for ProcessError {}
impl CargoError for CargoTestError {}
impl CargoError for CliError {}
Expand Down
2 changes: 1 addition & 1 deletion src/crates-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ name = "crates_io"
path = "lib.rs"

[dependencies]
curl = "0.2"
curl = "0.3"
url = "1.0"
rustc-serialize = "0.3"
Loading