diff options
Diffstat (limited to 'src/leap/soledad/client/_db/blobs.py')
-rw-r--r-- | src/leap/soledad/client/_db/blobs.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index cfabda74..1447e3bb 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -73,6 +73,20 @@ class SyncStatus: class ConnectionPool(adbapi.ConnectionPool): + def blocking_create_schema(self, create_schema_function): + """ + Grabs a connection and executes schema creation from current thread, + disconnecting right after it. This ensures that schema creation blocks + everything and doesn't run concurrently. + + :param create_schema_function: A function that receives a connection + and executes schema criation and/or migrations. + :type create_schema_function: function + """ + conn = self.connect() + create_schema_function(conn) + self.disconnect(conn) + def insertAndGetLastRowid(self, *args, **kwargs): """ Execute an SQL query and return the last rowid. @@ -439,8 +453,8 @@ class SQLiteBlobBackend(object): opts = sqlcipher.SQLCipherOptions( '/tmp/ignored', binascii.b2a_hex(key), is_raw_key=True, create=True) - pragmafun = partial(pragmas.set_init_pragmas, opts=opts) - openfun = _sqlcipherInitFactory(pragmafun) + openfun = partial(pragmas.set_init_pragmas, opts=opts, + schema_func=_init_blob_table) self.dbpool = ConnectionPool( backend, self.path, check_same_thread=False, timeout=5, @@ -553,13 +567,6 @@ def _init_blob_table(conn): conn.execute('ALTER TABLE blobs ADD COLUMN retries INT default 0') -def _sqlcipherInitFactory(fun): - def _initialize(conn): - fun(conn) - _init_blob_table(conn) - return _initialize - - # # testing facilities # |