Skip to content

Commit 6d55f37

Browse files
committed
Download gzipped version of the library index
1 parent 93ae80c commit 6d55f37

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
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
}

0 commit comments

Comments
 (0)