From 2ee1c760cc5845c06c0de98c3327299b3d72eb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Fri, 4 Jan 2008 14:00:33 +0000 Subject: Issue #1735: TarFile.extractall() now correctly sets directory permissions and times. (will backport to 2.5) --- Lib/tarfile.py | 8 ++++---- Lib/test/test_tarfile.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'Lib') diff --git a/Lib/tarfile.py b/Lib/tarfile.py index ae242912e9..7143f0b5e2 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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 diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index a280bdda82..d446d5fa2d 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -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): -- cgit v1.2.1