]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #1735: TarFile.extractall() now correctly sets
authorLars Gustäbel <lars@gustaebel.de>
Fri, 4 Jan 2008 14:00:33 +0000 (14:00 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Fri, 4 Jan 2008 14:00:33 +0000 (14:00 +0000)
directory permissions and times.

(will backport to 2.5)

Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index ae242912e92c8b0aa8d335777736c14354bb56a2..7143f0b5e2ca2661d144c24a2f1cdcbd9e4fa0cf 100644 (file)
@@ -2037,11 +2037,11 @@ class TarFile(object):
 
         # 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
index a280bdda82e59d0f2cc2c3948c42b27b360d685c..d446d5fa2db3d2a777af5193fbdd40227fcc56d6 100644 (file)
@@ -244,6 +244,23 @@ class MiscReadTest(ReadTest):
         data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read()
         self.assertEqual(md5sum(data), md5_regtype)
 
+    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
+
+        tar = tarfile.open(tarname, encoding="iso8859-1")
+        directories = [t for t in tar if t.isdir()]
+        tar.extractall(TEMPDIR, directories)
+        for tarinfo in directories:
+            path = os.path.join(TEMPDIR, tarinfo.name)
+            self.assertEqual(tarinfo.mode & 0777, os.stat(path).st_mode & 0777)
+            self.assertEqual(tarinfo.mtime, os.path.getmtime(path))
+        tar.close()
+
 
 class StreamReadTest(ReadTest):
 
index 8100c77199984b309562866ed3da1b8448d4701d..7095b5b0a71b1f4f3e0ea210b29217a3416a1476 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -342,6 +342,9 @@ Core and builtins
 Library
 -------
 
+- Issue #1735: TarFile.extractall() now correctly sets directory permissions
+  and times.
+
 - Bug #1713: posixpath.ismount() claims symlink to a mountpoint is a mountpoint.
 
 - Bug #1687: Fxed plistlib.py restricts <integer> to Python int when writing