Delete file's database entries if file paramter is False

This commit is contained in:
ZeroNet 2016-08-10 12:49:22 +02:00
parent 55cc496c2e
commit 0ddc1e47ba

View file

@ -200,9 +200,17 @@ class Db(object):
return False return False
# Load the json file # Load the json file
if not file: try:
if file is None: # Open file is not file object passed
file = open(file_path) file = open(file_path)
if file is False: # File deleted
data = {}
else:
data = json.load(file) data = json.load(file)
except Exception, err:
self.log.debug("Json file %s load error: %s" % (file_path, err))
data = {}
# No cursor specificed # No cursor specificed
if not cur: if not cur:
@ -301,6 +309,11 @@ class Db(object):
row["json_id"] = json_row["json_id"] row["json_id"] = json_row["json_id"]
cur.execute("INSERT OR REPLACE INTO %s ?" % table_name, row) cur.execute("INSERT OR REPLACE INTO %s ?" % table_name, row)
# Cleanup json row
if not data:
self.log.debug("Cleanup json row for %s" % file_path)
cur.execute("DELETE FROM json WHERE json_id = %s" % json_row["json_id"])
if commit_after_done: if commit_after_done:
cur.execute("COMMIT") cur.execute("COMMIT")
return True return True