func downloadFiles(results []VersionFilesResult, versionDetails *utils.VersionDetails, targetPath string, flags *utils.DownloadFlags) (totalDownloaded int, err error) { size := len(results) downloadedForThread := make([]int, flags.Threads) var wg sync.WaitGroup for i := 0; i < flags.Threads; i++ { wg.Add(1) go func(threadId int) { logMsgPrefix := cliutils.GetLogMsgPrefix(threadId, false) for j := threadId; j < size; j += flags.Threads { pathDetails := &utils.PathDetails{ Subject: versionDetails.Subject, Repo: versionDetails.Repo, Path: results[j].Path} e := utils.DownloadBintrayFile(flags.BintrayDetails, pathDetails, targetPath, flags, logMsgPrefix) if e != nil { err = e continue } downloadedForThread[threadId]++ } wg.Done() }(i) } wg.Wait() for i := range downloadedForThread { totalDownloaded += downloadedForThread[i] } return }
func DownloadFile(pathDetails *utils.PathDetails, targetPath string, flags *utils.DownloadFlags) (err error) { ioutils.CreateTempDirPath() defer ioutils.RemoveTempDir() if flags.BintrayDetails.User == "" { flags.BintrayDetails.User = pathDetails.Subject } err = utils.DownloadBintrayFile(flags.BintrayDetails, pathDetails, targetPath, flags, "") if err != nil { return } log.Info("Downloaded 1 artifact.") return }