From 017eeaea29d1fc6bb6c8723c77bdd4216b84f7d8 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Thu, 7 Jul 2016 00:16:51 +0200 Subject: [PATCH] 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 --- lib/ansible/modules/files/unarchive.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/files/unarchive.py b/lib/ansible/modules/files/unarchive.py index 40a63dd771c..c53499b48ed 100644 --- a/lib/ansible/modules/files/unarchive.py +++ b/lib/ansible/modules/files/unarchive.py @@ -441,16 +441,24 @@ class ZipArchive(object): # Do not handle permissions of symlinks 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 - if ztype == '?': + elif ztype == '?': mode = self._permstr_to_octal(permstr, 0) else: 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 - 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): + + if mode != stat.S_IMODE(st.st_mode): change = True itemized[5] = 'p' 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'), ), add_file_common_args = True, + # check-mode only works for zip files # supports_check_mode = True, )