[go: up one dir, main page]

Skip to content

Commit

Permalink
Auto merge of rust-lang#4781 - alexcrichton:beta-next, r=alexcrichton
Browse files Browse the repository at this point in the history
[beta] Reconfigure curl handles after reset

This is a backport of rust-lang#4780
  • Loading branch information
bors committed Dec 5, 2017
2 parents 6a1aee0 + 4650ff3 commit 4504311
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use self::cargo_package::{package, PackageOpts};
pub use self::registry::{publish, registry_configuration, RegistryConfig};
pub use self::registry::{registry_login, search, http_proxy_exists, http_handle};
pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts};
pub use self::registry::configure_http_handle;
pub use self::cargo_fetch::fetch;
pub use self::cargo_pkgid::pkgid;
pub use self::resolve::{resolve_ws, resolve_ws_precisely, resolve_with_previous};
Expand Down
12 changes: 11 additions & 1 deletion src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
// 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 mut handle = Easy::new();
configure_http_handle(config, &mut handle)?;
Ok(handle)
}

/// Configure a libcurl http handle with the defaults options for Cargo
pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<()> {
// 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.
handle.connect_timeout(Duration::new(30, 0))?;
handle.low_speed_limit(10 /* bytes per second */)?;
handle.low_speed_time(Duration::new(30, 0))?;
Expand All @@ -290,7 +300,7 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
handle.connect_timeout(Duration::new(timeout as u64, 0))?;
handle.low_speed_time(Duration::new(timeout as u64, 0))?;
}
Ok(handle)
Ok(())
}

/// Find an explicit HTTP proxy if one is available.
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/sources/registry/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use hex::ToHex;
use serde_json;

use core::{PackageId, SourceId};
use ops;
use sources::git;
use sources::registry::{RegistryData, RegistryConfig, INDEX_LOCK};
use util::network;
Expand Down Expand Up @@ -159,7 +158,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
//
// This way if there's a problem the error gets printed before we even
// hit the index, which may not actually read this configuration.
ops::http_handle(self.config)?;
self.config.http()?;

self.repo()?;
self.head.set(None);
Expand Down
6 changes: 5 additions & 1 deletion src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,11 @@ impl Config {
let http = self.easy.get_or_try_init(|| {
ops::http_handle(self).map(RefCell::new)
})?;
http.borrow_mut().reset();
{
let mut http = http.borrow_mut();
http.reset();
ops::configure_http_handle(self, &mut http)?;
}
Ok(http)
}
}
Expand Down
12 changes: 7 additions & 5 deletions tests/lockfile-compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

#[test]
fn frozen_flag_preserves_old_lockfile() {
Package::new("foo", "0.1.0").publish();
let cksum = Package::new("foo", "0.1.0").publish();

let old_lockfile =
let old_lockfile = format!(
r#"[root]
name = "zzz"
version = "0.0.1"
Expand All @@ -95,8 +95,10 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9e0a16bdf5c05435698fa27192d89e331b22a26a972c34984f560662544453b"
"#;
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "{}"
"#,
cksum,
);

let p = project("bar")
.file("Cargo.toml", r#"
Expand All @@ -109,7 +111,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
foo = "0.1.0"
"#)
.file("src/lib.rs", "")
.file("Cargo.lock", old_lockfile)
.file("Cargo.lock", &old_lockfile)
.build();

assert_that(p.cargo("build").arg("--locked"),
Expand Down

0 comments on commit 4504311

Please sign in to comment.