Skip to content

Commit 4268597

Browse files
committed
dist: extract URL alteration from download() method
1 parent 963d7f0 commit 4268597

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/dist/manifestation.rs

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

1516
use crate::dist::component::{
1617
Components, Package, PackageContext, TarGzPackage, TarXzPackage, TarZStdPackage, Transaction,
@@ -187,7 +188,17 @@ impl Manifestation {
187188
let sem = semaphore.clone();
188189
async move {
189190
let _permit = sem.acquire().await.unwrap();
190-
bin.download(altered, tmp_cx, download_cfg, max_retries, new_manifest)
191+
let url = if altered {
192+
utils::parse_url(
193+
&bin.binary
194+
.url
195+
.replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str()),
196+
)?
197+
} else {
198+
utils::parse_url(&bin.binary.url)?
199+
};
200+
201+
bin.download(&url, download_cfg, max_retries, new_manifest)
191202
.await
192203
.map(|downloaded| (bin, downloaded))
193204
}
@@ -745,33 +756,22 @@ struct ComponentBinary<'a> {
745756
impl<'a> ComponentBinary<'a> {
746757
async fn download(
747758
&self,
748-
altered: bool,
749-
tmp_cx: &temp::Context,
759+
url: &Url,
750760
download_cfg: &DownloadCfg<'_>,
751761
max_retries: usize,
752762
new_manifest: &Manifest,
753763
) -> Result<File> {
754764
use tokio_retry::{RetryIf, strategy::FixedInterval};
755765

756-
let url = if altered {
757-
self.binary
758-
.url
759-
.replace(DEFAULT_DIST_SERVER, tmp_cx.dist_server.as_str())
760-
} else {
761-
self.binary.url.clone()
762-
};
763-
764-
let url_url = utils::parse_url(&url)?;
765-
766766
let downloaded_file = RetryIf::spawn(
767767
FixedInterval::from_millis(0).take(max_retries),
768-
|| download_cfg.download(&url_url, &self.binary.hash),
768+
|| download_cfg.download(url, &self.binary.hash),
769769
|e: &anyhow::Error| {
770770
// retry only known retriable cases
771771
match e.downcast_ref::<RustupError>() {
772772
Some(RustupError::BrokenPartialFile)
773773
| Some(RustupError::DownloadingFile { .. }) => {
774-
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
774+
(download_cfg.notify_handler)(Notification::RetryingDownload(url.as_str()));
775775
true
776776
}
777777
_ => false,

0 commit comments

Comments
 (0)