gh-87264: Convert tarinfo type to stat type (GH-113230)

Co-authored-by: val-shkolnikov <val@nvsoft.net>
This commit is contained in:
Marat Idrisov 2023-12-19 22:04:43 +03:00 committed by GitHub
parent 6a1d5a4c0f
commit e1117cb886
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View file

@ -2106,6 +2106,10 @@ class TarFile(object):
output is produced. `members' is optional and must be a subset of the
list returned by getmembers().
"""
# Convert tarinfo type to stat type.
type2mode = {REGTYPE: stat.S_IFREG, SYMTYPE: stat.S_IFLNK,
FIFOTYPE: stat.S_IFIFO, CHRTYPE: stat.S_IFCHR,
DIRTYPE: stat.S_IFDIR, BLKTYPE: stat.S_IFBLK}
self._check()
if members is None:
@ -2115,7 +2119,8 @@ class TarFile(object):
if tarinfo.mode is None:
_safe_print("??????????")
else:
_safe_print(stat.filemode(tarinfo.mode))
modetype = type2mode.get(tarinfo.type, 0)
_safe_print(stat.filemode(modetype | tarinfo.mode))
_safe_print("%s/%s" % (tarinfo.uname or tarinfo.uid,
tarinfo.gname or tarinfo.gid))
if tarinfo.ischr() or tarinfo.isblk():