From 8a4cc56266d234b9a8cd2ef3ec999fb00374e480 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Tue, 22 Apr 2014 11:04:02 +0200 Subject: [PATCH] ensure all files we create end with a single newline Signed-off-by: Steven Armstrong --- cdist/util/fsproperty.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cdist/util/fsproperty.py b/cdist/util/fsproperty.py index 49d4a32d..98de09f8 100644 --- a/cdist/util/fsproperty.py +++ b/cdist/util/fsproperty.py @@ -143,6 +143,9 @@ class DirectoryDict(collections.MutableMapping): fd.write(str(v) + '\n') else: fd.write(str(value)) + # ensure file ends with a single newline + if value and value[-1] != '\n': + fd.write('\n') except EnvironmentError as e: raise cdist.Error(str(e)) @@ -281,7 +284,7 @@ class FileStringProperty(FileBasedProperty): value = "" try: with open(path, "r") as fd: - value = fd.read() + value = fd.read().rstrip('\n') except EnvironmentError: pass return value @@ -292,6 +295,9 @@ class FileStringProperty(FileBasedProperty): try: with open(path, "w") as fd: fd.write(str(value)) + # ensure file ends with a single newline + if value[-1] != '\n': + fd.write('\n') except EnvironmentError as e: raise cdist.Error(str(e)) else: