Fix a problem where the newly provided mode is a string (#3769)

* Fix a problem where the newly provided mode is a string

This fixes #3597

* Implement python3-compatible get_exception() handling
pull/18777/head
Dag Wieers 8 years ago committed by Matt Clay
parent 855ca9b204
commit 017eeaea29

@ -441,16 +441,24 @@ class ZipArchive(object):
# Do not handle permissions of symlinks # Do not handle permissions of symlinks
if ftype != 'L': if ftype != 'L':
# Use the new mode provided with the action, if there is one
if self.file_args['mode']:
if isinstance(self.file_args['mode'], int):
mode = self.file_args['mode']
else:
try:
mode = int(self.file_args['mode'], 8)
except Exception:
e = get_exception()
self.module.fail_json(path=path, msg="mode %(mode)s must be in octal form" % self.file_args, details=str(e))
# Only special files require no umask-handling # Only special files require no umask-handling
if ztype == '?': elif ztype == '?':
mode = self._permstr_to_octal(permstr, 0) mode = self._permstr_to_octal(permstr, 0)
else: else:
mode = self._permstr_to_octal(permstr, umask) mode = self._permstr_to_octal(permstr, umask)
if self.file_args['mode'] and self.file_args['mode'] != stat.S_IMODE(st.st_mode):
change = True if mode != stat.S_IMODE(st.st_mode):
err += 'Path %s differs in permissions (%o vs %o)\n' % (path, self.file_args['mode'], stat.S_IMODE(st.st_mode))
itemized[5] = 'p'
elif mode != stat.S_IMODE(st.st_mode):
change = True change = True
itemized[5] = 'p' itemized[5] = 'p'
err += 'Path %s differs in permissions (%o vs %o)\n' % (path, mode, stat.S_IMODE(st.st_mode)) err += 'Path %s differs in permissions (%o vs %o)\n' % (path, mode, stat.S_IMODE(st.st_mode))
@ -700,6 +708,7 @@ def main():
validate_certs = dict(required=False, default=True, type='bool'), validate_certs = dict(required=False, default=True, type='bool'),
), ),
add_file_common_args = True, add_file_common_args = True,
# check-mode only works for zip files
# supports_check_mode = True, # supports_check_mode = True,
) )

Loading…
Cancel
Save