@@ -21,6 +21,7 @@ import (
21
21
"context"
22
22
"errors"
23
23
"fmt"
24
+ "github.com/sirupsen/logrus"
24
25
"os"
25
26
"path/filepath"
26
27
@@ -54,24 +55,25 @@ type Result struct {
54
55
OtaStatus otaapi.Ota
55
56
}
56
57
57
- func buildOtaFile (params * MassUploadParams ) (string , error ) {
58
+ func buildOtaFile (params * MassUploadParams ) (string , string , error ) {
58
59
var otaFile string
60
+ var otaDir string
61
+ var err error
59
62
if params .DoNotApplyHeader {
60
63
otaFile = params .File
61
64
} else {
62
- otaDir , err : = os .MkdirTemp ("" , "" )
65
+ otaDir , err = os .MkdirTemp ("" , "" )
63
66
if err != nil {
64
- return "" , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
67
+ return "" , "" , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
65
68
}
66
69
otaFile = filepath .Join (otaDir , "temp.ota" )
67
- defer os .RemoveAll (otaDir )
68
70
69
71
err = Generate (params .File , otaFile , params .FQBN )
70
72
if err != nil {
71
- return "" , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
73
+ return "" , "" , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
72
74
}
73
75
}
74
- return otaFile , nil
76
+ return otaFile , otaDir , nil
75
77
}
76
78
77
79
// MassUpload command is used to mass upload a firmware OTA,
@@ -84,6 +86,7 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
84
86
}
85
87
86
88
// Generate .ota file
89
+ logrus .Infoln ("Uploading binary" , params .File )
87
90
_ , err := os .Stat (params .File )
88
91
if err != nil {
89
92
return nil , fmt .Errorf ("file %s does not exists: %w" , params .File , err )
@@ -98,10 +101,13 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
98
101
}
99
102
100
103
// Generate .ota file
101
- otaFile , err := buildOtaFile (params )
104
+ otaFile , otaDir , err := buildOtaFile (params )
102
105
if err != nil {
103
106
return nil , err
104
107
}
108
+ if otaDir != "" {
109
+ defer os .RemoveAll (otaDir )
110
+ }
105
111
106
112
iotClient , err := iot .NewClient (cred )
107
113
if err != nil {
@@ -204,6 +210,7 @@ func run(ctx context.Context, uploader otaUploader, otapi otaStatusGetter, ids [
204
210
for _ , id := range ids {
205
211
file , err := os .Open (otaFile )
206
212
if err != nil {
213
+ logrus .Error ("cannot open ota file:" , otaFile )
207
214
r := Result {ID : id , Err : fmt .Errorf ("cannot open ota file" )}
208
215
results = append (results , r )
209
216
continue
@@ -213,6 +220,7 @@ func run(ctx context.Context, uploader otaUploader, otapi otaStatusGetter, ids [
213
220
}
214
221
close (jobs )
215
222
223
+ logrus .Infoln ("Uploading firmware to devices..." )
216
224
for i := 0 ; i < numConcurrentUploads ; i ++ {
217
225
go func () {
218
226
for job := range jobs {
0 commit comments