From ba70bf7e3f8f83fea1f1b780525002dd7c735003 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 10 Mar 2013 01:53:24 +0200 Subject: [PATCH] Do not touch conf files if the new one would be identical to the old one. --- backends.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backends.py b/backends.py index 0aec6e2ea..9ac6fbfae 100755 --- a/backends.py +++ b/backends.py @@ -53,7 +53,16 @@ def do_conf_file(src, dst, variables): line = line.replace('@' + varname + '@', var) match = re.search(regex, line) result.append(line) - open(dst, 'w').writelines(result) + dst_tmp = dst + '~' + open(dst_tmp, 'w').writelines(result) + # If contents are identical, don't touch the file to prevent + # unnecessary rebuilds. + try: + if open(dst, 'r').read() == open(dst_tmp, 'r').read(): + return + except FileNotFoundError: + pass + os.replace(dst_tmp, dst) class Backend():