Skip to content

Commit

Permalink
win_lineinfile: fixes the inconsistent of the last emtpy line on diff. (
Browse files Browse the repository at this point in the history
ansible-collections#283)

* Fixes the inconsistent of the last emtpy line on diff.

The last empty line is stripped from the only before data of diff.
While the after data of diff is fixed on ansible-collections#219.

* Added changelog fragment

Co-authored-by: Jordan Borean <jborean93@gmail.com>
  • Loading branch information
teramako and jborean93 authored Aug 23, 2021
1 parent 8761cbe commit e004dd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/win_lineinfile-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- win_lineinfile - Fix up diff output with ending newlines - https://github.com/ansible-collections/community.windows/pull/283
4 changes: 4 additions & 0 deletions plugins/modules/win_lineinfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function Present($path, $regex, $line, $insertafter, $insertbefore, $create, $ba
}

if ($diff_support) {
if ($endswithnewline) {
$before += ""
}
$result.diff = @{
before = $before -join $linesep;
}
Expand Down Expand Up @@ -254,6 +257,7 @@ function Absent($path, $regex, $line, $backup, $validate, $encodingobj, $linesep
$alltext = [System.IO.File]::ReadAllText($cleanpath, $encodingobj);
If (($alltext[-1] -eq "`n") -or ($alltext[-1] -eq "`r")) {
$lines.Add("")
$before += ""
}
}

Expand Down

0 comments on commit e004dd1

Please sign in to comment.