@@ -5,7 +5,7 @@ use std::fmt::Display;
5
5
use std:: fs;
6
6
use std:: io:: { BufRead , ErrorKind , Write } ;
7
7
use std:: path:: { Path , PathBuf } ;
8
- use std:: sync:: Arc ;
8
+ use std:: sync:: { Arc , Mutex } ;
9
9
use std:: { cmp, env} ;
10
10
11
11
use anyhow:: { anyhow, Context , Result } ;
@@ -167,23 +167,34 @@ impl NotifyOnConsole {
167
167
}
168
168
}
169
169
170
+ struct Notifier {
171
+ tracker : Arc < Mutex < DownloadTracker > > ,
172
+ notifier : RefCell < NotifyOnConsole > ,
173
+ }
174
+
175
+ impl Notifier {
176
+ fn new ( verbose : bool , quiet : bool ) -> Self {
177
+ Self {
178
+ tracker : DownloadTracker :: new_with_display_progress ( !quiet) ,
179
+ notifier : RefCell :: new ( NotifyOnConsole {
180
+ verbose,
181
+ ..Default :: default ( )
182
+ } ) ,
183
+ }
184
+ }
185
+
186
+ fn handle ( & self , n : Notification < ' _ > ) {
187
+ if self . tracker . lock ( ) . unwrap ( ) . handle_notification ( & n) {
188
+ return ;
189
+ }
190
+ self . notifier . borrow_mut ( ) . handle ( n) ;
191
+ }
192
+ }
193
+
170
194
#[ cfg_attr( feature = "otel" , tracing:: instrument) ]
171
195
pub ( crate ) fn set_globals ( current_dir : PathBuf , verbose : bool , quiet : bool ) -> Result < Cfg > {
172
- let download_tracker = DownloadTracker :: new_with_display_progress ( !quiet) ;
173
- let console_notifier = RefCell :: new ( NotifyOnConsole {
174
- verbose,
175
- ..Default :: default ( )
176
- } ) ;
177
-
178
- Cfg :: from_env (
179
- current_dir,
180
- Arc :: new ( move |n : Notification < ' _ > | {
181
- if download_tracker. lock ( ) . unwrap ( ) . handle_notification ( & n) {
182
- return ;
183
- }
184
- console_notifier. borrow_mut ( ) . handle ( n) ;
185
- } ) ,
186
- )
196
+ let notifier = Notifier :: new ( verbose, quiet) ;
197
+ Cfg :: from_env ( current_dir, Arc :: new ( move |n| notifier. handle ( n) ) )
187
198
}
188
199
189
200
pub ( crate ) fn show_channel_update (
0 commit comments