@@ -75,6 +75,8 @@ func Resolve(port, board, file, commandline string, extra Extra, t locater) (str
75
75
76
76
// Network performs a network upload
77
77
func Network (port , board , file , commandline string , auth Auth , l logger ) error {
78
+ Busy = true
79
+
78
80
// Defaults
79
81
if auth .Username == "" {
80
82
auth .Username = "root"
@@ -89,14 +91,16 @@ func Network(port, board, file, commandline string, auth Auth, l logger) error {
89
91
// try with ssh
90
92
err = ssh (port , file , commandline , auth , l )
91
93
}
94
+
95
+ Busy = false
92
96
return err
93
97
}
94
98
95
- // Kill stops any upload process as soon as possible
96
- func Kill () {}
97
-
98
99
// Serial performs a serial upload
99
100
func Serial (port , commandline string , extra Extra , l logger ) error {
101
+ Busy = true
102
+ defer func () { Busy = false }()
103
+
100
104
// some boards needs to be resetted
101
105
if extra .Use1200bpsTouch {
102
106
var err error
@@ -114,6 +118,14 @@ func Serial(port, commandline string, extra Extra, l logger) error {
114
118
return program (z [0 ], z [1 :], l )
115
119
}
116
120
121
+ // Kill stops any upload process as soon as possible
122
+ func Kill () {
123
+ log .Println (cmd )
124
+ if cmd != nil && cmd .Process .Pid > 0 {
125
+ cmd .Process .Kill ()
126
+ }
127
+ }
128
+
117
129
// reset opens the port at 1200bps. It returns the new port name (which could change
118
130
// sometimes) and an error (usually because the port listing failed)
119
131
func reset (port string , wait bool , l logger ) (string , error ) {
@@ -204,9 +216,14 @@ func waitReset(beforeReset []string, l logger) string {
204
216
return port
205
217
}
206
218
219
+ // cmd is the upload command
220
+ var cmd * exec.Cmd
221
+
207
222
// program spawns the given binary with the given args, logging the sdtout and stderr
208
223
// through the logger
209
224
func program (binary string , args []string , l logger ) error {
225
+ defer func () { cmd = nil }()
226
+
210
227
// remove quotes form binary command and args
211
228
binary = strings .Replace (binary , "\" " , "" , - 1 )
212
229
@@ -220,23 +237,23 @@ func program(binary string, args []string, l logger) error {
220
237
extension = ".exe"
221
238
}
222
239
223
- oscmd : = exec .Command (binary , args ... )
240
+ cmd = exec .Command (binary , args ... )
224
241
225
- utilities .TellCommandNotToSpawnShell (oscmd )
242
+ utilities .TellCommandNotToSpawnShell (cmd )
226
243
227
- stdout , err := oscmd .StdoutPipe ()
244
+ stdout , err := cmd .StdoutPipe ()
228
245
if err != nil {
229
246
return errors .Wrapf (err , "Retrieve output" )
230
247
}
231
248
232
- stderr , err := oscmd .StderrPipe ()
249
+ stderr , err := cmd .StderrPipe ()
233
250
if err != nil {
234
251
return errors .Wrapf (err , "Retrieve output" )
235
252
}
236
253
237
254
info (l , "Flashing with command:" + binary + extension + " " + strings .Join (args , " " ))
238
255
239
- err = oscmd .Start ()
256
+ err = cmd .Start ()
240
257
241
258
stdoutCopy := bufio .NewScanner (stdout )
242
259
stderrCopy := bufio .NewScanner (stderr )
@@ -256,9 +273,11 @@ func program(binary string, args []string, l logger) error {
256
273
}
257
274
}()
258
275
259
- err = oscmd .Wait ()
260
-
261
- return errors .Wrapf (err , "Executing command" )
276
+ err = cmd .Wait ()
277
+ if err != nil {
278
+ return errors .Wrapf (err , "Executing command" )
279
+ }
280
+ return nil
262
281
}
263
282
264
283
func form (port , board , file string , auth Auth , l logger ) error {
@@ -280,6 +299,7 @@ func form(port, board, file string, auth Auth, l logger) error {
280
299
if _ , err = io .Copy (fw , f ); err != nil {
281
300
return errors .Wrapf (err , "Copy form file" )
282
301
}
302
+
283
303
// Add the other fields
284
304
board = strings .Replace (board , ":" , "_" , - 1 )
285
305
if fw , err = w .CreateFormField ("board" ); err != nil {
@@ -288,6 +308,7 @@ func form(port, board, file string, auth Auth, l logger) error {
288
308
if _ , err = fw .Write ([]byte (board )); err != nil {
289
309
return errors .Wrapf (err , "" )
290
310
}
311
+
291
312
// Don't forget to close the multipart writer.
292
313
// If you don't close it, your request will be missing the terminating boundary.
293
314
w .Close ()
0 commit comments