Skip to content

Commit dd68c17

Browse files
fix(DownloadCfg): remove lifetime parameters from DownloadCfg
1 parent 7285c27 commit dd68c17

File tree

5 files changed

+50
-80
lines changed

5 files changed

+50
-80
lines changed

src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,15 @@ impl<'a> Cfg<'a> {
329329

330330
/// construct a download configuration
331331
pub(crate) fn download_cfg(
332-
&'a self,
332+
&self,
333333
notify_handler: Arc<dist::notifications::NotifyHandler>,
334-
) -> DownloadCfg<'a> {
334+
) -> DownloadCfg {
335335
DownloadCfg {
336-
dist_root: &self.dist_root_url,
336+
dist_root: Arc::from(self.dist_root_url.clone()),
337337
tmp_cx: Arc::clone(&self.tmp_cx),
338-
download_dir: &self.download_dir,
338+
download_dir: Arc::new(self.download_dir.clone()),
339339
notify_handler,
340-
process: self.process,
340+
process: Arc::new(self.process.clone()),
341341
}
342342
}
343343

src/dist/download.rs

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,12 @@ use crate::utils;
1818
const UPDATE_HASH_LEN: usize = 20;
1919

2020
#[derive(Clone)]
21-
pub struct DownloadCfg<'a> {
22-
pub dist_root: &'a str,
21+
pub struct DownloadCfg {
22+
pub dist_root: Arc<str>,
2323
pub tmp_cx: Arc<temp::Context>,
24-
pub download_dir: &'a PathBuf,
24+
pub download_dir: Arc<PathBuf>,
2525
pub notify_handler: Arc<NotifyHandler>,
26-
pub process: &'a Process,
27-
}
28-
29-
#[derive(Clone)]
30-
pub struct OwnedDownloadCfg {
31-
pub dist_root: String,
32-
pub tmp_cx: Arc<temp::Context>,
33-
pub download_dir: PathBuf,
34-
pub notify_handler: Arc<NotifyHandler>,
35-
pub process: Process,
36-
}
37-
38-
impl<'a> From<&'a OwnedDownloadCfg> for DownloadCfg<'a> {
39-
fn from(odc: &'a OwnedDownloadCfg) -> Self {
40-
Self {
41-
dist_root: &odc.dist_root,
42-
tmp_cx: Arc::clone(&odc.tmp_cx),
43-
download_dir: &odc.download_dir,
44-
notify_handler: Arc::clone(&odc.notify_handler),
45-
process: &odc.process,
46-
}
47-
}
48-
}
49-
50-
impl DownloadCfg<'_> {
51-
pub fn to_owned(&self) -> OwnedDownloadCfg {
52-
OwnedDownloadCfg {
53-
dist_root: self.dist_root.to_owned(),
54-
tmp_cx: Arc::clone(&self.tmp_cx),
55-
download_dir: self.download_dir.clone(),
56-
notify_handler: Arc::clone(&self.notify_handler),
57-
process: self.process.clone(),
58-
}
59-
}
26+
pub process: Arc<Process>,
6027
}
6128

6229
pub(crate) struct File {
@@ -71,15 +38,15 @@ impl ops::Deref for File {
7138
}
7239
}
7340

74-
impl<'a> DownloadCfg<'a> {
41+
impl DownloadCfg {
7542
/// Downloads a file and validates its hash. Resumes interrupted downloads.
7643
/// Partial downloads are stored in `self.download_dir`, keyed by hash. If the
7744
/// target file already exists, then the hash is checked and it is returned
7845
/// immediately without re-downloading.
7946
pub(crate) async fn download(&self, url: &Url, hash: &str) -> Result<File> {
8047
utils::ensure_dir_exists(
8148
"Download Directory",
82-
self.download_dir,
49+
&self.download_dir,
8350
&*self.notify_handler,
8451
)?;
8552
let target_file = self.download_dir.join(Path::new(hash));
@@ -115,7 +82,7 @@ impl<'a> DownloadCfg<'a> {
11582
Some(&mut hasher),
11683
true,
11784
&|n| (self.notify_handler)(n.into()),
118-
self.process,
85+
&self.process,
11986
)
12087
.await
12188
{
@@ -150,7 +117,7 @@ impl<'a> DownloadCfg<'a> {
150117
&partial_file_path,
151118
&target_file,
152119
&*self.notify_handler,
153-
self.process,
120+
&self.process,
154121
)?;
155122
Ok(File { path: target_file })
156123
}
@@ -175,7 +142,7 @@ impl<'a> DownloadCfg<'a> {
175142
&hash_file,
176143
None,
177144
&|n| (self.notify_handler)(n.into()),
178-
self.process,
145+
&self.process,
179146
)
180147
.await?;
181148

@@ -220,7 +187,7 @@ impl<'a> DownloadCfg<'a> {
220187
&file,
221188
Some(&mut hasher),
222189
&|n| (self.notify_handler)(n.into()),
223-
self.process,
190+
&self.process,
224191
)
225192
.await?;
226193
let actual_hash = format!("{:x}", hasher.finalize());

src/dist/manifestation.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Manifestation {
109109
new_manifest: Arc<Manifest>,
110110
changes: Changes,
111111
force_update: bool,
112-
download_cfg: DownloadCfg<'_>,
112+
download_cfg: DownloadCfg,
113113
toolchain_str: &str,
114114
implicit_modify: bool,
115115
) -> Result<UpdateStatus> {
@@ -176,12 +176,12 @@ impl Manifestation {
176176
prefix.clone(),
177177
Arc::clone(&download_cfg.tmp_cx),
178178
Arc::clone(&download_cfg.notify_handler),
179-
Arc::new(download_cfg.process.clone()),
179+
Arc::clone(&download_cfg.process),
180180
);
181181

182182
// If the previous installation was from a v1 manifest we need
183183
// to uninstall it first.
184-
tx = self.maybe_handle_v2_upgrade(&config, tx, download_cfg.process)?;
184+
tx = self.maybe_handle_v2_upgrade(&config, tx, &download_cfg.process)?;
185185

186186
info!("downloading component(s)");
187187
for (component, _, url, _) in components.clone() {
@@ -211,7 +211,7 @@ impl Manifestation {
211211
&new_manifest,
212212
tx,
213213
&*download_cfg.notify_handler,
214-
download_cfg.process,
214+
&download_cfg.process,
215215
)?;
216216
}
217217

@@ -290,7 +290,6 @@ impl Manifestation {
290290
let tmp_cx = download_cfg.tmp_cx.clone();
291291
let download_cfg = Arc::clone(&download_cfg);
292292
move || {
293-
let download_cfg = (&*download_cfg).into();
294293
this.install_component(
295294
component,
296295
format,
@@ -486,11 +485,11 @@ impl Manifestation {
486485
use std::path::PathBuf;
487486
let dld_dir = PathBuf::from("bogus");
488487
let dlcfg = DownloadCfg {
489-
dist_root: "bogus",
490-
download_dir: &dld_dir,
488+
dist_root: Arc::from("bogus".to_string()),
489+
download_dir: Arc::new(dld_dir),
491490
tmp_cx: Arc::clone(&tmp_cx),
492491
notify_handler: Arc::clone(&notify_handler),
493-
process: &process,
492+
process: Arc::clone(&process),
494493
};
495494

496495
let dl = dlcfg
@@ -575,7 +574,7 @@ impl Manifestation {
575574
hash: String,
576575
altered: bool,
577576
tmp_cx: &temp::Context,
578-
download_cfg: &DownloadCfg<'_>,
577+
download_cfg: &DownloadCfg,
579578
max_retries: usize,
580579
new_manifest: &Manifest,
581580
notification_tx: mpsc::Sender<Result<(Component, CompressionKind, File)>>,
@@ -621,7 +620,7 @@ impl Manifestation {
621620
format: CompressionKind,
622621
installer_file: File,
623622
tmp_cx: Arc<temp::Context>,
624-
download_cfg: DownloadCfg<'_>,
623+
download_cfg: Arc<DownloadCfg>,
625624
new_manifest: Arc<Manifest>,
626625
tx: Transaction,
627626
) -> Result<Transaction> {
@@ -653,7 +652,7 @@ impl Manifestation {
653652
reader,
654653
tmp_cx,
655654
Some(&notification_converter),
656-
download_cfg.process,
655+
&download_cfg.process,
657656
)?;
658657
&gz
659658
}
@@ -662,7 +661,7 @@ impl Manifestation {
662661
reader,
663662
tmp_cx,
664663
Some(&notification_converter),
665-
download_cfg.process,
664+
&download_cfg.process,
666665
)?;
667666
&xz
668667
}
@@ -671,7 +670,7 @@ impl Manifestation {
671670
reader,
672671
tmp_cx,
673672
Some(&notification_converter),
674-
download_cfg.process,
673+
&download_cfg.process,
675674
)?;
676675
&zst
677676
}

src/dist/manifestation/tests.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,13 @@ impl TestContext {
473473
}
474474
}
475475

476-
fn default_dl_cfg(&self) -> DownloadCfg<'_> {
476+
fn default_dl_cfg(&self) -> DownloadCfg {
477477
DownloadCfg {
478-
dist_root: "phony",
478+
dist_root: Arc::from("phony".to_string()),
479479
tmp_cx: Arc::new(self.tmp_cx.clone()),
480-
download_dir: &self.download_dir,
480+
download_dir: Arc::new(self.download_dir.clone()),
481481
notify_handler: Arc::new(|event| println!("{event}")),
482-
process: &self.tp.process,
482+
process: Arc::new(self.tp.process.clone()),
483483
}
484484
}
485485

@@ -502,12 +502,19 @@ impl TestContext {
502502
add: &[Component],
503503
remove: &[Component],
504504
force: bool,
505-
dl_cfg: DownloadCfg<'_>,
505+
dl_cfg: DownloadCfg,
506506
) -> Result<UpdateStatus> {
507507
// Download the dist manifest and place it into the installation prefix
508508
let manifest_url = make_manifest_url(&self.url, &self.toolchain)?;
509509
let manifest_file = Arc::new(self.tmp_cx.clone()).new_file()?;
510-
download_file(&manifest_url, &manifest_file, None, &|_| {}, dl_cfg.process).await?;
510+
download_file(
511+
&manifest_url,
512+
&manifest_file,
513+
None,
514+
&|_| {},
515+
&dl_cfg.process,
516+
)
517+
.await?;
511518
let manifest_str = utils::read_file("manifest", &manifest_file)?;
512519
let manifest = Manifest::parse(&manifest_str)?;
513520

src/dist/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ pub(crate) struct DistOptions<'a> {
891891
pub(crate) toolchain: &'a ToolchainDesc,
892892
pub(crate) profile: Profile,
893893
pub(crate) update_hash: Option<&'a Path>,
894-
pub(crate) dl_cfg: DownloadCfg<'a>,
894+
pub(crate) dl_cfg: DownloadCfg,
895895
/// --force bool is whether to force an update/install
896896
pub(crate) force: bool,
897897
/// --allow-downgrade
@@ -1066,7 +1066,7 @@ pub(crate) async fn update_from_dist(
10661066

10671067
#[allow(clippy::too_many_arguments)]
10681068
async fn try_update_from_dist_(
1069-
download: DownloadCfg<'_>,
1069+
download: DownloadCfg,
10701070
update_hash: Option<&Path>,
10711071
toolchain: &ToolchainDesc,
10721072
profile: Option<Profile>,
@@ -1215,9 +1215,9 @@ async fn try_update_from_dist_(
12151215
.update_v1(
12161216
&manifest,
12171217
update_hash,
1218-
Arc::clone(&download.tmp_cx),
1218+
download.tmp_cx,
12191219
download.notify_handler,
1220-
Arc::new(download.process),
1220+
download.process,
12211221
)
12221222
.await;
12231223

@@ -1234,11 +1234,11 @@ async fn try_update_from_dist_(
12341234
}
12351235

12361236
pub(crate) async fn dl_v2_manifest(
1237-
download: DownloadCfg<'_>,
1237+
download: DownloadCfg,
12381238
update_hash: Option<&Path>,
12391239
toolchain: &ToolchainDesc,
12401240
) -> Result<Option<(ManifestV2, String)>> {
1241-
let manifest_url = toolchain.manifest_v2_url(download.dist_root, download.process);
1241+
let manifest_url = toolchain.manifest_v2_url(&download.dist_root, &download.process);
12421242
match download
12431243
.download_and_check(&manifest_url, update_hash, ".toml")
12441244
.await
@@ -1264,7 +1264,7 @@ pub(crate) async fn dl_v2_manifest(
12641264
// Manifest checksum mismatched.
12651265
warn!("{err}");
12661266

1267-
let server = dist_root_server(download.process)?;
1267+
let server = dist_root_server(&download.process)?;
12681268
if server == DEFAULT_DIST_SERVER {
12691269
info!(
12701270
"this is likely due to an ongoing update of the official release server, please try again later"
@@ -1282,11 +1282,8 @@ pub(crate) async fn dl_v2_manifest(
12821282
}
12831283
}
12841284

1285-
async fn dl_v1_manifest(
1286-
download: DownloadCfg<'_>,
1287-
toolchain: &ToolchainDesc,
1288-
) -> Result<Vec<String>> {
1289-
let root_url = toolchain.package_dir(download.dist_root);
1285+
async fn dl_v1_manifest(download: DownloadCfg, toolchain: &ToolchainDesc) -> Result<Vec<String>> {
1286+
let root_url = toolchain.package_dir(&download.dist_root);
12901287

12911288
if let Channel::Version(ver) = &toolchain.channel {
12921289
// This is an explicit version. In v1 there was no manifest,
@@ -1295,7 +1292,7 @@ async fn dl_v1_manifest(
12951292
return Ok(vec![installer_name]);
12961293
}
12971294

1298-
let manifest_url = toolchain.manifest_v1_url(download.dist_root, download.process);
1295+
let manifest_url = toolchain.manifest_v1_url(&download.dist_root, &download.process);
12991296
let manifest_dl = download.download_and_check(&manifest_url, None, "").await?;
13001297
let (manifest_file, _) = manifest_dl.unwrap();
13011298
let manifest_str = utils::read_file("manifest", &manifest_file)?;

0 commit comments

Comments
 (0)