From f5fb6b83ff6ae61fc0b77eab1d29c98a01f2b7a7 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Wed, 15 Feb 2017 12:43:05 +0100 Subject: [PATCH] Rev1905, Secure DB write db_mode option --- src/Config.py | 3 ++- src/Db/Db.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Config.py b/src/Config.py index a9c07efe..5d148069 100644 --- a/src/Config.py +++ b/src/Config.py @@ -10,7 +10,7 @@ class Config(object): def __init__(self, argv): self.version = "0.5.2" - self.rev = 1899 + self.rev = 1905 self.argv = argv self.action = None self.config_file = "zeronet.conf" @@ -206,6 +206,7 @@ class Config(object): type='bool', choices=[True, False], default=True) self.parser.add_argument("--fix_float_decimals", help='Fix content.json modification date float precision on verification', type='bool', choices=[True, False], default=fix_float_decimals) + self.parser.add_argument("--db_mode", choices=["speed", "security"], default="speed") self.parser.add_argument('--coffeescript_compiler', help='Coffeescript compiler for developing', default=coffeescript, metavar='executable_path') diff --git a/src/Db/Db.py b/src/Db/Db.py index 9e97e1e4..de711a21 100644 --- a/src/Db/Db.py +++ b/src/Db/Db.py @@ -59,9 +59,12 @@ class Db(object): self.conn.row_factory = sqlite3.Row self.conn.isolation_level = None self.cur = self.getCursor() - # We need more speed then security - self.cur.execute("PRAGMA journal_mode = MEMORY") - self.cur.execute("PRAGMA synchronous = OFF") + if config.db_mode == "security": + self.cur.execute("PRAGMA journal_mode = WAL") + self.cur.execute("PRAGMA synchronous = NORMAL") + else: + self.cur.execute("PRAGMA journal_mode = MEMORY") + self.cur.execute("PRAGMA synchronous = OFF") if self.foreign_keys: self.execute("PRAGMA foreign_keys = ON") self.log.debug(