diff options
author | Kali Kaneko <kali@leap.se> | 2015-05-25 16:17:20 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-05-25 16:17:20 -0400 |
commit | 745ac11c78455e7487bef88da3c3ffeb4fe4351c (patch) | |
tree | cc14a46120a69921ba9eed6e5584012c23fc694f /client/src/leap/soledad/client/pragmas.py | |
parent | 340b0dcfbc0a819738a28f9c803fdbf848754897 (diff) | |
parent | 3e6e51649bb6206125f20ac6773f6744ec8bf175 (diff) |
Merge remote-tracking branch 'leapcode/pr/216' into develop
this branch includes many changes that improve the asynchronous
retrieval of the sync docs, and the parallel decryption of the encrypted
documents.
Diffstat (limited to 'client/src/leap/soledad/client/pragmas.py')
-rw-r--r-- | client/src/leap/soledad/client/pragmas.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/pragmas.py b/client/src/leap/soledad/client/pragmas.py index 2e9c53a3..55397d10 100644 --- a/client/src/leap/soledad/client/pragmas.py +++ b/client/src/leap/soledad/client/pragmas.py @@ -19,10 +19,53 @@ Different pragmas used in the initialization of the SQLCipher database. """ import logging import string +import threading +import os + +from leap.soledad.common import soledad_assert + logger = logging.getLogger(__name__) +_db_init_lock = threading.Lock() + + +def set_init_pragmas(conn, opts=None, extra_queries=None): + """ + Set the initialization pragmas. + + This includes the crypto pragmas, and any other options that must + be passed early to sqlcipher db. + """ + soledad_assert(opts is not None) + extra_queries = [] if extra_queries is None else extra_queries + with _db_init_lock: + # only one execution path should initialize the db + _set_init_pragmas(conn, opts, extra_queries) + + +def _set_init_pragmas(conn, opts, extra_queries): + + sync_off = os.environ.get('LEAP_SQLITE_NOSYNC') + memstore = os.environ.get('LEAP_SQLITE_MEMSTORE') + nowal = os.environ.get('LEAP_SQLITE_NOWAL') + + set_crypto_pragmas(conn, opts) + + if not nowal: + set_write_ahead_logging(conn) + if sync_off: + set_synchronous_off(conn) + else: + set_synchronous_normal(conn) + if memstore: + set_mem_temp_store(conn) + + for query in extra_queries: + conn.cursor().execute(query) + + def set_crypto_pragmas(db_handle, sqlcipher_opts): """ Set cryptographic params (key, cipher, KDF number of iterations and |