Skip to content

Commit 162e9b8

Browse files
committed
dist: move URL alteration logic into DownloadCfg method
1 parent 07cb923 commit 162e9b8

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/dist/download.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use tracing::{debug, warn};
1212
use url::Url;
1313

1414
use crate::config::Cfg;
15+
use crate::dist::DEFAULT_DIST_SERVER;
1516
use crate::dist::temp;
1617
use crate::download::{download_file, download_file_with_resume};
1718
use crate::errors::RustupError;
@@ -207,6 +208,15 @@ impl<'a> DownloadCfg<'a> {
207208
retry_time: Mutex::new(None),
208209
}
209210
}
211+
212+
pub(crate) fn url(&self, url: &str) -> Result<Url> {
213+
match &*self.tmp_cx.dist_server {
214+
server if server != DEFAULT_DIST_SERVER => utils::parse_url(
215+
&url.replace(DEFAULT_DIST_SERVER, self.tmp_cx.dist_server.as_str()),
216+
),
217+
_ => utils::parse_url(url),
218+
}
219+
}
210220
}
211221

212222
/// Tracks download progress and displays information about it to a terminal.

src/dist/manifestation.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use futures_util::stream::StreamExt;
1111
use std::sync::Arc;
1212
use tokio::sync::Semaphore;
1313
use tracing::{info, warn};
14-
use url::Url;
1514

1615
use crate::dist::component::{
1716
Components, Package, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction,
@@ -153,8 +152,6 @@ impl Manifestation {
153152
}
154153
}
155154

156-
let altered = tmp_cx.dist_server != DEFAULT_DIST_SERVER;
157-
158155
// Download component packages and validate hashes
159156
let mut things_to_install = Vec::new();
160157
let mut things_downloaded = Vec::new();
@@ -190,17 +187,7 @@ impl Manifestation {
190187
let sem = semaphore.clone();
191188
async move {
192189
let _permit = sem.acquire().await.unwrap();
193-
let url = if altered {
194-
utils::parse_url(
195-
&bin.binary
196-
.url
197-
.replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str()),
198-
)?
199-
} else {
200-
utils::parse_url(&bin.binary.url)?
201-
};
202-
203-
bin.download(&url, download_cfg, max_retries, new_manifest)
190+
bin.download(download_cfg, max_retries, new_manifest)
204191
.await
205192
.map(|downloaded| (bin, downloaded))
206193
}
@@ -699,16 +686,16 @@ struct ComponentBinary<'a> {
699686
impl<'a> ComponentBinary<'a> {
700687
async fn download(
701688
&self,
702-
url: &Url,
703689
download_cfg: &DownloadCfg<'_>,
704690
max_retries: usize,
705691
new_manifest: &Manifest,
706692
) -> Result<File> {
707693
use tokio_retry::{RetryIf, strategy::FixedInterval};
708694

695+
let url = download_cfg.url(&self.binary.url)?;
709696
let downloaded_file = RetryIf::spawn(
710697
FixedInterval::from_millis(0).take(max_retries),
711-
|| download_cfg.download(url, &self.binary.hash, &self.status),
698+
|| download_cfg.download(&url, &self.binary.hash, &self.status),
712699
|e: &anyhow::Error| {
713700
// retry only known retriable cases
714701
match e.downcast_ref::<RustupError>() {

0 commit comments

Comments
 (0)