Make a (symbolic) link called targetpath. If it cannot be created (platform limitation), we try to make a copy of the referenced file instead of a link.
(self, tarinfo, targetpath)
| 2499 | os.makedev(tarinfo.devmajor, tarinfo.devminor)) |
| 2500 | |
| 2501 | def makelink(self, tarinfo, targetpath): |
| 2502 | """Make a (symbolic) link called targetpath. If it cannot be created |
| 2503 | (platform limitation), we try to make a copy of the referenced file |
| 2504 | instead of a link. |
| 2505 | """ |
| 2506 | try: |
| 2507 | # For systems that support symbolic and hard links. |
| 2508 | if tarinfo.issym(): |
| 2509 | if os.path.lexists(targetpath): |
| 2510 | # Avoid FileExistsError on following os.symlink. |
| 2511 | os.unlink(targetpath) |
| 2512 | os.symlink(tarinfo.linkname, targetpath) |
| 2513 | else: |
| 2514 | if os.path.exists(tarinfo._link_target): |
| 2515 | os.link(tarinfo._link_target, targetpath) |
| 2516 | else: |
| 2517 | self._extract_member(self._find_link_target(tarinfo), |
| 2518 | targetpath) |
| 2519 | except symlink_exception: |
| 2520 | try: |
| 2521 | self._extract_member(self._find_link_target(tarinfo), |
| 2522 | targetpath) |
| 2523 | except KeyError: |
| 2524 | raise ExtractError("unable to resolve link inside archive") from None |
| 2525 | |
| 2526 | def chown(self, tarinfo, targetpath, numeric_owner): |
| 2527 | """Set owner of targetpath according to tarinfo. If numeric_owner |
no test coverage detected