diff options
author | antialias <antialias@leap.se> | 2013-01-24 11:38:18 -0500 |
---|---|---|
committer | antialias <antialias@leap.se> | 2013-01-24 11:38:18 -0500 |
commit | cbdd369c00fda7e8d04dc2c422cbab9d5ad59c7d (patch) | |
tree | 9a18fefee8c22ea4341a7ff4b8b6d73f517820e4 /src/leap/soledad/backends/sqlcipher.py | |
parent | 66c40125df7c39d0a83cfa2fc2873de6bfbc7496 (diff) | |
parent | 1a9eb8218722ae64643c8e77f381c5609a89e18f (diff) |
Merge branch 'develop' of ssh://leap.se/leap_client into develop
Diffstat (limited to 'src/leap/soledad/backends/sqlcipher.py')
-rw-r--r-- | src/leap/soledad/backends/sqlcipher.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/leap/soledad/backends/sqlcipher.py b/src/leap/soledad/backends/sqlcipher.py index 08b4df43..6cebcf7d 100644 --- a/src/leap/soledad/backends/sqlcipher.py +++ b/src/leap/soledad/backends/sqlcipher.py @@ -25,10 +25,11 @@ from u1db.backends.sqlite_backend import ( SQLitePartialExpandDatabase, ) from u1db import ( - Document, errors, ) +from leap.soledad.backends.leap_backend import LeapDocument + def open(path, password, create=True, document_factory=None): """Open a database at the given location. @@ -70,7 +71,7 @@ class SQLCipherDatabase(SQLitePartialExpandDatabase): SQLCipherDatabase.set_pragma_key(self._db_handle, password) self._real_replica_uid = None self._ensure_schema() - self._factory = document_factory or Document + self._factory = document_factory or LeapDocument def _check_if_db_is_encrypted(self, sqlite_file): if not os.path.exists(sqlite_file): @@ -133,5 +134,26 @@ class SQLCipherDatabase(SQLitePartialExpandDatabase): return Synchronizer(self, LeapSyncTarget(url, creds=creds), soledad=self._soledad).sync(autocreate=autocreate) + def _extra_schema_init(self, c): + c.execute( + 'ALTER TABLE document ' + 'ADD COLUMN syncable BOOL NOT NULL DEFAULT TRUE') + + def _put_and_update_indexes(self, old_doc, doc): + super(SQLCipherDatabase, self)._put_and_update_indexes(old_doc, doc) + c = self._db_handle.cursor() + c.execute('UPDATE document SET syncable=? WHERE doc_id=?', + (doc.syncable, doc.doc_id)) + + def _get_doc(self, doc_id, check_for_conflicts=False): + doc = super(SQLCipherDatabase, self)._get_doc(doc_id, + check_for_conflicts) + if doc: + c = self._db_handle.cursor() + c.execute('SELECT syncable FROM document WHERE doc_id=?', + (doc.doc_id,)) + doc.syncable = bool(c.fetchone()[0]) + return doc + SQLiteDatabase.register_implementation(SQLCipherDatabase) |