Bug 1343718 - Don't display download progress when we don't know the download size in advance. r=chmanchester draft
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 01 Mar 2017 11:16:27 +0900
changeset 562404 4bfd15f53cf0885a8b0984c0c8532a612f0bb4ae
parent 562403 db9dc89b09d146440392ec2aa6c84bce6aa398e3
child 562405 fbfe40552b2be4940ff66cea8619e84e20a15252
push id54023
push userbmo:mh+mozilla@glandium.org
push dateThu, 13 Apr 2017 23:16:24 +0000
reviewerschmanchester
bugs1343718
milestone55.0a1
Bug 1343718 - Don't display download progress when we don't know the download size in advance. r=chmanchester In most cases, the HTTP response for the download will contain the content-length, but if some error happens (e.g. authentication error), there might not be one, and the download fails with a TypeError for a division by None, instead of failing with a more friendly error message about the HTTP error.
python/mozbuild/mozbuild/artifacts.py
--- a/python/mozbuild/mozbuild/artifacts.py
+++ b/python/mozbuild/mozbuild/artifacts.py
@@ -713,16 +713,18 @@ class ArtifactCache(CacheManager):
 
         self.log(logging.INFO, 'artifact',
             {'path': path},
             'Downloading to temporary location {path}')
         try:
             dl = self._download_manager.download(url, fname)
 
             def download_progress(dl, bytes_so_far, total_size):
+                if not total_size:
+                    return
                 percent = (float(bytes_so_far) / total_size) * 100
                 now = int(percent / 5)
                 if now == self._last_dl_update:
                     return
                 self._last_dl_update = now
                 self.log(logging.INFO, 'artifact',
                          {'bytes_so_far': bytes_so_far, 'total_size': total_size, 'percent': percent},
                          'Downloading... {percent:02.1f} %')