Only write file if contents will change.

This commit is contained in:
Tim 'mithro' Ansell 2018-11-28 20:18:31 -08:00
parent a2938a7ae7
commit 3ff6a18a45

View file

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