Set owner of targetpath according to tarinfo. If numeric_owner is True, use .gid/.uid instead of .gname/.uname. If numeric_owner is False, fall back to .gid/.uid when the search based on name fails.
(self, tarinfo, targetpath, numeric_owner)
| 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 |
| 2528 | is True, use .gid/.uid instead of .gname/.uname. If numeric_owner |
| 2529 | is False, fall back to .gid/.uid when the search based on name |
| 2530 | fails. |
| 2531 | """ |
| 2532 | if hasattr(os, "geteuid") and os.geteuid() == 0: |
| 2533 | # We have to be root to do so. |
| 2534 | g = tarinfo.gid |
| 2535 | u = tarinfo.uid |
| 2536 | if not numeric_owner: |
| 2537 | try: |
| 2538 | if grp and tarinfo.gname: |
| 2539 | g = grp.getgrnam(tarinfo.gname)[2] |
| 2540 | except KeyError: |
| 2541 | pass |
| 2542 | try: |
| 2543 | if pwd and tarinfo.uname: |
| 2544 | u = pwd.getpwnam(tarinfo.uname)[2] |
| 2545 | except KeyError: |
| 2546 | pass |
| 2547 | if g is None: |
| 2548 | g = -1 |
| 2549 | if u is None: |
| 2550 | u = -1 |
| 2551 | try: |
| 2552 | if tarinfo.issym() and hasattr(os, "lchown"): |
| 2553 | os.lchown(targetpath, u, g) |
| 2554 | else: |
| 2555 | os.chown(targetpath, u, g) |
| 2556 | except OSError as e: |
| 2557 | raise ExtractError("could not change owner") from e |
| 2558 | |
| 2559 | def chmod(self, tarinfo, targetpath): |
| 2560 | """Set file permissions of targetpath according to tarinfo. |
no test coverage detected