summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2008-01-04 14:44:23 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2008-01-04 14:44:23 (GMT)
commite5f9e588c64fd8428701111f2c64a8c092b3d5ba (patch)
tree3ca64e354c5e5921e8f627dcbe34feb6f5d19e55
parent12f03ccece461264acbddea8c9db9a85614483be (diff)
downloadcpython-e5f9e588c64fd8428701111f2c64a8c092b3d5ba.zip
cpython-e5f9e588c64fd8428701111f2c64a8c092b3d5ba.tar.gz
cpython-e5f9e588c64fd8428701111f2c64a8c092b3d5ba.tar.bz2
Issue #1735: TarFile.extractall() now correctly sets directory
permissions and times. (backport from r59712)
-rw-r--r--Lib/tarfile.py8
-rw-r--r--Lib/test/test_tarfile.py28
-rw-r--r--Misc/NEWS3
3 files changed, 35 insertions, 4 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 87b298e..86991c4 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -1525,11 +1525,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
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index f3c090d..dc28038 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -197,6 +197,34 @@ class ReadTest(BaseTest):
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 = "|"
diff --git a/Misc/NEWS b/Misc/NEWS
index 167bedc..299b3af 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -53,6 +53,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.
- Issue #1700: Regular expression inline flags incorrectly handle certain