mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #31647 from alprs/feature-file_comment_no_backup
Add option to not save a backup with file.comment/uncomment
This commit is contained in:
commit
af5e5e580c
@ -1062,6 +1062,7 @@ def comment_line(path,
|
||||
|
||||
:param backup: string
|
||||
The file extension to give the backup file. Default is ``.bak``
|
||||
Set to False/None to not keep a backup.
|
||||
|
||||
:return: boolean
|
||||
Returns True if successful, False if not
|
||||
@ -1191,6 +1192,7 @@ def comment_line(path,
|
||||
except (OSError, IOError) as exc:
|
||||
raise CommandExecutionError("Exception: {0}".format(exc))
|
||||
|
||||
if backup:
|
||||
# Move the backup file to the original directory
|
||||
backup_name = '{0}{1}'.format(path, backup)
|
||||
try:
|
||||
@ -1201,6 +1203,8 @@ def comment_line(path,
|
||||
"backup file '{1}'. "
|
||||
"Exception: {2}".format(path, temp_file, exc)
|
||||
)
|
||||
else:
|
||||
os.remove(temp_file)
|
||||
|
||||
if not salt.utils.is_windows():
|
||||
check_perms(path, None, pre_user, pre_group, pre_mode)
|
||||
|
@ -3150,6 +3150,8 @@ def comment(name, regex, char='#', backup='.bak'):
|
||||
``uncomment`` is called. Meaning the backup will only be useful
|
||||
after the first invocation.
|
||||
|
||||
Set to False/None to not keep a backup.
|
||||
|
||||
Usage:
|
||||
|
||||
.. code-block:: yaml
|
||||
@ -3243,6 +3245,8 @@ def uncomment(name, regex, char='#', backup='.bak'):
|
||||
``uncomment`` is called. Meaning the backup will only be useful
|
||||
after the first invocation.
|
||||
|
||||
Set to False/None to not keep a backup.
|
||||
|
||||
Usage:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
Loading…
Reference in New Issue
Block a user