diff options
author | kali <kali@leap.se> | 2013-01-25 01:55:04 +0900 |
---|---|---|
committer | kali <kali@leap.se> | 2013-01-25 01:55:04 +0900 |
commit | b9cba4bc7b88420e0ee46a6f03dd4aa2fb1edd1e (patch) | |
tree | 136fcde8955f00ac42ca2054a3108bd4bc0de064 /src/leap/soledad/backends/sqlcipher.py | |
parent | b093b632049e1cf4c61d714c025831fb8d373ed7 (diff) | |
parent | d02402a147bbae945618befdb8a1a260a91ce7a6 (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) |