1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 17:26:15 +02:00

Port CpioRead and CpioHdr to python3

This is a bytes only API because a filename in a cpio archive can
contain, for instance, illegal utf-8 sequences. A user can decode
the filename/content as she wishes.
This commit is contained in:
Marcus Huewe 2019-01-15 20:05:47 +01:00
parent 54ac438eb0
commit 3e326b1bb4

View File

@ -42,7 +42,7 @@ class CpioHdr:
""" """
def __init__(self, mgc, ino, mode, uid, gid, nlink, mtime, filesize, def __init__(self, mgc, ino, mode, uid, gid, nlink, mtime, filesize,
dev_maj, dev_min, rdev_maj, rdev_min, namesize, checksum, dev_maj, dev_min, rdev_maj, rdev_min, namesize, checksum,
off = -1, filename = ''): off=-1, filename=b''):
""" """
All passed parameters are hexadecimal strings (not NUL terminated) except All passed parameters are hexadecimal strings (not NUL terminated) except
off and filename. They will be converted into normal ints. off and filename. They will be converted into normal ints.
@ -82,7 +82,7 @@ class CpioRead:
# supported formats - use name -> mgc mapping to increase readabilty # supported formats - use name -> mgc mapping to increase readabilty
sfmt = { sfmt = {
'newascii': '070701', 'newascii': b'070701',
} }
# header format # header format
@ -164,7 +164,7 @@ class CpioRead:
data = struct.unpack(self.hdr_fmt, data) data = struct.unpack(self.hdr_fmt, data)
hdr = CpioHdr(*data) hdr = CpioHdr(*data)
hdr.filename = self.__file.read(hdr.namesize - 1) hdr.filename = self.__file.read(hdr.namesize - 1)
if hdr.filename == 'TRAILER!!!': if hdr.filename == b'TRAILER!!!':
break break
pos += hdr.namesize pos += hdr.namesize
if self._is_format('newascii'): if self._is_format('newascii'):