Mercurial > hg
comparison mercurial/archival.py @ 45048:2c0043977b6d stable
archival: abort if compression method is unavailable
`tarfile.CompressionError` is documented to be the "exception for unavailable
compression methods".
Also, make tests conditional on whether the lzma module is available or not.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Wed, 08 Jul 2020 08:57:21 +0200 |
parents | f8427841c8fc |
children | 3a6ec080b521 |
comparison
equal
deleted
inserted
replaced
45047:40120de810ba | 45048:2c0043977b6d |
---|---|
187 self.fileobj = gzfileobj | 187 self.fileobj = gzfileobj |
188 return tarfile.TarFile.taropen( # pytype: disable=attribute-error | 188 return tarfile.TarFile.taropen( # pytype: disable=attribute-error |
189 name, pycompat.sysstr(mode), gzfileobj | 189 name, pycompat.sysstr(mode), gzfileobj |
190 ) | 190 ) |
191 else: | 191 else: |
192 return tarfile.open(name, pycompat.sysstr(mode + kind), fileobj) | 192 try: |
193 return tarfile.open( | |
194 name, pycompat.sysstr(mode + kind), fileobj | |
195 ) | |
196 except tarfile.CompressionError as e: | |
197 raise error.Abort(pycompat.bytestr(e)) | |
193 | 198 |
194 if isinstance(dest, bytes): | 199 if isinstance(dest, bytes): |
195 self.z = taropen(b'w:', name=dest) | 200 self.z = taropen(b'w:', name=dest) |
196 else: | 201 else: |
197 self.z = taropen(b'w|', fileobj=dest) | 202 self.z = taropen(b'w|', fileobj=dest) |