summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2005-10-28 05:52:22 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2005-10-28 05:52:22 +0000
commit202acc1b223ac264b01b1711f4e8c6d834117602 (patch)
treeeed94dbcf38acff8e837e9480e36f518930720bd /Lib/tarfile.py
parent21244e75b84d3756939ba5c8afa33481d7c0cb4e (diff)
downloadcpython-202acc1b223ac264b01b1711f4e8c6d834117602.tar.gz
Patch #1338314, Bug #1336623: fix tarfile so it can extract
REGTYPE directories from tarfiles written by old programs. Will backport.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index c86248c1a4..0b3d477171 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -739,6 +739,11 @@ class TarInfo(object):
tarinfo.devmajor = tarinfo.devmajor = 0
tarinfo.prefix = buf[345:500]
+ # Some old tar programs represent a directory as a regular
+ # file with a trailing slash.
+ if tarinfo.isreg() and tarinfo.name.endswith("/"):
+ tarinfo.type = DIRTYPE
+
# The prefix field is used for filenames > 100 in
# the POSIX standard.
# name = prefix + '/' + name
@@ -746,7 +751,7 @@ class TarInfo(object):
tarinfo.name = normpath(os.path.join(nts(tarinfo.prefix), tarinfo.name))
# Directory names should have a '/' at the end.
- if tarinfo.isdir() and tarinfo.name[-1:] != "/":
+ if tarinfo.isdir():
tarinfo.name += "/"
return tarinfo
@@ -1716,10 +1721,6 @@ class TarFile(object):
# Skip the following data blocks.
self.offset += self._block(tarinfo.size)
- if tarinfo.isreg() and tarinfo.name[:-1] == "/":
- # some old tar programs don't know DIRTYPE
- tarinfo.type = DIRTYPE
-
self.members.append(tarinfo)
return tarinfo