@@ -21,12 +21,12 @@ import (
21
21
"context"
22
22
"errors"
23
23
"fmt"
24
- "io/ioutil"
25
24
"os"
26
25
"path/filepath"
27
26
28
27
"github.com/arduino/arduino-cloud-cli/config"
29
28
"github.com/arduino/arduino-cloud-cli/internal/iot"
29
+ otaapi "github.com/arduino/arduino-cloud-cli/internal/ota-api"
30
30
iotclient "github.com/arduino/iot-client-go"
31
31
)
32
32
@@ -46,8 +46,9 @@ type MassUploadParams struct {
46
46
47
47
// Result of an ota upload on a device.
48
48
type Result struct {
49
- ID string
50
- Err error
49
+ ID string
50
+ Err error
51
+ OtaStatus otaapi.Ota
51
52
}
52
53
53
54
// MassUpload command is used to mass upload a firmware OTA,
@@ -60,7 +61,7 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
60
61
}
61
62
62
63
// Generate .ota file
63
- otaDir , err := ioutil . TempDir ("" , "" )
64
+ otaDir , err := os . MkdirTemp ("" , "" )
64
65
if err != nil {
65
66
return nil , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
66
67
}
@@ -76,6 +77,7 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
76
77
if err != nil {
77
78
return nil , err
78
79
}
80
+ otapi := otaapi .NewClient (cred )
79
81
80
82
// Prepare the list of device-ids to update
81
83
d , err := idsGivenTags (ctx , iotClient , params .Tags )
@@ -96,7 +98,7 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
96
98
expiration = otaDeferredExpirationMins
97
99
}
98
100
99
- res := run (ctx , iotClient , valid , otaFile , expiration )
101
+ res := run (ctx , iotClient , otapi , valid , otaFile , expiration )
100
102
res = append (res , invalid ... )
101
103
return res , nil
102
104
}
@@ -155,7 +157,11 @@ type otaUploader interface {
155
157
DeviceOTA (ctx context.Context , id string , file * os.File , expireMins int ) error
156
158
}
157
159
158
- func run (ctx context.Context , uploader otaUploader , ids []string , otaFile string , expiration int ) []Result {
160
+ type otaStatusGetter interface {
161
+ GetOtaLastStatusByDeviceID (deviceID string ) (* otaapi.OtaStatusByDeviceResponse , error )
162
+ }
163
+
164
+ func run (ctx context.Context , uploader otaUploader , otapi otaStatusGetter , ids []string , otaFile string , expiration int ) []Result {
159
165
type job struct {
160
166
id string
161
167
file * os.File
@@ -181,7 +187,14 @@ func run(ctx context.Context, uploader otaUploader, ids []string, otaFile string
181
187
go func () {
182
188
for job := range jobs {
183
189
err := uploader .DeviceOTA (ctx , job .id , job .file , expiration )
184
- resCh <- Result {ID : job .id , Err : err }
190
+ otaResult := Result {ID : job .id , Err : err }
191
+
192
+ otaID , otaapierr := otapi .GetOtaLastStatusByDeviceID (job .id )
193
+ if otaapierr == nil && otaID != nil && len (otaID .Ota ) > 0 {
194
+ otaResult .OtaStatus = otaID .Ota [0 ]
195
+ }
196
+
197
+ resCh <- otaResult
185
198
}
186
199
}()
187
200
}
0 commit comments