From 95cbab7ef4ca0ce8a75a595cf6aeff765999c182 Mon Sep 17 00:00:00 2001 From: Joe Eacott Date: Thu, 29 Aug 2019 11:31:59 -0600 Subject: [PATCH] Whoops missed this file entirely --- salt/states/file.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/salt/states/file.py b/salt/states/file.py index 6964e40443d1..08f0b465440c 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -2712,9 +2712,18 @@ def managed(name, contents = '' for part in validated_contents: for line in part.splitlines(): - contents += line.rstrip('\n').rstrip('\r') + os.linesep - if contents_newline and not contents.endswith(os.linesep): - contents += os.linesep + if not (line == validated_contents[-1]): + # So long as we havent reached the end strip out the + # newline and carriage return and add a platform + # specific line ending with os.linesep + contents += line.rstrip('\n').rstrip('\r') + os.linesep + else: + # Were at the last line decide if a newline needs to + # go in or not + contents += line.rstrip('\n').rstrip('\r') + if contents_newline: + contents += os.linesep + except UnicodeDecodeError: # Either something terrible happened, or we have binary data. if template: