Better file exception handling on saving index JSON

ticket-242-reliability-dict
dgtlmoon 3 years ago
parent a51c555964
commit fda93c3798

@ -398,13 +398,10 @@ class ChangeDetectionStore:
# system was out of memory, out of RAM etc # system was out of memory, out of RAM etc
with open(self.json_store_path+".tmp", 'w') as json_file: with open(self.json_store_path+".tmp", 'w') as json_file:
json.dump(data, json_file, indent=4) json.dump(data, json_file, indent=4)
os.rename(self.json_store_path+".tmp", self.json_store_path)
except Exception as e: except Exception as e:
logging.error("Error writing JSON!! (Main JSON file save was skipped) : %s", str(e)) logging.error("Error writing JSON!! (Main JSON file save was skipped) : %s", str(e))
else:
os.rename(self.json_store_path+".tmp", self.json_store_path)
self.needs_write = False self.needs_write = False
# Thread runner, this helps with thread/write issues when there are many operations that want to update the JSON # Thread runner, this helps with thread/write issues when there are many operations that want to update the JSON

Loading…
Cancel
Save