file: return 'useful' error message for recursion error (#57222)
* file: return 'useful' error message for recursion error Fixes #56397 * Fix line length * Re-phrase the error message
This commit is contained in:
parent
18f2ed63e0
commit
46f8bd47ce
2 changed files with 37 additions and 26 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- file - return more useful error message for recursion error (https://github.com/ansible/ansible/issues/56397)
|
|
@ -318,6 +318,8 @@ def get_state(path):
|
|||
# This should be moved into the common file utilities
|
||||
def recursive_set_attributes(b_path, follow, file_args, mtime, atime):
|
||||
changed = False
|
||||
|
||||
try:
|
||||
for b_root, b_dirs, b_files in os.walk(b_path):
|
||||
for b_fsobj in b_dirs + b_files:
|
||||
b_fsname = os.path.join(b_root, b_fsobj)
|
||||
|
@ -347,6 +349,13 @@ def recursive_set_attributes(b_path, follow, file_args, mtime, atime):
|
|||
tmp_file_args['path'] = to_native(b_fsname, errors='surrogate_or_strict')
|
||||
changed |= module.set_fs_attributes_if_different(tmp_file_args, changed, expand=False)
|
||||
changed |= update_timestamp_for_file(tmp_file_args['path'], mtime, atime)
|
||||
except RuntimeError as e:
|
||||
# on Python3 "RecursionError" is raised which is derived from "RuntimeError"
|
||||
# TODO once this function is moved into the common file utilities, this should probably raise more general exception
|
||||
raise AnsibleModuleError(
|
||||
results={'msg': "Could not recursively set attributes on %s. Original error was: '%s'" % (to_native(b_path), to_native(e))}
|
||||
)
|
||||
|
||||
return changed
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue