[Python-checkins] commit of r41341 - in python/branches/release24-maint: Lib Lib/test Misc

neal.norwitz@python.org neal.norwitz at python.org
Fri Oct 28 08:00:52 CEST 2005


Author: neal.norwitz
Date: Fri Oct 28 08:00:51 2005
New Revision: 41341

Modified:
   python/branches/release24-maint/Lib/tarfile.py
   python/branches/release24-maint/Lib/test/test_tarfile.py
   python/branches/release24-maint/Misc/NEWS
Log:
Backport:
- Patch #1338314, Bug #1336623: fix tarfile so it can extract
  REGTYPE directories from tarfiles written by old programs.


Modified: python/branches/release24-maint/Lib/tarfile.py
==============================================================================
--- python/branches/release24-maint/Lib/tarfile.py	(original)
+++ python/branches/release24-maint/Lib/tarfile.py	Fri Oct 28 08:00:51 2005
@@ -688,6 +688,11 @@
             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
@@ -695,7 +700,7 @@
             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
 
@@ -1628,10 +1633,6 @@
             # 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
 

Modified: python/branches/release24-maint/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_tarfile.py	(original)
+++ python/branches/release24-maint/Lib/test/test_tarfile.py	Fri Oct 28 08:00:51 2005
@@ -134,6 +134,30 @@
                          "readlines() after seek failed")
             fobj.close()
 
+    def test_old_dirtype(self):
+        """Test old style dirtype member (bug #1336623).
+        """
+        # Old tars create directory members using a REGTYPE
+        # header with a "/" appended to the filename field.
+
+        # Create an old tar style directory entry.
+        filename = tmpname()
+        tarinfo = tarfile.TarInfo("directory/")
+        tarinfo.type = tarfile.REGTYPE
+
+        fobj = file(filename, "w")
+        fobj.write(tarinfo.tobuf())
+        fobj.close()
+
+        # Test if it is still a directory entry when
+        # read back.
+        tar = tarfile.open(filename)
+        tarinfo = tar.getmembers()[0]
+        tar.close()
+
+        self.assert_(tarinfo.type == tarfile.DIRTYPE)
+        self.assert_(tarinfo.name.endswith("/"))
+
 class ReadStreamTest(ReadTest):
     sep = "|"
 

Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS	(original)
+++ python/branches/release24-maint/Misc/NEWS	Fri Oct 28 08:00:51 2005
@@ -25,6 +25,9 @@
 Extension Modules
 -----------------
 
+- Patch #1338314, Bug #1336623: fix tarfile so it can extract
+  REGTYPE directories from tarfiles written by old programs.
+
 - Patch #1309009, Fix segfault in pyexpat when the XML document is in latin_1,
   but Python incorrectly assumes it is in UTF-8 format
 


More information about the Python-checkins mailing list