Don't modify file if contents hasn't changed.

This commit is contained in:
Tim 'mithro' Ansell 2016-12-15 19:14:12 +01:00
parent 9d716def9d
commit 8179a9ea2e
1 changed files with 3 additions and 0 deletions

View File

@ -23,6 +23,9 @@ def write_to_file(filename, contents, force_unix=False):
newline = None newline = None
if force_unix: if force_unix:
newline = "\n" newline = "\n"
if os.path.exists(filename):
if open(filename, "r", newline=newline).read() == contents:
return
with open(filename, "w", newline=newline) as f: with open(filename, "w", newline=newline) as f:
f.write(contents) f.write(contents)