Skip to content

Commit 298922b

Browse files
committed
Using NoResume when download index files
1 parent 430a3e9 commit 298922b

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

Diff for: Gopkg.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var LibraryIndexURL, _ = url.Parse("https://downloads.arduino.cc/libraries/libra
2929
// UpdateIndex downloads the libraries index file from Arduino repository.
3030
func (lm *LibrariesManager) UpdateIndex() (*downloader.Downloader, error) {
3131
lm.IndexFile.Parent().MkdirAll()
32-
lm.IndexFile.Remove()
3332
// TODO: Download from gzipped URL index
34-
return downloader.Download(lm.IndexFile.String(), LibraryIndexURL.String())
33+
return downloader.Download(lm.IndexFile.String(), LibraryIndexURL.String(), downloader.NoResume)
3534
}

Diff for: vendor/go.bug.st/downloader/downloader.go

+20-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ import (
1919
type Downloader struct {
2020
URL string
2121
Done chan bool
22-
NoResume bool
2322
resp *http.Response
2423
out io.Writer
2524
completed int64
2625
size int64
2726
err error
2827
}
2928

29+
// DownloadOptions are optional flags that can be passed to Download function
30+
type DownloadOptions int
31+
32+
const (
33+
// NoResume will not try to resume a partial download
34+
NoResume DownloadOptions = iota
35+
)
36+
3037
// Close the download
3138
func (d *Downloader) Close() error {
3239
return d.resp.Body.Close()
@@ -98,16 +105,24 @@ func (d *Downloader) Completed() int64 {
98105
// Download returns an asynchronous downloader that will donwload the specified url
99106
// in the specified file. A download resume is tried if a file shorter than the requested
100107
// url is already present.
101-
func Download(file string, url string) (*Downloader, error) {
108+
func Download(file string, url string, options ...DownloadOptions) (*Downloader, error) {
109+
noResume := false
110+
for _, opt := range options {
111+
if opt == NoResume {
112+
noResume = true
113+
}
114+
}
102115
req, err := http.NewRequest("GET", url, nil)
103116
if err != nil {
104117
return nil, fmt.Errorf("setting up HTTP request: %s", err)
105118
}
106119

107120
var completed int64
108-
if info, err := os.Stat(file); err == nil {
109-
completed = info.Size()
110-
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", completed))
121+
if !noResume {
122+
if info, err := os.Stat(file); err == nil {
123+
completed = info.Size()
124+
req.Header.Set("Range", fmt.Sprintf("bytes=%d-", completed))
125+
}
111126
}
112127

113128
client := &http.Client{}

0 commit comments

Comments
 (0)