@@ -54,6 +54,26 @@ type Result struct {
54
54
OtaStatus otaapi.Ota
55
55
}
56
56
57
+ func buildOtaFile (params * MassUploadParams ) (string , error ) {
58
+ var otaFile string
59
+ if params .DoNotApplyHeader {
60
+ otaFile = params .File
61
+ } else {
62
+ otaDir , err := os .MkdirTemp ("" , "" )
63
+ if err != nil {
64
+ return "" , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
65
+ }
66
+ otaFile = filepath .Join (otaDir , "temp.ota" )
67
+ defer os .RemoveAll (otaDir )
68
+
69
+ err = Generate (params .File , otaFile , params .FQBN )
70
+ if err != nil {
71
+ return "" , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
72
+ }
73
+ }
74
+ return otaFile , nil
75
+ }
76
+
57
77
// MassUpload command is used to mass upload a firmware OTA,
58
78
// on devices of Arduino IoT Cloud.
59
79
func MassUpload (ctx context.Context , params * MassUploadParams , cred * config.Credentials ) ([]Result , error ) {
@@ -78,21 +98,9 @@ func MassUpload(ctx context.Context, params *MassUploadParams, cred *config.Cred
78
98
}
79
99
80
100
// Generate .ota file
81
- var otaFile string
82
- if params .DoNotApplyHeader {
83
- otaFile = params .File
84
- } else {
85
- otaDir , err := os .MkdirTemp ("" , "" )
86
- if err != nil {
87
- return nil , fmt .Errorf ("%s: %w" , "cannot create temporary folder" , err )
88
- }
89
- otaFile = filepath .Join (otaDir , "temp.ota" )
90
- defer os .RemoveAll (otaDir )
91
-
92
- err = Generate (params .File , otaFile , params .FQBN )
93
- if err != nil {
94
- return nil , fmt .Errorf ("%s: %w" , "cannot generate .ota file" , err )
95
- }
101
+ otaFile , err := buildOtaFile (params )
102
+ if err != nil {
103
+ return nil , err
96
104
}
97
105
98
106
iotClient , err := iot .NewClient (cred )
0 commit comments