Skip to content

Commit 2cdc095

Browse files
committed
Download gzipped version of the library index
1 parent cdbebe9 commit 2cdc095

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

Diff for: arduino/libraries/librariesmanager/download.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@ package librariesmanager
1717

1818
import (
1919
"net/url"
20-
21-
"go.bug.st/downloader/v2"
2220
)
2321

24-
// LibraryIndexURL is the URL where to get library index.
22+
// LibraryIndexURL is the URL where to get the library index.
2523
var LibraryIndexURL, _ = url.Parse("https://downloads.arduino.cc/libraries/library_index.json")
2624

27-
// UpdateIndex downloads the libraries index file from Arduino repository.
28-
func (lm *LibrariesManager) UpdateIndex(config *downloader.Config) (*downloader.Downloader, error) {
29-
lm.IndexFile.Parent().MkdirAll()
30-
// TODO: Download from gzipped URL index
31-
return downloader.DownloadWithConfig(lm.IndexFile.String(), LibraryIndexURL.String(), *config, downloader.NoResume)
32-
}
25+
// LibraryIndexGZURL is the URL where to get the gzipped library index.
26+
var LibraryIndexGZURL, _ = url.Parse("https://downloads.arduino.cc/libraries/library_index.json.gz")

Diff for: commands/instances.go

+31-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package commands
1717

1818
import (
1919
"context"
20-
"errors"
2120
"fmt"
2221
"io/ioutil"
2322
"net/url"
@@ -37,6 +36,7 @@ import (
3736
"github.com/arduino/arduino-cli/configuration"
3837
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3938
paths "github.com/arduino/go-paths-helper"
39+
"github.com/pkg/errors"
4040
"github.com/sirupsen/logrus"
4141
"go.bug.st/downloader/v2"
4242
)
@@ -179,14 +179,40 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequ
179179
if err != nil {
180180
return err
181181
}
182-
d, err := lm.UpdateIndex(config)
182+
183+
if err := lm.IndexFile.Parent().MkdirAll(); err != nil {
184+
return err
185+
}
186+
187+
// Create a temp dir to stage all downloads
188+
tmp, err := paths.MkTempDir("", "library_index_download")
183189
if err != nil {
184190
return err
185191
}
186-
Download(d, "Updating index: library_index.json", downloadCB)
187-
if d.Error() != nil {
188-
return d.Error()
192+
defer tmp.RemoveAll()
193+
194+
// Download gzipped library_index
195+
tmpIndexGz := tmp.Join("library_index.json.gz")
196+
if d, err := downloader.DownloadWithConfig(tmpIndexGz.String(), librariesmanager.LibraryIndexGZURL.String(), *config, downloader.NoResume); err != nil {
197+
return err
198+
} else {
199+
if err := Download(d, "Updating index: library_index.json.gz", downloadCB); err != nil {
200+
return errors.Wrap(err, "downloading library_index.json.gz")
201+
}
202+
}
203+
204+
// Extract the real library_index
205+
tmpIndex := tmp.Join("library_index.json")
206+
if err := paths.GUnzip(tmpIndexGz, tmpIndex); err != nil {
207+
return errors.Wrap(err, "unzipping library_index.json.gz")
208+
}
209+
210+
// Copy extracted library_index to final destination
211+
lm.IndexFile.Remove()
212+
if err := tmpIndex.CopyTo(lm.IndexFile); err != nil {
213+
return errors.Wrap(err, "writing library_index.json")
189214
}
215+
190216
if _, err := Rescan(req.GetInstance().GetId()); err != nil {
191217
return fmt.Errorf("rescanning filesystem: %s", err)
192218
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.14
44

55
require (
66
github.com/arduino/board-discovery v0.0.0-20180823133458-1ba29327fb0c
7-
github.com/arduino/go-paths-helper v1.5.0
7+
github.com/arduino/go-paths-helper v1.6.0
88
github.com/arduino/go-properties-orderedmap v1.3.0
99
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
1010
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ github.com/arduino/go-paths-helper v1.4.0 h1:ilnseAdxmN1bFnLxxXHRtcdmt9jBf3O4jtY
1818
github.com/arduino/go-paths-helper v1.4.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
1919
github.com/arduino/go-paths-helper v1.5.0 h1:RVo189hD+GhUS1rQ3gixwK1nSbvVR8MGIGa7Gxv2bdM=
2020
github.com/arduino/go-paths-helper v1.5.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
21+
github.com/arduino/go-paths-helper v1.6.0 h1:S7/d7DqB9XlnvF9KrgSiGmo2oWKmYW6O/DTjj3Bijx4=
22+
github.com/arduino/go-paths-helper v1.6.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2123
github.com/arduino/go-properties-orderedmap v1.3.0 h1:4No/vQopB36e7WUIk6H6TxiSEJPiMrVOCZylYmua39o=
2224
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2325
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b h1:9hDi4F2st6dbLC3y4i02zFT5quS4X6iioWifGlVwfy4=

0 commit comments

Comments
 (0)