Solving progress not safe issue for api

Progress is not safe so for api its always nil and
code needs to take care of this
This commit is contained in:
Oliver Sauder
2016-11-25 16:25:09 +01:00
committed by Lorenzo Bolla
parent 1c7c07ace7
commit 25d7d7c037
2 changed files with 13 additions and 6 deletions

View File

@@ -550,12 +550,14 @@ func (repo *RemoteRepo) DownloadPackageIndexes(progress aptly.Progress, d aptly.
}
}
err = repo.packageList.Add(p)
if _, ok := err.(*PackageConflictError); ok {
if progress != nil {
progress.ColoredPrintf("@y[!]@| @!skipping package %s: duplicate in packages index@|", p)
if err != nil {
if _, ok := err.(*PackageConflictError); ok {
if progress != nil {
progress.ColoredPrintf("@y[!]@| @!skipping package %s: duplicate in packages index@|", p)
}
} else if err != nil {
return err
}
} else if err != nil {
return err
}
}

View File

@@ -152,6 +152,7 @@ func retryableError(err error) bool {
func (downloader *downloaderImpl) newRequest(ctx context.Context, method, url string) (*http.Request, error) {
req, err := http.NewRequest(method, url, nil)
if err != nil {
return nil, errors.Wrap(err, url)
}
@@ -230,7 +231,11 @@ func (downloader *downloaderImpl) download(req *http.Request, url, destination s
defer outfile.Close()
checksummer := utils.NewChecksumWriter()
writers := []io.Writer{outfile, downloader.aggWriter}
writers := []io.Writer{outfile}
if downloader.progress != nil {
writers = append(writers, downloader.progress)
}
if expected != nil {
writers = append(writers, checksummer)