[Python-checkins] r59713 - in python/branches/release25-maint: Lib/tarfile.py Lib/test/test_tarfile.py Misc/NEWS

lars.gustaebel python-checkins at python.org
Fri Jan 4 15:44:24 CET 2008


Author: lars.gustaebel
Date: Fri Jan  4 15:44:23 2008
New Revision: 59713

Modified:
   python/branches/release25-maint/Lib/tarfile.py
   python/branches/release25-maint/Lib/test/test_tarfile.py
   python/branches/release25-maint/Misc/NEWS
Log:
Issue #1735: TarFile.extractall() now correctly sets directory
permissions and times.

(backport from r59712)


Modified: python/branches/release25-maint/Lib/tarfile.py
==============================================================================
--- python/branches/release25-maint/Lib/tarfile.py	(original)
+++ python/branches/release25-maint/Lib/tarfile.py	Fri Jan  4 15:44:23 2008
@@ -1525,11 +1525,11 @@
 
         # Set correct owner, mtime and filemode on directories.
         for tarinfo in directories:
-            path = os.path.join(path, tarinfo.name)
+            dirpath = os.path.join(path, tarinfo.name)
             try:
-                self.chown(tarinfo, path)
-                self.utime(tarinfo, path)
-                self.chmod(tarinfo, path)
+                self.chown(tarinfo, dirpath)
+                self.utime(tarinfo, dirpath)
+                self.chmod(tarinfo, dirpath)
             except ExtractError, e:
                 if self.errorlevel > 1:
                     raise

Modified: python/branches/release25-maint/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_tarfile.py	(original)
+++ python/branches/release25-maint/Lib/test/test_tarfile.py	Fri Jan  4 15:44:23 2008
@@ -197,6 +197,34 @@
                 self.assert_(tarinfo.name.endswith("/"))
                 self.assert_(not tarinfo.name[:-1].endswith("/"))
 
+    def test_extractall(self):
+        # Test if extractall() correctly restores directory permissions
+        # and times (see issue1735).
+        if sys.platform == "win32":
+            # Win32 has no support for utime() on directories or
+            # fine grained permissions.
+            return
+
+        fobj = StringIO.StringIO()
+        tar = tarfile.open(fileobj=fobj, mode="w:")
+        for name in ("foo", "foo/bar"):
+            tarinfo = tarfile.TarInfo(name)
+            tarinfo.type = tarfile.DIRTYPE
+            tarinfo.mtime = 07606136617
+            tarinfo.mode = 0755
+            tar.addfile(tarinfo)
+        tar.close()
+        fobj.seek(0)
+
+        TEMPDIR = os.path.join(dirname(), "extract-test")
+        tar = tarfile.open(fileobj=fobj)
+        tar.extractall(TEMPDIR)
+        for tarinfo in tar.getmembers():
+            path = os.path.join(TEMPDIR, tarinfo.name)
+            self.assertEqual(tarinfo.mode, os.stat(path).st_mode & 0777)
+            self.assertEqual(tarinfo.mtime, os.path.getmtime(path))
+        tar.close()
+
 
 class ReadStreamTest(ReadTest):
     sep = "|"

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Fri Jan  4 15:44:23 2008
@@ -53,6 +53,9 @@
 Library
 -------
 
+- Issue #1735: TarFile.extractall() now correctly sets directory permissions
+  and times.
+
 - Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
 
 - Issue #1700: Regular expression inline flags incorrectly handle certain


More information about the Python-checkins mailing list