(self)
| 708 | |
| 709 | @os_helper.skip_unless_working_chmod |
| 710 | def test_extractall(self): |
| 711 | # Test if extractall() correctly restores directory permissions |
| 712 | # and times (see issue1735). |
| 713 | tar = tarfile.open(tarname, encoding="iso8859-1") |
| 714 | DIR = os.path.join(TEMPDIR, "extractall") |
| 715 | os.mkdir(DIR) |
| 716 | try: |
| 717 | directories = [t for t in tar if t.isdir()] |
| 718 | tar.extractall(DIR, directories, filter='fully_trusted') |
| 719 | for tarinfo in directories: |
| 720 | path = os.path.join(DIR, tarinfo.name) |
| 721 | if sys.platform != "win32": |
| 722 | # Win32 has no support for fine grained permissions. |
| 723 | self.assertEqual(tarinfo.mode & 0o777, |
| 724 | os.stat(path).st_mode & 0o777, |
| 725 | tarinfo.name) |
| 726 | def format_mtime(mtime): |
| 727 | if isinstance(mtime, float): |
| 728 | return "{} ({})".format(mtime, mtime.hex()) |
| 729 | else: |
| 730 | return "{!r} (int)".format(mtime) |
| 731 | file_mtime = os.path.getmtime(path) |
| 732 | errmsg = "tar mtime {0} != file time {1} of path {2!a}".format( |
| 733 | format_mtime(tarinfo.mtime), |
| 734 | format_mtime(file_mtime), |
| 735 | path) |
| 736 | self.assertEqual(tarinfo.mtime, file_mtime, errmsg) |
| 737 | finally: |
| 738 | tar.close() |
| 739 | os_helper.rmtree(DIR) |
| 740 | |
| 741 | @staticmethod |
| 742 | def test_extractall_default_filter(): |
nothing calls this directly
no test coverage detected