Skip to content

Commit 6dbfde3

Browse files
committed
refactor: move try_old_curl!() to util::network
1 parent f182b84 commit 6dbfde3

File tree

3 files changed

+21
-39
lines changed

3 files changed

+21
-39
lines changed

src/cargo/core/package.rs

+2-19
Original file line numberDiff line numberDiff line change
@@ -651,23 +651,6 @@ impl<'cfg> PackageSet<'cfg> {
651651
}
652652
}
653653

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

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

src/cargo/sources/registry/http_remote.rs

+1-20
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

+18
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)