prevent file corruption during json.dump

This commit is contained in:
Jakob Ketterl
2021-02-16 17:17:09 +01:00
parent 496e771e17
commit 3c0a26eaa8
3 changed files with 9 additions and 3 deletions

View File

@ -21,5 +21,7 @@ class DynamicConfig(PropertyLayer):
return "{data_directory}/settings.json".format(data_directory=coreConfig.get_data_directory())
def store(self):
# don't write directly to file to avoid corruption on exceptions
jsonContent = json.dumps(self.__dict__(), indent=4)
with open(DynamicConfig._getSettingsFile(), "w") as file:
json.dump(self.__dict__(), file, indent=4)
file.write(jsonContent)