1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix dead code in files module (#43479)

* Use pwd.getpwnam instead of non-existent pwd.getpwname

* Add specific exceptions to pwd and grp calls
This commit is contained in:
joren485 2018-09-04 16:06:57 +02:00 committed by Matt Martz
parent cf1006179d
commit cd5d484f7a
2 changed files with 11 additions and 11 deletions

View file

@ -496,13 +496,13 @@ def main():
try: # user data
pw = pwd.getpwuid(st.st_uid)
output['pw_name'] = pw.pw_name
except:
except (TypeError, KeyError):
pass
try: # group data
grp_info = grp.getgrgid(st.st_gid)
output['gr_name'] = grp_info.gr_name
except:
except (KeyError, ValueError, OverflowError):
pass
# checksums

View file

@ -303,22 +303,22 @@ class ZipArchive(object):
run_gid = os.getgid()
try:
run_owner = pwd.getpwuid(run_uid).pw_name
except:
except (TypeError, KeyError):
run_owner = run_uid
try:
run_group = grp.getgrgid(run_gid).gr_name
except:
except (KeyError, ValueError, OverflowError):
run_group = run_gid
# Get future user ownership
fut_owner = fut_uid = None
if self.file_args['owner']:
try:
tpw = pwd.getpwname(self.file_args['owner'])
except:
tpw = pwd.getpwnam(self.file_args['owner'])
except KeyError:
try:
tpw = pwd.getpwuid(self.file_args['owner'])
except:
except (TypeError, KeyError):
tpw = pwd.getpwuid(run_uid)
fut_owner = tpw.pw_name
fut_uid = tpw.pw_uid
@ -334,10 +334,10 @@ class ZipArchive(object):
if self.file_args['group']:
try:
tgr = grp.getgrnam(self.file_args['group'])
except:
except (ValueError, KeyError):
try:
tgr = grp.getgrgid(self.file_args['group'])
except:
except (KeyError, ValueError, OverflowError):
tgr = grp.getgrgid(run_gid)
fut_group = tgr.gr_name
fut_gid = tgr.gr_gid
@ -528,7 +528,7 @@ class ZipArchive(object):
owner = uid = None
try:
owner = pwd.getpwuid(st.st_uid).pw_name
except:
except (TypeError, KeyError):
uid = st.st_uid
# If we are not root and requested owner is not our user, fail
@ -548,7 +548,7 @@ class ZipArchive(object):
group = gid = None
try:
group = grp.getgrgid(st.st_gid).gr_name
except:
except (KeyError, ValueError, OverflowError):
gid = st.st_gid
if run_uid != 0 and fut_gid not in groups: