| 1642 | |
| 1643 | @os_helper.skip_unless_symlink |
| 1644 | def test_extractall_symlinks(self): |
| 1645 | # Test if extractall works properly when tarfile contains symlinks |
| 1646 | tempdir = os.path.join(TEMPDIR, "testsymlinks") |
| 1647 | temparchive = os.path.join(TEMPDIR, "testsymlinks.tar") |
| 1648 | os.mkdir(tempdir) |
| 1649 | try: |
| 1650 | source_file = os.path.join(tempdir,'source') |
| 1651 | target_file = os.path.join(tempdir,'symlink') |
| 1652 | with open(source_file,'w') as f: |
| 1653 | f.write('something\n') |
| 1654 | os.symlink(source_file, target_file) |
| 1655 | with tarfile.open(temparchive, 'w') as tar: |
| 1656 | tar.add(source_file, arcname="source") |
| 1657 | tar.add(target_file, arcname="symlink") |
| 1658 | # Let's extract it to the location which contains the symlink |
| 1659 | with tarfile.open(temparchive, errorlevel=2) as tar: |
| 1660 | # this should not raise OSError: [Errno 17] File exists |
| 1661 | try: |
| 1662 | tar.extractall(path=tempdir, |
| 1663 | filter='fully_trusted') |
| 1664 | except OSError: |
| 1665 | self.fail("extractall failed with symlinked files") |
| 1666 | finally: |
| 1667 | os_helper.unlink(temparchive) |
| 1668 | os_helper.rmtree(tempdir) |
| 1669 | |
| 1670 | def test_pathnames(self): |
| 1671 | self._test_pathname("foo") |