Skip to content

Commit cd612e0

Browse files
djcrami3l
authored andcommitted
Externalize wrapping of DownloadTracker
1 parent 768ed53 commit cd612e0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/cli/common.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ pub(super) struct Notifier {
133133
impl Notifier {
134134
pub(super) fn new(verbose: bool, quiet: bool) -> Self {
135135
Self {
136-
tracker: DownloadTracker::new_with_display_progress(!quiet),
136+
tracker: Arc::new(Mutex::new(DownloadTracker::new_with_display_progress(
137+
!quiet,
138+
))),
137139
ram_notice_shown: RefCell::new(false),
138140
verbose,
139141
}

src/cli/download_tracker.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::VecDeque;
22
use std::fmt;
33
use std::io::Write;
4-
use std::sync::{Arc, Mutex};
54
use std::time::{Duration, Instant};
65

76
use crate::currentprocess::{process, terminalsource};
@@ -50,8 +49,8 @@ pub(crate) struct DownloadTracker {
5049

5150
impl DownloadTracker {
5251
/// Creates a new DownloadTracker.
53-
pub(crate) fn new_with_display_progress(display_progress: bool) -> Arc<Mutex<Self>> {
54-
Arc::new(Mutex::new(Self {
52+
pub(crate) fn new_with_display_progress(display_progress: bool) -> Self {
53+
Self {
5554
content_len: None,
5655
total_downloaded: 0,
5756
downloaded_this_sec: 0,
@@ -62,7 +61,7 @@ impl DownloadTracker {
6261
displayed_charcount: None,
6362
units: vec![Unit::B],
6463
display_progress,
65-
}))
64+
}
6665
}
6766

6867
pub(crate) fn handle_notification(&mut self, n: &Notification<'_>) -> bool {

src/cli/self_update/windows.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::io::Write;
55
use std::os::windows::ffi::{OsStrExt, OsStringExt};
66
use std::path::Path;
77
use std::process::Command;
8+
use std::sync::{Arc, Mutex};
89

910
use anyhow::{anyhow, Context, Result};
1011

@@ -179,7 +180,7 @@ pub(crate) async fn try_install_msvc(opts: &InstallOpts<'_>) -> Result<ContinueI
179180
.context("error creating temp directory")?;
180181

181182
let visual_studio = tempdir.path().join("vs_setup.exe");
182-
let download_tracker = DownloadTracker::new_with_display_progress(true);
183+
let download_tracker = Arc::new(Mutex::new(DownloadTracker::new_with_display_progress(true)));
183184
download_tracker.lock().unwrap().download_finished();
184185

185186
info!("downloading Visual Studio installer");

0 commit comments

Comments
 (0)