| 1659 | |
| 1660 | @os_helper.skip_unless_symlink |
| 1661 | def test_extractall_symlinks(self): |
| 1662 | # Test if extractall works properly when tarfile contains symlinks |
| 1663 | tempdir = os.path.join(TEMPDIR, "testsymlinks") |
| 1664 | temparchive = os.path.join(TEMPDIR, "testsymlinks.tar") |
| 1665 | os.mkdir(tempdir) |
| 1666 | try: |
| 1667 | source_file = os.path.join(tempdir,'source') |
| 1668 | target_file = os.path.join(tempdir,'symlink') |
| 1669 | with open(source_file,'w') as f: |
| 1670 | f.write('something\n') |
| 1671 | os.symlink(source_file, target_file) |
| 1672 | with tarfile.open(temparchive, 'w') as tar: |
| 1673 | tar.add(source_file, arcname="source") |
| 1674 | tar.add(target_file, arcname="symlink") |
| 1675 | # Let's extract it to the location which contains the symlink |
| 1676 | with tarfile.open(temparchive, errorlevel=2) as tar: |
| 1677 | # this should not raise OSError: [Errno 17] File exists |
| 1678 | try: |
| 1679 | tar.extractall(path=tempdir, |
| 1680 | filter='fully_trusted') |
| 1681 | except OSError: |
| 1682 | self.fail("extractall failed with symlinked files") |
| 1683 | finally: |
| 1684 | os_helper.unlink(temparchive) |
| 1685 | os_helper.rmtree(tempdir) |
| 1686 | |
| 1687 | def test_pathnames(self): |
| 1688 | self._test_pathname("foo") |