Skip to content

Commit 3664131

Browse files
committed
dist: simplify DownloadStatus setup
1 parent 4111520 commit 3664131

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

src/dist/download.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const UPDATE_HASH_LEN: usize = 20;
2323
pub struct DownloadCfg<'a> {
2424
pub tmp_cx: &'a temp::Context,
2525
pub download_dir: &'a PathBuf,
26-
pub(crate) tracker: DownloadTracker,
26+
pub(super) tracker: DownloadTracker,
2727
pub process: &'a Process,
2828
}
2929

@@ -184,6 +184,24 @@ impl<'a> DownloadCfg<'a> {
184184

185185
Ok(Some((file, partial_hash)))
186186
}
187+
188+
pub(crate) fn status_for(&self, component: impl Into<Cow<'static, str>>) -> DownloadStatus {
189+
let progress = ProgressBar::hidden();
190+
progress.set_style(
191+
ProgressStyle::with_template(
192+
"{msg:>12.bold} [{bar:40}] {bytes}/{total_bytes} ({bytes_per_sec}, ETA: {eta})",
193+
)
194+
.unwrap()
195+
.progress_chars("## "),
196+
);
197+
progress.set_message(component);
198+
self.tracker.multi_progress_bars.add(progress.clone());
199+
200+
DownloadStatus {
201+
progress,
202+
retry_time: Mutex::new(None),
203+
}
204+
}
187205
}
188206

189207
/// Tracks download progress and displays information about it to a terminal.
@@ -208,13 +226,6 @@ impl DownloadTracker {
208226
multi_progress_bars,
209227
}
210228
}
211-
212-
/// Creates a new ProgressBar for the given component.
213-
pub(crate) fn status_for(&self, component: impl Into<Cow<'static, str>>) -> DownloadStatus {
214-
let status = DownloadStatus::new(component);
215-
self.multi_progress_bars.add(status.progress.clone());
216-
status
217-
}
218229
}
219230

220231
pub(crate) struct DownloadStatus {
@@ -223,23 +234,6 @@ pub(crate) struct DownloadStatus {
223234
}
224235

225236
impl DownloadStatus {
226-
fn new(component: impl Into<Cow<'static, str>>) -> Self {
227-
let progress = ProgressBar::hidden();
228-
progress.set_style(
229-
ProgressStyle::with_template(
230-
"{msg:>12.bold} [{bar:40}] {bytes}/{total_bytes} ({bytes_per_sec}, ETA: {eta})",
231-
)
232-
.unwrap()
233-
.progress_chars("## "),
234-
);
235-
progress.set_message(component);
236-
237-
Self {
238-
progress,
239-
retry_time: Mutex::new(None),
240-
}
241-
}
242-
243237
pub(crate) fn received_length(&self, len: u64) {
244238
self.progress.reset();
245239
self.progress.set_length(len);

src/dist/manifestation.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ impl Manifestation {
164164
res.map(|(component, binary)| ComponentBinary {
165165
component,
166166
binary,
167-
status: download_cfg
168-
.tracker
169-
.status_for(component.short_name(new_manifest)),
167+
status: download_cfg.status_for(component.short_name(new_manifest)),
170168
})
171169
})
172170
.collect::<Result<Vec<_>>>()?;
@@ -444,7 +442,7 @@ impl Manifestation {
444442
.unwrap()
445443
.replace(DEFAULT_DIST_SERVER, dl_cfg.tmp_cx.dist_server.as_str());
446444

447-
let status = dl_cfg.tracker.status_for("rust");
445+
let status = dl_cfg.status_for("rust");
448446
let dl = dl_cfg
449447
.download_and_check(&url, update_hash, Some(&status), ".tar.gz")
450448
.await?;

0 commit comments

Comments
 (0)