summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-08-27 10:07:56 +0000
committerMartin v. Löwis <martin@v.loewis.de>2005-08-27 10:07:56 +0000
commit6a09a8178b39df97f1cd62360aedc09abc7beef0 (patch)
tree24ed7ee68f031bad211b3d8f7be3488eb47494d8 /Lib/tarfile.py
parentb70be768086f23e7712832ec868cde971662a1a3 (diff)
downloadcpython-6a09a8178b39df97f1cd62360aedc09abc7beef0.tar.gz
Patch #1168594: set sizes of non-regular files to zero. Fixes #1167128.
Will backport to 2.4.
Diffstat (limited to 'Lib/tarfile.py')
-rw-r--r--Lib/tarfile.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index e4c58636c4..60259bc4d0 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1179,17 +1179,16 @@ class TarFile(object):
# Fill the TarInfo object with all
# information we can get.
- tarinfo.name = arcname
- tarinfo.mode = stmd
- tarinfo.uid = statres.st_uid
- tarinfo.gid = statres.st_gid
- if stat.S_ISDIR(stmd):
- # For a directory, the size must be 0
- tarinfo.size = 0
- else:
+ tarinfo.name = arcname
+ tarinfo.mode = stmd
+ tarinfo.uid = statres.st_uid
+ tarinfo.gid = statres.st_gid
+ if stat.S_ISREG(stmd):
tarinfo.size = statres.st_size
+ else:
+ tarinfo.size = 0L
tarinfo.mtime = statres.st_mtime
- tarinfo.type = type
+ tarinfo.type = type
tarinfo.linkname = linkname
if pwd:
try:
@@ -1280,16 +1279,15 @@ class TarFile(object):
self.addfile(tarinfo, f)
f.close()
- if tarinfo.type in (LNKTYPE, SYMTYPE, FIFOTYPE, CHRTYPE, BLKTYPE):
- tarinfo.size = 0L
- self.addfile(tarinfo)
-
- if tarinfo.isdir():
+ elif tarinfo.isdir():
self.addfile(tarinfo)
if recursive:
for f in os.listdir(name):
self.add(os.path.join(name, f), os.path.join(arcname, f))
+ else:
+ self.addfile(tarinfo)
+
def addfile(self, tarinfo, fileobj=None):
"""Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
given, tarinfo.size bytes are read from it and added to the archive.