@@ -32,6 +32,7 @@ package test
3232import (
3333 "arduino.cc/builder/constants"
3434 "arduino.cc/builder/gohasissues"
35+ "arduino.cc/builder/props"
3536 "arduino.cc/builder/utils"
3637 "encoding/json"
3738 "fmt"
@@ -80,7 +81,7 @@ type Core struct {
8081
8182func DownloadCoresAndToolsAndLibraries (t * testing.T ) {
8283 cores := []Core {
83- Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.7 " },
84+ Core {Maintainer : "arduino" , Arch : "avr" , Version : "1.6.8 " },
8485 Core {Maintainer : "arduino" , Arch : "sam" , Version : "1.6.4" },
8586 }
8687
@@ -151,7 +152,9 @@ func patch(t *testing.T) {
151152}
152153
153154func 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 &&
155158 allBoardsManagerCoresAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerCores ) &&
156159 allBoardsManagerCoresAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerRedBearCores ) &&
157160 allBoardsManagerToolsAlreadyDownloadedAndUnpacked (BOARD_MANAGER_FOLDER , boardsManagerTools ) &&
@@ -310,18 +313,37 @@ func boardManagerCoreAlreadyDownloadedAndUnpacked(targetPath string, core Core)
310313 return ! os .IsNotExist (err )
311314}
312315
313- func allCoresAlreadyDownloadedAndUnpacked (targetPath string , cores []Core ) bool {
316+ func allCoresAlreadyDownloadedAndUnpacked (targetPath string , cores []Core ) ( bool , error ) {
314317 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
317324 }
318325 }
319- return true
326+ return true , nil
320327}
321328
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
325347}
326348
327349func allBoardsManagerToolsAlreadyDownloadedAndUnpacked (targetPath string , tools []Tool ) bool {
@@ -367,11 +389,15 @@ func libraryAlreadyDownloadedAndUnpacked(targetPath string, library Library) boo
367389}
368390
369391func 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 {
371397 return nil
372398 }
373399
374- targetPath , err : = filepath .Abs (targetPath )
400+ targetPath , err = filepath .Abs (targetPath )
375401 if err != nil {
376402 return utils .WrapError (err )
377403 }
0 commit comments