Skip to content

Commit 02343aa

Browse files
committed
refactor: move try_old_curl!() to util::network
1 parent e09dab5 commit 02343aa

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

src/cargo/core/package.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -652,23 +652,6 @@ impl<'cfg> PackageSet<'cfg> {
652652
}
653653
}
654654

655-
// When dynamically linked against libcurl, we want to ignore some failures
656-
// when using old versions that don't support certain features.
657-
macro_rules! try_old_curl {
658-
($e:expr, $msg:expr) => {
659-
let result = $e;
660-
if cfg!(target_os = "macos") {
661-
if let Err(e) = result {
662-
warn!("ignoring libcurl {} error: {}", $msg, e);
663-
}
664-
} else {
665-
result.with_context(|| {
666-
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
667-
})?;
668-
}
669-
};
670-
}
671-
672655
impl<'a, 'cfg> Downloads<'a, 'cfg> {
673656
/// Starts to download the package for the `id` specified.
674657
///
@@ -749,7 +732,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
749732
// errors here on OSX, but consider this a fatal error to not activate
750733
// HTTP/2 on all other platforms.
751734
if self.set.multiplexing {
752-
try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
735+
crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
753736
} else {
754737
handle.http_version(HttpVersion::V11)?;
755738
}
@@ -761,7 +744,7 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
761744
// Once the main one is opened we realized that pipelining is possible
762745
// and multiplexing is possible with static.crates.io. All in all this
763746
// reduces the number of connections down to a more manageable state.
764-
try_old_curl!(handle.pipewait(true), "pipewait");
747+
crate::try_old_curl!(handle.pipewait(true), "pipewait");
765748

766749
handle.write_function(move |buf| {
767750
debug!("{} - {} bytes of data", token, buf.len());

src/cargo/sources/registry/http_remote.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -391,25 +391,6 @@ impl<'cfg> HttpRegistry<'cfg> {
391391
}
392392
}
393393

394-
// copied from src/cargo/core/package.rs to keep change minimal
395-
//
396-
// When dynamically linked against libcurl, we want to ignore some failures
397-
// when using old versions that don't support certain features.
398-
macro_rules! try_old_curl {
399-
($e:expr, $msg:expr) => {
400-
let result = $e;
401-
if cfg!(target_os = "macos") {
402-
if let Err(e) = result {
403-
warn!("ignoring libcurl {} error: {}", $msg, e);
404-
}
405-
} else {
406-
result.with_context(|| {
407-
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
408-
})?;
409-
}
410-
};
411-
}
412-
413394
impl<'cfg> RegistryData for HttpRegistry<'cfg> {
414395
fn prepare(&self) -> CargoResult<()> {
415396
Ok(())
@@ -572,7 +553,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
572553

573554
// Enable HTTP/2 if possible.
574555
if self.multiplexing {
575-
try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
556+
crate::try_old_curl!(handle.http_version(HttpVersion::V2), "HTTP2");
576557
} else {
577558
handle.http_version(HttpVersion::V11)?;
578559
}

src/cargo/util/network.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ where
110110
}
111111
}
112112

113+
// When dynamically linked against libcurl, we want to ignore some failures
114+
// when using old versions that don't support certain features.
115+
#[macro_export]
116+
macro_rules! try_old_curl {
117+
($e:expr, $msg:expr) => {
118+
let result = $e;
119+
if cfg!(target_os = "macos") {
120+
if let Err(e) = result {
121+
warn!("ignoring libcurl {} error: {}", $msg, e);
122+
}
123+
} else {
124+
result.with_context(|| {
125+
anyhow::format_err!("failed to enable {}, is curl not built right?", $msg)
126+
})?;
127+
}
128+
};
129+
}
130+
113131
#[test]
114132
fn with_retry_repeats_the_call_then_works() {
115133
use crate::core::Shell;

0 commit comments

Comments
 (0)