Try closing the config file explicitly, to avoid null byte errors

This commit is contained in:
cmdr2 2023-06-30 12:39:36 +05:30
parent 45f99ab48a
commit 8618708fd1

View File

@ -158,8 +158,12 @@ def setConfig(config):
config = commented_config config = commented_config
yaml.indent(mapping=2, sequence=4, offset=2) yaml.indent(mapping=2, sequence=4, offset=2)
with open(config_yaml_path, "w", encoding="utf-8") as f:
try:
f = open(config_yaml_path, "w", encoding="utf-8")
yaml.dump(config, f) yaml.dump(config, f)
finally:
f.close() # do this explicitly to avoid NUL bytes (rare bug when using 'with')
except: except:
log.error(traceback.format_exc()) log.error(traceback.format_exc())