Fix write_file_if_changed() if target file does not exist

develop
lethosor 2022-07-27 01:04:47 -04:00
parent 6293b71e9e
commit 671f10e5d8
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
1 changed files with 5 additions and 2 deletions

@ -135,8 +135,11 @@ def write_file_if_changed(path):
yield buffer yield buffer
new_contents = buffer.getvalue() new_contents = buffer.getvalue()
with open(path, 'r') as infile: try:
old_contents = infile.read() with open(path, 'r') as infile:
old_contents = infile.read()
except IOError:
old_contents = None
if old_contents != new_contents: if old_contents != new_contents:
with open(path, 'w') as outfile: with open(path, 'w') as outfile: