mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
test mode for file.line, fix #27906
This commit is contained in:
parent
62c9514108
commit
8b595b85c8
@ -1609,7 +1609,7 @@ def line(path, content, match=None, mode=None, location=None,
|
||||
|
||||
changed = body_before != hashlib.sha256(salt.utils.to_bytes(body)).hexdigest()
|
||||
|
||||
if backup and changed:
|
||||
if backup and changed and __opts__['test'] is False:
|
||||
try:
|
||||
temp_file = _mkstemp_copy(path=path, preserve_inode=True)
|
||||
shutil.move(temp_file, '{0}.{1}'.format(path, time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())))
|
||||
@ -1621,6 +1621,7 @@ def line(path, content, match=None, mode=None, location=None,
|
||||
if changed:
|
||||
if show_changes:
|
||||
changes_diff = ''.join(difflib.unified_diff(salt.utils.fopen(path, 'r').readlines(), body.splitlines()))
|
||||
if __opts__['test'] is False:
|
||||
fh_ = None
|
||||
try:
|
||||
fh_ = salt.utils.atomicfile.atomic_open(path, 'w')
|
||||
|
Loading…
Reference in New Issue
Block a user