mirror of
https://github.com/openSUSE/osc.git
synced 2024-12-25 17:36:13 +01:00
Refactor tar open functions to return early
This commit is contained in:
parent
395df87fa1
commit
241b34d645
@ -69,34 +69,38 @@ class DebQuery(packagequery.PackageQuery, packagequery.PackageQueryResult):
|
|||||||
|
|
||||||
def _open_tar(self, arfile):
|
def _open_tar(self, arfile):
|
||||||
control = arfile.get_file(b'control.tar')
|
control = arfile.get_file(b'control.tar')
|
||||||
if control:
|
if not control:
|
||||||
return tarfile.open(fileobj=control)
|
return None
|
||||||
return None
|
|
||||||
|
return tarfile.open(fileobj=control)
|
||||||
|
|
||||||
def _open_tar_gz(self, arfile):
|
def _open_tar_gz(self, arfile):
|
||||||
control = arfile.get_file(b'control.tar.gz')
|
control = arfile.get_file(b'control.tar.gz')
|
||||||
if control:
|
if not control:
|
||||||
return tarfile.open(fileobj=control)
|
return None
|
||||||
return None
|
|
||||||
|
return tarfile.open(fileobj=control)
|
||||||
|
|
||||||
def _open_tar_xz(self, arfile):
|
def _open_tar_xz(self, arfile):
|
||||||
control = arfile.get_file(b'control.tar.xz')
|
control = arfile.get_file(b'control.tar.xz')
|
||||||
if control:
|
if not control:
|
||||||
if not HAVE_LZMA:
|
return None
|
||||||
raise DebError(self._path, 'can\'t open control.tar.xz without python-lzma')
|
|
||||||
decompressed = lzma.decompress(control.read())
|
if not HAVE_LZMA:
|
||||||
return tarfile.open(fileobj=BytesIO(decompressed))
|
raise DebError(self._path, 'can\'t open control.tar.xz without python-lzma')
|
||||||
return None
|
decompressed = lzma.decompress(control.read())
|
||||||
|
return tarfile.open(fileobj=BytesIO(decompressed))
|
||||||
|
|
||||||
def _open_tar_zst(self, arfile):
|
def _open_tar_zst(self, arfile):
|
||||||
control = arfile.get_file(b'control.tar.zst')
|
control = arfile.get_file(b'control.tar.zst')
|
||||||
if control:
|
if not control:
|
||||||
if not HAVE_ZSTD:
|
return None
|
||||||
raise DebError(self._path, 'can\'t open control.tar.zst without python-zstandard')
|
|
||||||
with zstandard.ZstdDecompressor().stream_reader(BytesIO(control.read())) as reader:
|
if not HAVE_ZSTD:
|
||||||
decompressed = reader.read()
|
raise DebError(self._path, 'can\'t open control.tar.zst without python-zstandard')
|
||||||
return tarfile.open(fileobj=BytesIO(decompressed))
|
with zstandard.ZstdDecompressor().stream_reader(BytesIO(control.read())) as reader:
|
||||||
return None
|
decompressed = reader.read()
|
||||||
|
return tarfile.open(fileobj=BytesIO(decompressed))
|
||||||
|
|
||||||
def _parse_control(self, control, all_tags=False, self_provides=True, *extra_tags):
|
def _parse_control(self, control, all_tags=False, self_provides=True, *extra_tags):
|
||||||
data = control.readline().strip()
|
data = control.readline().strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user