Skip to content

Commit cc732d2

Browse files
committed
dist: simplify DownloadStatus setup
1 parent 5856672 commit cc732d2

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

@@ -189,6 +189,24 @@ impl<'a> DownloadCfg<'a> {
189189

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

194212
/// Tracks download progress and displays information about it to a terminal.
@@ -213,13 +231,6 @@ impl DownloadTracker {
213231
multi_progress_bars,
214232
}
215233
}
216-
217-
/// Creates a new ProgressBar for the given component.
218-
pub(crate) fn status_for(&self, component: impl Into<Cow<'static, str>>) -> DownloadStatus {
219-
let status = DownloadStatus::new(component);
220-
self.multi_progress_bars.add(status.progress.clone());
221-
status
222-
}
223234
}
224235

225236
pub(crate) struct DownloadStatus {
@@ -234,23 +245,6 @@ pub(crate) struct DownloadStatus {
234245
}
235246

236247
impl DownloadStatus {
237-
fn new(component: impl Into<Cow<'static, str>>) -> Self {
238-
let progress = ProgressBar::hidden();
239-
progress.set_style(
240-
ProgressStyle::with_template(
241-
"{msg:>12.bold} [{bar:40}] {bytes}/{total_bytes} ({bytes_per_sec}, ETA: {eta})",
242-
)
243-
.unwrap()
244-
.progress_chars("## "),
245-
);
246-
progress.set_message(component);
247-
248-
Self {
249-
progress,
250-
retry_time: Mutex::new(None),
251-
}
252-
}
253-
254248
pub(crate) fn received_length(&self, len: u64) {
255249
self.progress.reset();
256250
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)