Bug 1547730 - don't fail on an unsupported .seek() needed to support adding from compressed `zipfile.ZipFile` entries. r=#build
☠☠ backed out by ee4b88439111 ☠ ☠
authorJustin Wood <Callek@gmail.com>
Wed, 24 Apr 2019 22:07:53 -0400
changeset 474159 9e9c2e06d0fbf2688be81b6f210a18c3da01cb3a
parent 474158 d282ddabcb3d214f603704468f8e172d09bc7c2d
child 474160 d8d0020e4b9edce245d75feb0f0670f2247d4a73
push id36023
push userncsoregi@mozilla.com
push dateThu, 16 May 2019 21:56:43 +0000
treeherdermozilla-central@786f094a30ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1547730
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1547730 - don't fail on an unsupported .seek() needed to support adding from compressed `zipfile.ZipFile` entries. r=#build Differential Revision: https://phabricator.services.mozilla.com/D29216
python/mozbuild/mozpack/mozjar.py
--- a/python/mozbuild/mozpack/mozjar.py
+++ b/python/mozbuild/mozpack/mozjar.py
@@ -1,15 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
-from io import BytesIO
+from io import (
+    BytesIO,
+    UnsupportedOperation,
+)
 import struct
 import subprocess
 import zlib
 import os
 import six
 from zipfile import (
     ZIP_STORED,
     ZIP_DEFLATED,
@@ -625,18 +628,20 @@ class JarWriter(object):
         if (isinstance(data, (JarFileReader, Deflater)) and
                 data.compress == compress):
             deflater = data
         else:
             deflater = Deflater(compress, compress_level=self._compress_level)
             if isinstance(data, (six.binary_type, six.string_types)):
                 deflater.write(data)
             elif hasattr(data, 'read'):
-                if hasattr(data, 'seek'):
+                try:
                     data.seek(0)
+                except (UnsupportedOperation, AttributeError):
+                    pass
                 deflater.write(data.read())
             else:
                 raise JarWriterError("Don't know how to handle %s" %
                                      type(data))
         # Fill a central directory entry for this new member.
         entry = JarCdirEntry()
         entry['creator_version'] = 20
         if mode is not None: