Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More intelligent diffing in changes of file.serialize state #48609

Merged
merged 10 commits into from
Dec 11, 2018
1 change: 1 addition & 0 deletions doc/ref/roster/all/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ roster modules
cache
cloud
clustershell
dir
flat
range
scan
Expand Down
4 changes: 2 additions & 2 deletions doc/ref/roster/all/salt.roster.dir.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=================
===============
salt.roster.dir
=================
===============

.. automodule:: salt.roster.dir
:members:
45 changes: 27 additions & 18 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def run():
import salt.payload
import salt.utils.data
import salt.utils.dateutils
import salt.utils.dictdiffer
import salt.utils.dictupdate
import salt.utils.files
import salt.utils.hashutils
Expand Down Expand Up @@ -7210,6 +7211,7 @@ def serialize(name,
salt.utils.data.repack_dictlist(deserializer_opts)
)

existing_data = None
if merge_if_exists:
if os.path.isfile(name):
if deserializer_name not in __serializers__:
Expand Down Expand Up @@ -7286,25 +7288,32 @@ def serialize(name,
else:
ret['result'] = True
ret['comment'] = 'The file {0} is in the correct state'.format(name)
return ret
else:
ret = __salt__['file.manage_file'](
name=name,
sfn='',
ret=ret,
source=None,
source_sum={},
user=user,
group=group,
mode=mode,
attrs=None,
saltenv=__env__,
backup=backup,
makedirs=makedirs,
template=None,
show_changes=show_changes,
encoding=encoding,
encoding_errors=encoding_errors,
contents=contents
)

if isinstance(existing_data, dict) and isinstance(merged_data, dict):
ret['changes']['diff'] = salt.utils.dictdiffer.recursive_diff(
existing_data, merged_data).diffs

return __salt__['file.manage_file'](name=name,
sfn='',
ret=ret,
source=None,
source_sum={},
user=user,
group=group,
mode=mode,
attrs=None,
saltenv=__env__,
backup=backup,
makedirs=makedirs,
template=None,
show_changes=show_changes,
encoding=encoding,
encoding_errors=encoding_errors,
contents=contents)
return ret


def mknod(name, ntype, major=0, minor=0, user=None, group=None, mode='0600'):
Expand Down