Skip to content

Commit

Permalink
download: respect user-defined timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Sep 30, 2021
1 parent f331ed4 commit 9546a28
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions pkg/plugins/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,34 @@ func Download(s schema.Stage, fs vfs.FS, console Console) error {

func downloadFile(dl schema.Download) error {
log.Debug("Downloading file ", dl.Path, dl.URL)
resp, err := grab.Get(dl.Path, dl.URL)
client := grabClient(dl.Timeout)

req, err := grab.NewRequest(dl.Path, dl.URL)
if err != nil {
log.Fatal(err)
return err
}
resp := client.Do(req)

t := time.NewTicker(500 * time.Millisecond)
defer t.Stop()

Loop:
for {
select {
case <-t.C:
log.Debugf(" transferred %v / %v bytes (%.2f%%)\n",
resp.BytesComplete(),
resp.Size,
100*resp.Progress())

case <-resp.Done:
// download is complete
break Loop
}
}

if err := resp.Err(); err != nil {
return err
}

file := resp.Filename
Expand Down

0 comments on commit 9546a28

Please sign in to comment.