@@ -32,6 +32,7 @@ package test
32
32
import (
33
33
"arduino.cc/builder/constants"
34
34
"arduino.cc/builder/gohasissues"
35
+ "arduino.cc/builder/props"
35
36
"arduino.cc/builder/utils"
36
37
"encoding/json"
37
38
"fmt"
@@ -80,7 +81,7 @@ type Core struct {
80
81
81
82
func DownloadCoresAndToolsAndLibraries (t * testing.T ) {
82
83
cores := []Core {
83
- Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.7 " },
84
+ Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.8 " },
84
85
Core {Maintainer : "arduino" , Arch : "sam" , Version : "1.6.4" },
85
86
}
86
87
@@ -151,7 +152,9 @@ func patch(t *testing.T) {
151
152
}
152
153
153
154
func download (t * testing.T , cores , boardsManagerCores , boardsManagerRedBearCores []Core , tools , boardsManagerTools , boardsManagerRFduinoTools []Tool , libraries []Library ) {
154
- if allCoresAlreadyDownloadedAndUnpacked (HARDWARE_FOLDER , cores ) &&
155
+ allCoresDownloaded , err := allCoresAlreadyDownloadedAndUnpacked (HARDWARE_FOLDER , cores )
156
+ NoError (t , err )
157
+ if allCoresDownloaded &&
155
158
allBoardsManagerCoresAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerCores ) &&
156
159
allBoardsManagerCoresAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerRedBearCores ) &&
157
160
allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerTools ) &&
@@ -310,18 +313,37 @@ func boardManagerCoreAlreadyDownloadedAndUnpacked(targetPath string, core Core)
310
313
return ! os .IsNotExist (err )
311
314
}
312
315
313
- func allCoresAlreadyDownloadedAndUnpacked (targetPath string , cores []Core ) bool {
316
+ func allCoresAlreadyDownloadedAndUnpacked (targetPath string , cores []Core ) ( bool , error ) {
314
317
for _ , core := range cores {
315
- if ! coreAlreadyDownloadedAndUnpacked (targetPath , core ) {
316
- return false
318
+ alreadyDownloaded , err := coreAlreadyDownloadedAndUnpacked (targetPath , core )
319
+ if err != nil {
320
+ return false , utils .WrapError (err )
321
+ }
322
+ if ! alreadyDownloaded {
323
+ return false , nil
317
324
}
318
325
}
319
- return true
326
+ return true , nil
320
327
}
321
328
322
- func coreAlreadyDownloadedAndUnpacked (targetPath string , core Core ) bool {
323
- _ , err := os .Stat (filepath .Join (targetPath , core .Maintainer , core .Arch ))
324
- return ! os .IsNotExist (err )
329
+ func coreAlreadyDownloadedAndUnpacked (targetPath string , core Core ) (bool , error ) {
330
+ corePath := filepath .Join (targetPath , core .Maintainer , core .Arch )
331
+
332
+ _ , err := os .Stat (corePath )
333
+ if os .IsNotExist (err ) {
334
+ return false , nil
335
+ }
336
+ platform , err := props .Load (filepath .Join (corePath , "platform.txt" ))
337
+ if err != nil {
338
+ return false , utils .WrapError (err )
339
+ }
340
+
341
+ if core .Version != platform ["version" ] {
342
+ err := os .RemoveAll (corePath )
343
+ return false , utils .WrapError (err )
344
+ }
345
+
346
+ return true , nil
325
347
}
326
348
327
349
func allBoardsManagerToolsAlreadyDownloadedAndUnpacked (targetPath string , tools []Tool ) bool {
@@ -367,11 +389,15 @@ func libraryAlreadyDownloadedAndUnpacked(targetPath string, library Library) boo
367
389
}
368
390
369
391
func downloadAndUnpackCore (core Core , url string , targetPath string ) error {
370
- if coreAlreadyDownloadedAndUnpacked (targetPath , core ) {
392
+ alreadyDownloaded , err := coreAlreadyDownloadedAndUnpacked (targetPath , core )
393
+ if err != nil {
394
+ return utils .WrapError (err )
395
+ }
396
+ if alreadyDownloaded {
371
397
return nil
372
398
}
373
399
374
- targetPath , err : = filepath .Abs (targetPath )
400
+ targetPath , err = filepath .Abs (targetPath )
375
401
if err != nil {
376
402
return utils .WrapError (err )
377
403
}
0 commit comments