@@ -26,7 +26,7 @@ use crate::{Cfg, Notification};
26
26
pub ( crate ) const WARN_COMPLETE_PROFILE : & str = "downloading with complete profile isn't recommended unless you are a developer of the rust language" ;
27
27
28
28
pub ( crate ) fn confirm ( question : & str , default : bool ) -> Result < bool > {
29
- write ! ( process( ) . stdout( ) , "{question} " ) ?;
29
+ write ! ( process( ) . stdout( ) . lock ( ) , "{question} " ) ?;
30
30
let _ = std:: io:: stdout ( ) . flush ( ) ;
31
31
let input = read_line ( ) ?;
32
32
@@ -37,7 +37,7 @@ pub(crate) fn confirm(question: &str, default: bool) -> Result<bool> {
37
37
_ => false ,
38
38
} ;
39
39
40
- writeln ! ( process( ) . stdout( ) ) ?;
40
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
41
41
42
42
Ok ( r)
43
43
}
@@ -49,11 +49,14 @@ pub(crate) enum Confirm {
49
49
}
50
50
51
51
pub ( crate ) fn confirm_advanced ( ) -> Result < Confirm > {
52
- writeln ! ( process( ) . stdout( ) ) ?;
53
- writeln ! ( process( ) . stdout( ) , "1) Proceed with installation (default)" ) ?;
54
- writeln ! ( process( ) . stdout( ) , "2) Customize installation" ) ?;
55
- writeln ! ( process( ) . stdout( ) , "3) Cancel installation" ) ?;
56
- write ! ( process( ) . stdout( ) , ">" ) ?;
52
+ writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
53
+ writeln ! (
54
+ process( ) . stdout( ) . lock( ) ,
55
+ "1) Proceed with installation (default)"
56
+ ) ?;
57
+ writeln ! ( process( ) . stdout( ) . lock( ) , "2) Customize installation" ) ?;
58
+ writeln ! ( process( ) . stdout( ) . lock( ) , "3) Cancel installation" ) ?;
59
+ write ! ( process( ) . stdout( ) . lock( ) , ">" ) ?;
57
60
58
61
let _ = std:: io:: stdout ( ) . flush ( ) ;
59
62
let input = read_line ( ) ?;
@@ -64,17 +67,17 @@ pub(crate) fn confirm_advanced() -> Result<Confirm> {
64
67
_ => Confirm :: No ,
65
68
} ;
66
69
67
- writeln ! ( process( ) . stdout( ) ) ?;
70
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
68
71
69
72
Ok ( r)
70
73
}
71
74
72
75
pub ( crate ) fn question_str ( question : & str , default : & str ) -> Result < String > {
73
- writeln ! ( process( ) . stdout( ) , "{question} [{default}]" ) ?;
76
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} [{default}]" ) ?;
74
77
let _ = std:: io:: stdout ( ) . flush ( ) ;
75
78
let input = read_line ( ) ?;
76
79
77
- writeln ! ( process( ) . stdout( ) ) ?;
80
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
78
81
79
82
if input. is_empty ( ) {
80
83
Ok ( default. to_string ( ) )
@@ -85,12 +88,12 @@ pub(crate) fn question_str(question: &str, default: &str) -> Result<String> {
85
88
86
89
pub ( crate ) fn question_bool ( question : & str , default : bool ) -> Result < bool > {
87
90
let default_text = if default { "(Y/n)" } else { "(y/N)" } ;
88
- writeln ! ( process( ) . stdout( ) , "{question} {default_text}" ) ?;
91
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} {default_text}" ) ?;
89
92
90
93
let _ = std:: io:: stdout ( ) . flush ( ) ;
91
94
let input = read_line ( ) ?;
92
95
93
- writeln ! ( process( ) . stdout( ) ) ?;
96
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
94
97
95
98
if input. is_empty ( ) {
96
99
Ok ( default)
@@ -257,20 +260,20 @@ fn show_channel_updates(
257
260
for ( pkg, banner, width, color, version, previous_version) in data {
258
261
let padding = max_width - width;
259
262
let padding: String = " " . repeat ( padding) ;
260
- let _ = write ! ( t, " {padding}" ) ;
263
+ let _ = write ! ( t. lock ( ) , " {padding}" ) ;
261
264
let _ = t. attr ( term:: Attr :: Bold ) ;
262
265
if let Some ( color) = color {
263
266
let _ = t. fg ( color) ;
264
267
}
265
- let _ = write ! ( t, "{pkg} {banner}" ) ;
268
+ let _ = write ! ( t. lock ( ) , "{pkg} {banner}" ) ;
266
269
let _ = t. reset ( ) ;
267
- let _ = write ! ( t, " - {version}" ) ;
270
+ let _ = write ! ( t. lock ( ) , " - {version}" ) ;
268
271
if let Some ( previous_version) = previous_version {
269
- let _ = write ! ( t, " (from {previous_version})" ) ;
272
+ let _ = write ! ( t. lock ( ) , " (from {previous_version})" ) ;
270
273
}
271
- let _ = writeln ! ( t) ;
274
+ let _ = writeln ! ( t. lock ( ) ) ;
272
275
}
273
- let _ = writeln ! ( t) ;
276
+ let _ = writeln ! ( t. lock ( ) ) ;
274
277
275
278
Ok ( ( ) )
276
279
}
@@ -288,7 +291,7 @@ pub(crate) fn update_all_channels(
288
291
289
292
let show_channel_updates = || {
290
293
if !toolchains. is_empty ( ) {
291
- writeln ! ( process( ) . stdout( ) ) ?;
294
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
292
295
293
296
let t = toolchains
294
297
. into_iter ( )
@@ -382,10 +385,10 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
382
385
. expect ( "rust-std should have a target" ) ;
383
386
if component. installed {
384
387
let _ = t. attr ( term:: Attr :: Bold ) ;
385
- let _ = writeln ! ( t, "{target} (installed)" ) ;
388
+ let _ = writeln ! ( t. lock ( ) , "{target} (installed)" ) ;
386
389
let _ = t. reset ( ) ;
387
390
} else if component. available {
388
- let _ = writeln ! ( t, "{target}" ) ;
391
+ let _ = writeln ! ( t. lock ( ) , "{target}" ) ;
389
392
}
390
393
}
391
394
}
@@ -396,7 +399,9 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
396
399
pub ( crate ) fn list_installed_targets (
397
400
distributable : DistributableToolchain < ' _ > ,
398
401
) -> Result < utils:: ExitCode > {
399
- let mut t = term:: stdout ( ) ;
402
+ let t = term:: stdout ( ) ;
403
+ let mut t_lock = t. lock ( ) ;
404
+
400
405
let manifestation = distributable. get_manifestation ( ) ?;
401
406
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
402
407
let manifest = distributable. get_manifest ( ) ?;
@@ -409,7 +414,7 @@ pub(crate) fn list_installed_targets(
409
414
. as_ref ( )
410
415
. expect ( "rust-std should have a target" ) ;
411
416
if component. installed {
412
- writeln ! ( t , "{target}" ) ?;
417
+ writeln ! ( t_lock , "{target}" ) ?;
413
418
}
414
419
}
415
420
}
@@ -420,6 +425,7 @@ pub(crate) fn list_components(
420
425
distributable : DistributableToolchain < ' _ > ,
421
426
) -> Result < utils:: ExitCode > {
422
427
let mut t = term:: stdout ( ) ;
428
+
423
429
let manifestation = distributable. get_manifestation ( ) ?;
424
430
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
425
431
let manifest = distributable. get_manifest ( ) ?;
@@ -428,26 +434,26 @@ pub(crate) fn list_components(
428
434
let name = component. name ;
429
435
if component. installed {
430
436
t. attr ( term:: Attr :: Bold ) ?;
431
- writeln ! ( t, "{name} (installed)" ) ?;
437
+ writeln ! ( t. lock ( ) , "{name} (installed)" ) ?;
432
438
t. reset ( ) ?;
433
439
} else if component. available {
434
- writeln ! ( t, "{name}" ) ?;
440
+ writeln ! ( t. lock ( ) , "{name}" ) ?;
435
441
}
436
442
}
437
443
438
444
Ok ( utils:: ExitCode ( 0 ) )
439
445
}
440
446
441
447
pub ( crate ) fn list_installed_components ( distributable : DistributableToolchain < ' _ > ) -> Result < ( ) > {
442
- let mut t = term:: stdout ( ) ;
448
+ let t = term:: stdout ( ) ;
443
449
let manifestation = distributable. get_manifestation ( ) ?;
444
450
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
445
451
let manifest = distributable. get_manifest ( ) ?;
446
452
let components = manifest. query_components ( distributable. desc ( ) , & config) ?;
447
453
448
454
for component in components {
449
455
if component. installed {
450
- writeln ! ( t, "{}" , component. name) ?;
456
+ writeln ! ( t. lock ( ) , "{}" , component. name) ?;
451
457
}
452
458
}
453
459
Ok ( ( ) )
@@ -472,7 +478,7 @@ fn print_toolchain_path(
472
478
String :: new ( )
473
479
} ;
474
480
writeln ! (
475
- process( ) . stdout( ) ,
481
+ process( ) . stdout( ) . lock ( ) ,
476
482
"{}{}{}{}" ,
477
483
& toolchain,
478
484
if_default,
@@ -490,7 +496,7 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
490
496
. map ( Into :: into)
491
497
. collect :: < Vec < _ > > ( ) ;
492
498
if toolchains. is_empty ( ) {
493
- writeln ! ( process( ) . stdout( ) , "no installed toolchains" ) ?;
499
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no installed toolchains" ) ?;
494
500
} else {
495
501
let def_toolchain_name = cfg. get_default ( ) ?. map ( |t| ( & t) . into ( ) ) ;
496
502
let cwd = utils:: current_dir ( ) ?;
@@ -528,7 +534,7 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
528
534
let overrides = cfg. settings_file . with ( |s| Ok ( s. overrides . clone ( ) ) ) ?;
529
535
530
536
if overrides. is_empty ( ) {
531
- writeln ! ( process( ) . stdout( ) , "no overrides" ) ?;
537
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no overrides" ) ?;
532
538
} else {
533
539
let mut any_not_exist = false ;
534
540
for ( k, v) in overrides {
@@ -537,15 +543,15 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
537
543
any_not_exist = true ;
538
544
}
539
545
writeln ! (
540
- process( ) . stdout( ) ,
546
+ process( ) . stdout( ) . lock ( ) ,
541
547
"{:<40}\t {:<20}" ,
542
548
utils:: format_path_for_display( & k)
543
549
+ if dir_exists { "" } else { " (not a directory)" } ,
544
550
v
545
551
) ?
546
552
}
547
553
if any_not_exist {
548
- writeln ! ( process( ) . stdout( ) ) ?;
554
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
549
555
info ! (
550
556
"you may remove overrides for non-existent directories with
551
557
`rustup override unset --nonexistent`"
@@ -570,43 +576,51 @@ pub(crate) fn version() -> &'static str {
570
576
pub ( crate ) fn dump_testament ( ) -> Result < utils:: ExitCode > {
571
577
use git_testament:: GitModification :: * ;
572
578
writeln ! (
573
- process( ) . stdout( ) ,
579
+ process( ) . stdout( ) . lock ( ) ,
574
580
"Rustup version renders as: {}" ,
575
581
version( )
576
582
) ?;
577
583
writeln ! (
578
- process( ) . stdout( ) ,
584
+ process( ) . stdout( ) . lock ( ) ,
579
585
"Current crate version: {}" ,
580
586
env!( "CARGO_PKG_VERSION" )
581
587
) ?;
582
588
if TESTAMENT . branch_name . is_some ( ) {
583
589
writeln ! (
584
- process( ) . stdout( ) ,
590
+ process( ) . stdout( ) . lock ( ) ,
585
591
"Built from branch: {}" ,
586
592
TESTAMENT . branch_name. unwrap( )
587
593
) ?;
588
594
} else {
589
- writeln ! ( process( ) . stdout( ) , "Branch information missing" ) ?;
595
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Branch information missing" ) ?;
590
596
}
591
- writeln ! ( process( ) . stdout( ) , "Commit info: {}" , TESTAMENT . commit) ?;
597
+ writeln ! (
598
+ process( ) . stdout( ) . lock( ) ,
599
+ "Commit info: {}" ,
600
+ TESTAMENT . commit
601
+ ) ?;
592
602
if TESTAMENT . modifications . is_empty ( ) {
593
- writeln ! ( process( ) . stdout( ) , "Working tree is clean" ) ?;
603
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Working tree is clean" ) ?;
594
604
} else {
595
605
for fmod in TESTAMENT . modifications {
596
606
match fmod {
597
- Added ( f) => writeln ! ( process( ) . stdout( ) , "Added: {}" , String :: from_utf8_lossy( f) ) ?,
607
+ Added ( f) => writeln ! (
608
+ process( ) . stdout( ) . lock( ) ,
609
+ "Added: {}" ,
610
+ String :: from_utf8_lossy( f)
611
+ ) ?,
598
612
Removed ( f) => writeln ! (
599
- process( ) . stdout( ) ,
613
+ process( ) . stdout( ) . lock ( ) ,
600
614
"Removed: {}" ,
601
615
String :: from_utf8_lossy( f)
602
616
) ?,
603
617
Modified ( f) => writeln ! (
604
- process( ) . stdout( ) ,
618
+ process( ) . stdout( ) . lock ( ) ,
605
619
"Modified: {}" ,
606
620
String :: from_utf8_lossy( f)
607
621
) ?,
608
622
Untracked ( f) => writeln ! (
609
- process( ) . stdout( ) ,
623
+ process( ) . stdout( ) . lock ( ) ,
610
624
"Untracked: {}" ,
611
625
String :: from_utf8_lossy( f)
612
626
) ?,
0 commit comments