|
|
@ -318,35 +318,44 @@ def get_state(path):
|
|
|
|
# This should be moved into the common file utilities
|
|
|
|
# This should be moved into the common file utilities
|
|
|
|
def recursive_set_attributes(b_path, follow, file_args, mtime, atime):
|
|
|
|
def recursive_set_attributes(b_path, follow, file_args, mtime, atime):
|
|
|
|
changed = False
|
|
|
|
changed = False
|
|
|
|
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)
|
|
|
|
|
|
|
|
if not os.path.islink(b_fsname):
|
|
|
|
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
# Change perms on the link
|
|
|
|
for b_root, b_dirs, b_files in os.walk(b_path):
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
for b_fsobj in b_dirs + b_files:
|
|
|
|
tmp_file_args['path'] = to_native(b_fsname, errors='surrogate_or_strict')
|
|
|
|
b_fsname = os.path.join(b_root, b_fsobj)
|
|
|
|
changed |= module.set_fs_attributes_if_different(tmp_file_args, changed, expand=False)
|
|
|
|
if not os.path.islink(b_fsname):
|
|
|
|
changed |= update_timestamp_for_file(tmp_file_args['path'], mtime, atime)
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
|
|
|
|
tmp_file_args['path'] = to_native(b_fsname, errors='surrogate_or_strict')
|
|
|
|
if follow:
|
|
|
|
changed |= module.set_fs_attributes_if_different(tmp_file_args, changed, expand=False)
|
|
|
|
b_fsname = os.path.join(b_root, os.readlink(b_fsname))
|
|
|
|
changed |= update_timestamp_for_file(tmp_file_args['path'], mtime, atime)
|
|
|
|
# The link target could be nonexistent
|
|
|
|
|
|
|
|
if os.path.exists(b_fsname):
|
|
|
|
else:
|
|
|
|
if os.path.isdir(b_fsname):
|
|
|
|
# Change perms on the link
|
|
|
|
# Link is a directory so change perms on the directory's contents
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
changed |= recursive_set_attributes(b_fsname, 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)
|
|
|
|
# Change perms on the file pointed to by the link
|
|
|
|
changed |= update_timestamp_for_file(tmp_file_args['path'], mtime, atime)
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
|
|
|
|
tmp_file_args['path'] = to_native(b_fsname, errors='surrogate_or_strict')
|
|
|
|
if follow:
|
|
|
|
changed |= module.set_fs_attributes_if_different(tmp_file_args, changed, expand=False)
|
|
|
|
b_fsname = os.path.join(b_root, os.readlink(b_fsname))
|
|
|
|
changed |= update_timestamp_for_file(tmp_file_args['path'], mtime, atime)
|
|
|
|
# The link target could be nonexistent
|
|
|
|
|
|
|
|
if os.path.exists(b_fsname):
|
|
|
|
|
|
|
|
if os.path.isdir(b_fsname):
|
|
|
|
|
|
|
|
# Link is a directory so change perms on the directory's contents
|
|
|
|
|
|
|
|
changed |= recursive_set_attributes(b_fsname, follow, file_args, mtime, atime)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Change perms on the file pointed to by the link
|
|
|
|
|
|
|
|
tmp_file_args = file_args.copy()
|
|
|
|
|
|
|
|
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
|
|
|
|
return changed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|