@@ -5,7 +5,7 @@ use std::{
5
5
sync:: {
6
6
atomic:: { AtomicUsize , Ordering } ,
7
7
mpsc:: { self , Receiver , TryRecvError } ,
8
- Arc ,
8
+ Arc , RwLock ,
9
9
} ,
10
10
thread,
11
11
} ;
@@ -15,6 +15,8 @@ use crate::{
15
15
weidu_parser:: parse_raw_output,
16
16
} ;
17
17
18
+ const TICK : u64 = 1000 ;
19
+
18
20
pub ( crate ) fn get_user_input ( ) -> String {
19
21
let stdin = io:: stdin ( ) ;
20
22
let mut input = String :: new ( ) ;
@@ -70,15 +72,17 @@ pub(crate) fn handle_io(
70
72
parser_config : Arc < ParserConfig > ,
71
73
timeout : usize ,
72
74
) -> InstallationResult {
75
+ let log = Arc :: new ( RwLock :: new ( String :: new ( ) ) ) ;
73
76
let mut weidu_stdin = child. stdin . take ( ) . unwrap ( ) ;
74
- let wait_counter = Arc :: new ( AtomicUsize :: new ( 0 ) ) ;
77
+ let wait_count = Arc :: new ( AtomicUsize :: new ( 0 ) ) ;
75
78
let raw_output_receiver = create_output_reader ( child. stdout . take ( ) . unwrap ( ) ) ;
76
79
let ( sender, parsed_output_receiver) = mpsc:: channel :: < State > ( ) ;
77
80
parse_raw_output (
78
81
sender,
79
82
raw_output_receiver,
80
83
parser_config,
81
- wait_counter. clone ( ) ,
84
+ wait_count. clone ( ) ,
85
+ log. clone ( ) ,
82
86
timeout,
83
87
) ;
84
88
@@ -93,6 +97,7 @@ pub(crate) fn handle_io(
93
97
}
94
98
State :: CompletedWithErrors { error_details } => {
95
99
log:: error!( "Weidu process seem to have completed with errors" ) ;
100
+ log:: error!( "Dumping log: {}" , log. read( ) . unwrap( ) ) ;
96
101
weidu_stdin
97
102
. write_all ( "\n " . as_bytes ( ) )
98
103
. expect ( "Failed to send final ENTER to weidu process" ) ;
@@ -103,10 +108,12 @@ pub(crate) fn handle_io(
103
108
"Weidu process seem to have been running for {} seconds, exiting" ,
104
109
timeout
105
110
) ;
111
+ log:: error!( "Dumping log: {}" , log. read( ) . unwrap( ) ) ;
106
112
return InstallationResult :: Fail ( "Timed out" . to_string ( ) ) ;
107
113
}
108
114
State :: CompletedWithWarnings => {
109
115
log:: warn!( "Weidu process seem to have completed with warnings" ) ;
116
+ log:: warn!( "Dumping log: {}" , log. read( ) . unwrap( ) ) ;
110
117
weidu_stdin
111
118
. write_all ( "\n " . as_bytes ( ) )
112
119
. expect ( "Failed to send final ENTER to weidu process" ) ;
@@ -127,14 +134,11 @@ pub(crate) fn handle_io(
127
134
}
128
135
}
129
136
Err ( TryRecvError :: Empty ) => {
130
- log:: info!(
131
- "{}\r " ,
132
- "." . repeat( wait_counter. load( Ordering :: Relaxed ) % 10 )
133
- ) ;
137
+ log:: info!( "{}" , "." . repeat( wait_count. load( Ordering :: Relaxed ) % 10 ) ) ;
134
138
std:: io:: stdout ( ) . flush ( ) . expect ( "Failed to flush stdout" ) ;
135
139
136
- wait_counter . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
137
- sleep ( 1000 ) ;
140
+ wait_count . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: Relaxed ) ;
141
+ sleep ( TICK ) ;
138
142
139
143
std:: io:: stdout ( ) . flush ( ) . expect ( "Failed to flush stdout" ) ;
140
144
}
0 commit comments