Skip to content

Commit

Permalink
fixes saltstack#61662 fix file.comment reports changes in test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasmhughes authored and garethgreenaway committed May 23, 2022
1 parent 6394a39 commit d94f759
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6062,10 +6062,11 @@ def comment(name, regex, char="#", backup=".bak", ignore_missing=False):
# remove (?i)-like flags, ^ and $
unanchor_regex = re.sub(r"^(\(\?[iLmsux]\))?\^?(.*?)\$?$", r"\2", regex)

uncomment_regex = "[^{}]".format(char) + unanchor_regex
comment_regex = char + unanchor_regex

# Make sure the pattern appears in the file before continuing
if not __salt__["file.search"](name, regex, multiline=True):
if not __salt__["file.search"](name, uncomment_regex, multiline=True):
if __salt__["file.search"](name, comment_regex, multiline=True):
ret["comment"] = "Pattern already commented"
ret["result"] = True
Expand Down Expand Up @@ -6097,7 +6098,7 @@ def comment(name, regex, char="#", backup=".bak", ignore_missing=False):
nlines = nlines.splitlines(True)

# Check the result
ret["result"] = __salt__["file.search"](name, unanchor_regex, multiline=True)
ret["result"] = __salt__["file.search"](name, comment_regex, multiline=True)

if slines != nlines:
if not __utils__["files.is_text"](name):
Expand Down

0 comments on commit d94f759

Please sign in to comment.