mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-02-16 10:29:39 +01:00
Verify a newly written config file before setting that as the actual config file. Helps prevent a corrupted write from overwriting the config file
This commit is contained in:
parent
8618708fd1
commit
5a643c383b
@ -160,10 +160,17 @@ def setConfig(config):
|
||||
yaml.indent(mapping=2, sequence=4, offset=2)
|
||||
|
||||
try:
|
||||
f = open(config_yaml_path, "w", encoding="utf-8")
|
||||
f = open(config_yaml_path + ".tmp", "w", encoding="utf-8")
|
||||
yaml.dump(config, f)
|
||||
finally:
|
||||
f.close() # do this explicitly to avoid NUL bytes (rare bug when using 'with')
|
||||
f.close() # do this explicitly to avoid NUL bytes (possible rare bug when using 'with')
|
||||
|
||||
# verify that the new file is valid, and only then overwrite the old config file
|
||||
# helps prevent the rare NUL bytes error from corrupting the config file
|
||||
yaml = YAML()
|
||||
with open(config_yaml_path + ".tmp", "r", encoding="utf-8") as f:
|
||||
yaml.load(f)
|
||||
shutil.move(config_yaml_path + ".tmp", config_yaml_path)
|
||||
except:
|
||||
log.error(traceback.format_exc())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user