Kaydet (Commit) ec80ba46 authored tarafından Xavier de Gaye's avatar Xavier de Gaye

Issue #26937: Merge 3.6.

...@@ -50,9 +50,13 @@ import copy ...@@ -50,9 +50,13 @@ import copy
import re import re
try: try:
import grp, pwd import pwd
except ImportError: except ImportError:
grp = pwd = None pwd = None
try:
import grp
except ImportError:
grp = None
# os.symlink on Windows prior to 6.0 raises NotImplementedError # os.symlink on Windows prior to 6.0 raises NotImplementedError
symlink_exception = (AttributeError, NotImplementedError) symlink_exception = (AttributeError, NotImplementedError)
...@@ -2219,22 +2223,25 @@ class TarFile(object): ...@@ -2219,22 +2223,25 @@ class TarFile(object):
def chown(self, tarinfo, targetpath, numeric_owner): def chown(self, tarinfo, targetpath, numeric_owner):
"""Set owner of targetpath according to tarinfo. If numeric_owner """Set owner of targetpath according to tarinfo. If numeric_owner
is True, use .gid/.uid instead of .gname/.uname. 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.
""" """
if pwd and hasattr(os, "geteuid") and os.geteuid() == 0: if hasattr(os, "geteuid") and os.geteuid() == 0:
# We have to be root to do so. # We have to be root to do so.
if numeric_owner: g = tarinfo.gid
g = tarinfo.gid u = tarinfo.uid
u = tarinfo.uid if not numeric_owner:
else:
try: try:
g = grp.getgrnam(tarinfo.gname)[2] if grp:
g = grp.getgrnam(tarinfo.gname)[2]
except KeyError: except KeyError:
g = tarinfo.gid pass
try: try:
u = pwd.getpwnam(tarinfo.uname)[2] if pwd:
u = pwd.getpwnam(tarinfo.uname)[2]
except KeyError: except KeyError:
u = tarinfo.uid pass
try: try:
if tarinfo.issym() and hasattr(os, "lchown"): if tarinfo.issym() and hasattr(os, "lchown"):
os.lchown(targetpath, u, g) os.lchown(targetpath, u, g)
......
...@@ -168,6 +168,10 @@ Core and Builtins ...@@ -168,6 +168,10 @@ Core and Builtins
Library Library
------- -------
- Issue #26937: The chown() method of the tarfile.TarFile class does not fail
now when the grp module cannot be imported, as for example on Android
platforms.
- Issue #28847: dbm.dumb now supports reading read-only files and no longer - Issue #28847: dbm.dumb now supports reading read-only files and no longer
writes the index file when it is not changed. A deprecation warning is now writes the index file when it is not changed. A deprecation warning is now
emitted if the index file is missed and recreated in the 'r' and 'w' modes emitted if the index file is missed and recreated in the 'r' and 'w' modes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment