From 8afb79c4d2171b03270143639296cbb6d9d0fdfa Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 23 Jul 2014 10:29:39 -0300 Subject: Allow deferred decryption without deferred encryption. --- client/src/leap/soledad/client/sqlcipher.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'client/src') diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py index 2df9606e..5a30b125 100644 --- a/client/src/leap/soledad/client/sqlcipher.py +++ b/client/src/leap/soledad/client/sqlcipher.py @@ -243,19 +243,14 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase): self._ensure_schema() self._crypto = crypto + # define sync-db attrs self._sync_db = None self._sync_db_write_lock = None self._sync_enc_pool = None + self._init_sync_db(sqlcipher_file) if self.defer_encryption: - if sqlcipher_file != ":memory:": - self._sync_db_path = "%s-sync" % sqlcipher_file - else: - self._sync_db_path = ":memory:" - # initialize sync db - self._init_sync_db() - # initialize syncing queue encryption pool self._sync_enc_pool = SyncEncrypterPool( self._crypto, self._sync_db, self._sync_db_write_lock) @@ -449,7 +444,6 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase): # the following context manager blocks until the syncing lock can be # acquired. with self.syncer(url, creds=creds) as syncer: - # XXX could mark the critical section here... try: res = syncer.sync(autocreate=autocreate, @@ -542,14 +536,21 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase): 'ALTER TABLE document ' 'ADD COLUMN syncable BOOL NOT NULL DEFAULT TRUE') - def _init_sync_db(self): + def _init_sync_db(self, sqlcipher_file): """ Initialize the Symmetrically-Encrypted document to be synced database, and the queue to communicate with subprocess workers. + + :param sqlcipher_file: The path for the SQLCipher file. + :type sqlcipher_file: str """ - self._sync_db = sqlite3.connect(self._sync_db_path, + sync_db_path = None + if sqlcipher_file != ":memory:": + sync_db_path = "%s-sync" % sqlcipher_file + else: + sync_db_path = ":memory:" + self._sync_db = sqlite3.connect(sync_db_path, check_same_thread=False) - self._sync_db_write_lock = threading.Lock() self._create_sync_db_tables() self.sync_queue = multiprocessing.Queue() -- cgit v1.2.3