mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
bpo-18819: tarfile: only set device fields for device files (GH-18080)
The GNU docs describe the `devmajor` and `devminor` fields of the tar header struct only in the context of character and block special files, suggesting that in other cases they are not populated. Typical utilities behave accordingly; this patch teaches `tarfile` to do the same.
This commit is contained in:
parent
4fac7ed43e
commit
674935b8ca
4 changed files with 60 additions and 2 deletions
|
|
@ -930,6 +930,14 @@ class TarInfo(object):
|
|||
"""Return a header block. info is a dictionary with file
|
||||
information, format must be one of the *_FORMAT constants.
|
||||
"""
|
||||
has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE)
|
||||
if has_device_fields:
|
||||
devmajor = itn(info.get("devmajor", 0), 8, format)
|
||||
devminor = itn(info.get("devminor", 0), 8, format)
|
||||
else:
|
||||
devmajor = stn("", 8, encoding, errors)
|
||||
devminor = stn("", 8, encoding, errors)
|
||||
|
||||
parts = [
|
||||
stn(info.get("name", ""), 100, encoding, errors),
|
||||
itn(info.get("mode", 0) & 0o7777, 8, format),
|
||||
|
|
@ -943,8 +951,8 @@ class TarInfo(object):
|
|||
info.get("magic", POSIX_MAGIC),
|
||||
stn(info.get("uname", ""), 32, encoding, errors),
|
||||
stn(info.get("gname", ""), 32, encoding, errors),
|
||||
itn(info.get("devmajor", 0), 8, format),
|
||||
itn(info.get("devminor", 0), 8, format),
|
||||
devmajor,
|
||||
devminor,
|
||||
stn(info.get("prefix", ""), 155, encoding, errors)
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue