diff --git a/cmd/asset/update.go b/cmd/asset/update.go index 4420926..0bf7597 100644 --- a/cmd/asset/update.go +++ b/cmd/asset/update.go @@ -25,8 +25,12 @@ func updateAsset(urls map[string]string, assetDir string, updateProxy string) { if len(urls) != 0 { log.Info("Start update assets") for file, url := range urls { - common.DownloadFile(url, path.Join(assetDir, file), updateProxy) // maybe override old asset + if !common.DownloadFile(url, path.Join(assetDir, file), updateProxy) { // maybe override old asset + log.Infof("Try to download asset `%s` again", file) + common.DownloadFile(url, path.Join(assetDir, file), updateProxy) // download retry + } } + log.Infof("Assets update complete") } } diff --git a/cmd/common/file.go b/cmd/common/file.go index a848cc7..4ef423d 100644 --- a/cmd/common/file.go +++ b/cmd/common/file.go @@ -74,7 +74,7 @@ func CopyFile(source string, target string) { } } -func DownloadFile(fileUrl string, filePath string, proxyUrl string) { +func DownloadFile(fileUrl string, filePath string, proxyUrl string) bool { log.Debugf("File download `%s` => `%s`", fileUrl, filePath) client := http.Client{} if proxyUrl != "" { // use proxy for download @@ -94,7 +94,7 @@ func DownloadFile(fileUrl string, filePath string, proxyUrl string) { }() if err != nil { log.Errorf("Download `%s` error -> %v", fileUrl, err) - return + return false } output, err := os.OpenFile(filePath, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) defer output.Close() @@ -102,7 +102,9 @@ func DownloadFile(fileUrl string, filePath string, proxyUrl string) { log.Panicf("Open `%s` error -> %v", filePath, err) } if _, err = io.Copy(output, resp.Body); err != nil { - log.Panicf("File `%s` save error -> %v", filePath, err) + log.Errorf("File `%s` save error -> %v", filePath, err) + return false } log.Infof("Download success `%s` => `%s`", fileUrl, filePath) + return true }