From 0ddc1e47ba0bd1eb7c1749ab4c6d4862d467dc61 Mon Sep 17 00:00:00 2001 From: ZeroNet Date: Wed, 10 Aug 2016 12:49:22 +0200 Subject: [PATCH] Delete file's database entries if file paramter is False --- src/Db/Db.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Db/Db.py b/src/Db/Db.py index e5fe18bc..607bf26b 100644 --- a/src/Db/Db.py +++ b/src/Db/Db.py @@ -200,9 +200,17 @@ class Db(object): return False # Load the json file - if not file: - file = open(file_path) - data = json.load(file) + try: + if file is None: # Open file is not file object passed + file = open(file_path) + + if file is False: # File deleted + data = {} + else: + data = json.load(file) + except Exception, err: + self.log.debug("Json file %s load error: %s" % (file_path, err)) + data = {} # No cursor specificed if not cur: @@ -301,6 +309,11 @@ class Db(object): row["json_id"] = json_row["json_id"] 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: cur.execute("COMMIT") return True