mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(cli): retry download when panicing
Will retry to download plugins once if the zip lib panics. closes #4068
This commit is contained in:
parent
1509b4cb6e
commit
f397d0ddd7
@ -111,7 +111,21 @@ func RemoveGitBuildFromname(pluginname, filename string) string {
|
||||
return r.ReplaceAllString(filename, pluginname+"/")
|
||||
}
|
||||
|
||||
var retryCount = 0
|
||||
|
||||
func downloadFile(pluginName, filepath, url string) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
retryCount++
|
||||
if retryCount == 1 {
|
||||
log.Debug("\nFailed downloading. Will retry once.\n")
|
||||
downloadFile(pluginName, filepath, url)
|
||||
} else {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -122,12 +136,6 @@ func downloadFile(pluginName, filepath, url string) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Got statuscode %s from %s\n", resp.Status, url)
|
||||
|
||||
if resp.StatusCode == 302 || resp.StatusCode == 301 {
|
||||
str, _ := ioutil.ReadAll(resp.Body)
|
||||
log.Info("body %s\n\n", string(str))
|
||||
}
|
||||
|
||||
r, err := zip.NewReader(bytes.NewReader(body), resp.ContentLength)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user