@@ -37,6 +37,15 @@ type IndexResource struct {
37
37
SignatureURL * url.URL
38
38
}
39
39
40
+ // IndexFileName returns the index file name as it is saved in data dir (package_xxx_index.json).
41
+ func (res * IndexResource ) IndexFileName () string {
42
+ filename := path .Base (res .URL .Path ) // == package_index.json[.gz] || packacge_index.tar.bz2
43
+ if i := strings .Index (filename , "." ); i != - 1 {
44
+ filename = filename [:i ]
45
+ }
46
+ return filename + ".json"
47
+ }
48
+
40
49
// Download will download the index and possibly check the signature using the Arduino's public key.
41
50
// If the file is in .gz format it will be unpacked first.
42
51
func (res * IndexResource ) Download (destDir * paths.Path , downloadCB rpc.DownloadProgressCB ) error {
@@ -53,18 +62,18 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
53
62
defer tmp .RemoveAll ()
54
63
55
64
// Download index file
56
- indexFileName := path .Base (res .URL .Path ) // == package_index.json[.gz]
57
- tmpIndexPath := tmp .Join (indexFileName )
58
- if err := httpclient .DownloadFile (tmpIndexPath , res .URL .String (), "" , tr ("Downloading index: %s" , indexFileName ), downloadCB , nil , downloader .NoResume ); err != nil {
65
+ downloadFileName := path .Base (res .URL .Path ) // == package_index.json[.gz] || package_index.tar.bz2
66
+ indexFileName := res .IndexFileName () // == package_index.json
67
+ tmpIndexPath := tmp .Join (downloadFileName )
68
+ if err := httpclient .DownloadFile (tmpIndexPath , res .URL .String (), "" , tr ("Downloading index: %s" , downloadFileName ), downloadCB , nil , downloader .NoResume ); err != nil {
59
69
return & arduino.FailedDownloadError {Message : tr ("Error downloading index '%s'" , res .URL ), Cause : err }
60
70
}
61
71
62
72
var signaturePath , tmpSignaturePath * paths.Path
63
73
hasSignature := false
64
74
65
75
// Expand the index if it is compressed
66
- if strings .HasSuffix (indexFileName , ".tar.bz2" ) {
67
- indexFileName = strings .TrimSuffix (indexFileName , ".tar.bz2" ) + ".json" // == package_index.json
76
+ if strings .HasSuffix (downloadFileName , ".tar.bz2" ) {
68
77
signatureFileName := indexFileName + ".sig"
69
78
signaturePath = destDir .Join (signatureFileName )
70
79
@@ -95,8 +104,7 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB rpc.DownloadP
95
104
} else {
96
105
logrus .Infof ("No signature %s found in package index archive %s" , signatureFileName , tmpArchivePath .Base ())
97
106
}
98
- } else if strings .HasSuffix (indexFileName , ".gz" ) {
99
- indexFileName = strings .TrimSuffix (indexFileName , ".gz" ) // == package_index.json
107
+ } else if strings .HasSuffix (downloadFileName , ".gz" ) {
100
108
tmpUnzippedIndexPath := tmp .Join (indexFileName )
101
109
if err := paths .GUnzip (tmpIndexPath , tmpUnzippedIndexPath ); err != nil {
102
110
return & arduino.PermissionDeniedError {Message : tr ("Error extracting %s" , indexFileName ), Cause : err }
0 commit comments