Merge pull request #48508 from rallytime/fix-file-bug

[2018.3] Fix 2 bugs found in the file.check_perms function
This commit is contained in:
Nicole Thomas 2018-07-11 11:03:31 -04:00 committed by GitHub
commit 70e5fcb8a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4519,6 +4519,7 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
.format(user))
elif 'cuser' in perms and user != '':
ret['changes']['user'] = user
if group:
if isinstance(group, int):
group = gid_to_group(group)
@ -4539,34 +4540,6 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
elif 'cgroup' in perms and user != '':
ret['changes']['group'] = group
# Mode changes if needed
if mode is not None:
# File is a symlink, ignore the mode setting
# if follow_symlinks is False
if os.path.islink(name) and not follow_symlinks:
pass
else:
mode = salt.utils.files.normalize_mode(mode)
if mode != perms['lmode']:
if __opts__['test'] is True:
ret['changes']['mode'] = mode
else:
set_mode(name, mode)
if mode != salt.utils.files.normalize_mode(get_mode(name)):
ret['result'] = False
ret['comment'].append(
'Failed to change mode to {0}'.format(mode)
)
else:
ret['changes']['mode'] = mode
if isinstance(orig_comment, six.string_types):
if orig_comment:
ret['comment'].insert(0, orig_comment)
ret['comment'] = '; '.join(ret['comment'])
if __opts__['test'] is True and ret['changes']:
ret['result'] = None
if not salt.utils.platform.is_windows() and not is_dir:
# Replace attributes on file if it had been removed
if perms.get('lattrs', ''):
@ -4619,6 +4592,18 @@ def check_perms(name, ret, user, group, mode, attrs=None, follow_symlinks=False)
else:
ret['changes']['attrs'] = attrs
# Only combine the comment list into a string
# after all comments are added above
if isinstance(orig_comment, six.string_types):
if orig_comment:
ret['comment'].insert(0, orig_comment)
ret['comment'] = '; '.join(ret['comment'])
# Set result to None at the very end of the function,
# after all changes have been recorded above
if __opts__['test'] is True and ret['changes']:
ret['result'] = None
return ret, perms