@@ -41,6 +41,7 @@ macro_rules! t {
41
41
42
42
static TEST : AtomicUsize = AtomicUsize :: new ( 0 ) ;
43
43
44
+ #[ derive( Copy , Clone ) ]
44
45
struct Config {
45
46
pub remote : bool ,
46
47
pub verbose : bool ,
@@ -71,6 +72,12 @@ impl Config {
71
72
}
72
73
}
73
74
75
+ fn print_verbose ( s : & str , conf : Config ) {
76
+ if conf. verbose {
77
+ println ! ( "{}" , s) ;
78
+ }
79
+ }
80
+
74
81
fn main ( ) {
75
82
println ! ( "starting test server" ) ;
76
83
@@ -92,7 +99,7 @@ fn main() {
92
99
tmp_dir. push ( "tmp" ) ;
93
100
( work_dir, tmp_dir)
94
101
} ;
95
- println ! ( "listening!" ) ;
102
+ println ! ( "listening on {}!" , bind_addr ) ;
96
103
97
104
t ! ( fs:: create_dir_all( & work) ) ;
98
105
t ! ( fs:: create_dir_all( & tmp) ) ;
@@ -106,23 +113,25 @@ fn main() {
106
113
continue ;
107
114
}
108
115
if & buf[ ..] == b"ping" {
116
+ print_verbose ( "Received ping" , config) ;
109
117
t ! ( socket. write_all( b"pong" ) ) ;
110
118
} else if & buf[ ..] == b"push" {
111
- handle_push ( socket, & work) ;
119
+ handle_push ( socket, & work, config ) ;
112
120
} else if & buf[ ..] == b"run " {
113
121
let lock = lock. clone ( ) ;
114
122
let work = work. clone ( ) ;
115
123
let tmp = tmp. clone ( ) ;
116
- thread:: spawn ( move || handle_run ( socket, & work, & tmp, & lock) ) ;
124
+ thread:: spawn ( move || handle_run ( socket, & work, & tmp, & lock, config ) ) ;
117
125
} else {
118
126
panic ! ( "unknown command {:?}" , buf) ;
119
127
}
120
128
}
121
129
}
122
130
123
- fn handle_push ( socket : TcpStream , work : & Path ) {
131
+ fn handle_push ( socket : TcpStream , work : & Path , config : Config ) {
124
132
let mut reader = BufReader :: new ( socket) ;
125
- recv ( & work, & mut reader) ;
133
+ let dst = recv ( & work, & mut reader) ;
134
+ print_verbose ( & format ! ( "push {:#?}" , dst) , config) ;
126
135
127
136
let mut socket = reader. into_inner ( ) ;
128
137
t ! ( socket. write_all( b"ack " ) ) ;
@@ -138,7 +147,7 @@ impl Drop for RemoveOnDrop<'_> {
138
147
}
139
148
}
140
149
141
- fn handle_run ( socket : TcpStream , work : & Path , tmp : & Path , lock : & Mutex < ( ) > ) {
150
+ fn handle_run ( socket : TcpStream , work : & Path , tmp : & Path , lock : & Mutex < ( ) > , config : Config ) {
142
151
let mut arg = Vec :: new ( ) ;
143
152
let mut reader = BufReader :: new ( socket) ;
144
153
@@ -205,6 +214,7 @@ fn handle_run(socket: TcpStream, work: &Path, tmp: &Path, lock: &Mutex<()>) {
205
214
// binary is and then we'll download it all to the exe path we calculated
206
215
// earlier.
207
216
let exe = recv ( & path, & mut reader) ;
217
+ print_verbose ( & format ! ( "run {:#?}" , exe) , config) ;
208
218
209
219
let mut cmd = Command :: new ( & exe) ;
210
220
cmd. args ( args) ;
0 commit comments