mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Use new get_diff helper in file module
This commit is contained in:
parent
c632265802
commit
612ffb5fe8
1 changed files with 7 additions and 16 deletions
|
@ -1567,7 +1567,7 @@ def comment_line(path,
|
|||
check_perms(path, None, pre_user, pre_group, pre_mode)
|
||||
|
||||
# Return a diff using the two dictionaries
|
||||
return ''.join(difflib.unified_diff(orig_file, new_file))
|
||||
return __salt__['stringutils.get_diff'](orig_file, new_file)
|
||||
|
||||
|
||||
def _get_flags(flags):
|
||||
|
@ -2038,9 +2038,7 @@ def line(path, content=None, match=None, mode=None, location=None,
|
|||
if show_changes:
|
||||
with salt.utils.files.fopen(path, 'r') as fp_:
|
||||
path_content = salt.utils.data.decode_list(fp_.read().splitlines(True))
|
||||
changes_diff = ''.join(difflib.unified_diff(
|
||||
path_content, body
|
||||
))
|
||||
changes_diff = __salt__['stringutils.get_diff'](path_content, body)
|
||||
if __opts__['test'] is False:
|
||||
fh_ = None
|
||||
try:
|
||||
|
@ -2426,18 +2424,15 @@ def replace(path,
|
|||
if not dry_run and not salt.utils.platform.is_windows():
|
||||
check_perms(path, None, pre_user, pre_group, pre_mode)
|
||||
|
||||
def get_changes():
|
||||
orig_file_as_str = [salt.utils.stringutils.to_unicode(x) for x in orig_file]
|
||||
new_file_as_str = [salt.utils.stringutils.to_unicode(x) for x in new_file]
|
||||
return ''.join(difflib.unified_diff(orig_file_as_str, new_file_as_str))
|
||||
differences = __utils__['stringutils.get_diff'](orig_file, new_file)
|
||||
|
||||
if show_changes:
|
||||
return get_changes()
|
||||
return differences
|
||||
|
||||
# We may have found a regex line match but don't need to change the line
|
||||
# (for situations where the pattern also matches the repl). Revert the
|
||||
# has_changes flag to False if the final result is unchanged.
|
||||
if not get_changes():
|
||||
if not differences:
|
||||
has_changes = False
|
||||
|
||||
return has_changes
|
||||
|
@ -2688,7 +2683,7 @@ def blockreplace(path,
|
|||
)
|
||||
|
||||
if block_found:
|
||||
diff = ''.join(difflib.unified_diff(orig_file, new_file))
|
||||
diff = __salt__['stringutils.get_diff'](orig_file, new_file)
|
||||
has_changes = diff is not ''
|
||||
if has_changes and not dry_run:
|
||||
# changes detected
|
||||
|
@ -5018,11 +5013,7 @@ def get_diff(file1,
|
|||
else:
|
||||
if show_filenames:
|
||||
args.extend(files)
|
||||
ret = ''.join(
|
||||
difflib.unified_diff(
|
||||
*salt.utils.data.decode(args)
|
||||
)
|
||||
)
|
||||
ret = __utils__['stringutils.get_diff'](*args)
|
||||
return ret
|
||||
return ''
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue