diff options
author | Marat Idrisov <idrisov.m.ti@gmail.com> | 2023-12-19 19:04:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-19 19:04:43 (GMT) |
commit | e1117cb8864ca337a26388a6186aa85f7cc29a94 (patch) | |
tree | de6e948630636debbbb7f9ba09c01c8774d53bcb /Lib/tarfile.py | |
parent | 6a1d5a4c0f209d51ab33d6529935d643bcdb3ba2 (diff) | |
download | cpython-e1117cb8864ca337a26388a6186aa85f7cc29a94.zip cpython-e1117cb8864ca337a26388a6186aa85f7cc29a94.tar.gz cpython-e1117cb8864ca337a26388a6186aa85f7cc29a94.tar.bz2 |
gh-87264: Convert tarinfo type to stat type (GH-113230)
Co-authored-by: val-shkolnikov <val@nvsoft.net>
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-x | Lib/tarfile.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index ec32f9b..5ada0ad 100755 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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(): |