@@ -10,6 +10,7 @@ import (
10
10
"encoding/hex"
11
11
"encoding/json"
12
12
"errors"
13
+ "fmt"
13
14
"io"
14
15
"io/ioutil"
15
16
"net/http"
@@ -226,7 +227,7 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
226
227
// Decompress
227
228
t .Logger ("Unpacking tool " + name )
228
229
229
- location := path .Join (dir (), pack , correctTool .Name , correctTool .Version )
230
+ location := path .Join ("tmp" , dir (), pack , correctTool .Name , correctTool .Version )
230
231
err = os .RemoveAll (location )
231
232
232
233
if err != nil {
@@ -240,12 +241,12 @@ func (t *Tools) Download(pack, name, version, behaviour string) error {
240
241
241
242
switch srcType {
242
243
case "application/zip" :
243
- location , err = extractZip (body , location )
244
+ location , err = extractZip (t . Logger , body , location )
244
245
case "application/x-bz2" :
245
246
case "application/octet-stream" :
246
- location , err = extractBz2 (body , location )
247
+ location , err = extractBz2 (t . Logger , body , location )
247
248
case "application/x-gzip" :
248
- location , err = extractTarGz (body , location )
249
+ location , err = extractTarGz (t . Logger , body , location )
249
250
default :
250
251
return errors .New ("Unknown extension for file " + correctSystem .URL )
251
252
}
@@ -392,7 +393,7 @@ func findBaseDir(dirList []string) string {
392
393
return commonBaseDir
393
394
}
394
395
395
- func extractZip (body []byte , location string ) (string , error ) {
396
+ func extractZip (log func ( msg string ) , body []byte , location string ) (string , error ) {
396
397
path , err := utilities .SaveFileonTempDir ("tooldownloaded.zip" , bytes .NewReader (body ))
397
398
r , err := zip .OpenReader (path )
398
399
if err != nil {
@@ -406,6 +407,7 @@ func extractZip(body []byte, location string) (string, error) {
406
407
}
407
408
408
409
basedir := findBaseDir (dirList )
410
+ log (fmt .Sprintf ("selected baseDir %s from Zip Archive Content: %v" , basedir , dirList ))
409
411
410
412
for _ , f := range r .File {
411
413
fullname := filepath .Join (location , strings .Replace (f .Name , basedir , "" , - 1 ))
@@ -439,7 +441,7 @@ func extractZip(body []byte, location string) (string, error) {
439
441
return location , nil
440
442
}
441
443
442
- func extractTarGz (body []byte , location string ) (string , error ) {
444
+ func extractTarGz (log func ( msg string ), body []byte , location string ) (string , error ) {
443
445
bodyCopy := make ([]byte , len (body ))
444
446
copy (bodyCopy , body )
445
447
tarFile , _ := gzip .NewReader (bytes .NewReader (body ))
@@ -456,6 +458,7 @@ func extractTarGz(body []byte, location string) (string, error) {
456
458
}
457
459
458
460
basedir := findBaseDir (dirList )
461
+ log (fmt .Sprintf ("selected baseDir %s from TarGz Archive Content: %v" , basedir , dirList ))
459
462
460
463
tarFile , _ = gzip .NewReader (bytes .NewReader (bodyCopy ))
461
464
tarReader = tar .NewReader (tarFile )
@@ -502,36 +505,8 @@ func extractTarGz(body []byte, location string) (string, error) {
502
505
return location , nil
503
506
}
504
507
505
- func (t * Tools ) installDrivers (location string ) error {
506
- OK_PRESSED := 6
507
- extension := ".bat"
508
- preamble := ""
509
- if runtime .GOOS != "windows" {
510
- extension = ".sh"
511
- // add ./ to force locality
512
- preamble = "./"
513
- }
514
- if _ , err := os .Stat (filepath .Join (location , "post_install" + extension )); err == nil {
515
- t .Logger ("Installing drivers" )
516
- ok := MessageBox ("Installing drivers" , "We are about to install some drivers needed to use Arduino/Genuino boards\n Do you want to continue?" )
517
- if ok == OK_PRESSED {
518
- os .Chdir (location )
519
- t .Logger (preamble + "post_install" + extension )
520
- oscmd := exec .Command (preamble + "post_install" + extension )
521
- if runtime .GOOS != "linux" {
522
- // spawning a shell could be the only way to let the user type his password
523
- TellCommandNotToSpawnShell (oscmd )
524
- }
525
- err = oscmd .Run ()
526
- return err
527
- } else {
528
- return errors .New ("Could not install drivers" )
529
- }
530
- }
531
- return nil
532
- }
533
508
534
- func extractBz2 (body []byte , location string ) (string , error ) {
509
+ func extractBz2 (log func ( msg string ), body []byte , location string ) (string , error ) {
535
510
bodyCopy := make ([]byte , len (body ))
536
511
copy (bodyCopy , body )
537
512
tarFile := bzip2 .NewReader (bytes .NewReader (body ))
@@ -548,6 +523,7 @@ func extractBz2(body []byte, location string) (string, error) {
548
523
}
549
524
550
525
basedir := findBaseDir (dirList )
526
+ log (fmt .Sprintf ("selected baseDir %s from Bz2 Archive Content: %v" , basedir , dirList ))
551
527
552
528
tarFile = bzip2 .NewReader (bytes .NewReader (bodyCopy ))
553
529
tarReader = tar .NewReader (tarFile )
@@ -596,6 +572,36 @@ func extractBz2(body []byte, location string) (string, error) {
596
572
return location , nil
597
573
}
598
574
575
+
576
+ func (t * Tools ) installDrivers (location string ) error {
577
+ OK_PRESSED := 6
578
+ extension := ".bat"
579
+ preamble := ""
580
+ if runtime .GOOS != "windows" {
581
+ extension = ".sh"
582
+ // add ./ to force locality
583
+ preamble = "./"
584
+ }
585
+ if _ , err := os .Stat (filepath .Join (location , "post_install" + extension )); err == nil {
586
+ t .Logger ("Installing drivers" )
587
+ ok := MessageBox ("Installing drivers" , "We are about to install some drivers needed to use Arduino/Genuino boards\n Do you want to continue?" )
588
+ if ok == OK_PRESSED {
589
+ os .Chdir (location )
590
+ t .Logger (preamble + "post_install" + extension )
591
+ oscmd := exec .Command (preamble + "post_install" + extension )
592
+ if runtime .GOOS != "linux" {
593
+ // spawning a shell could be the only way to let the user type his password
594
+ TellCommandNotToSpawnShell (oscmd )
595
+ }
596
+ err = oscmd .Run ()
597
+ return err
598
+ } else {
599
+ return errors .New ("Could not install drivers" )
600
+ }
601
+ }
602
+ return nil
603
+ }
604
+
599
605
func makeExecutable (location string ) error {
600
606
location = path .Join (location , "bin" )
601
607
files , err := ioutil .ReadDir (location )
0 commit comments