diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-06-03 20:50:27 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-06-03 20:50:27 -0300 |
commit | fbbb1f1cb315a0d4ada2db5b9455582327b75038 (patch) | |
tree | e77b2df3c7e3a1cf33d9369aa22fe661d1c2681c /src/leap/soledad/backends/couch.py | |
parent | 35de9dc370631a8519a707a74d188210cbc30e8d (diff) | |
parent | 917a00257b9a8b6f40457dba75463b886cb143db (diff) |
Merge remote-tracking branch 'drebs/feature/2359-avoid-encoding-problems-when-storing-u1db-data' into develop
Diffstat (limited to 'src/leap/soledad/backends/couch.py')
-rw-r--r-- | src/leap/soledad/backends/couch.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/leap/soledad/backends/couch.py b/src/leap/soledad/backends/couch.py index 0b9bff01..57885012 100644 --- a/src/leap/soledad/backends/couch.py +++ b/src/leap/soledad/backends/couch.py @@ -312,11 +312,13 @@ class CouchDatabase(ObjectStoreDatabase): # TODO: prevent user from overwriting a document with the same doc_id # as this one. doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) - doc.content = {self.U1DB_TRANSACTION_LOG_KEY: [], - self.U1DB_CONFLICTS_KEY: b64encode(json.dumps({})), - self.U1DB_OTHER_GENERATIONS_KEY: {}, - self.U1DB_INDEXES_KEY: b64encode(json.dumps({})), - self.U1DB_REPLICA_UID_KEY: self._replica_uid} + doc.content = { + self.U1DB_TRANSACTION_LOG_KEY: b64encode(json.dumps([])), + self.U1DB_CONFLICTS_KEY: b64encode(json.dumps({})), + self.U1DB_OTHER_GENERATIONS_KEY: b64encode(json.dumps({})), + self.U1DB_INDEXES_KEY: b64encode(json.dumps({})), + self.U1DB_REPLICA_UID_KEY: b64encode(self._replica_uid), + } self._put_doc(doc) def _fetch_u1db_data(self): @@ -331,13 +333,15 @@ class CouchDatabase(ObjectStoreDatabase): cdoc, self.COUCH_U1DB_ATTACHMENT_KEY).read() content = json.loads(jsonstr) # set u1db database info - self._transaction_log = content[self.U1DB_TRANSACTION_LOG_KEY] + self._transaction_log = json.loads( + b64decode(content[self.U1DB_TRANSACTION_LOG_KEY])) self._conflicts = json.loads( b64decode(content[self.U1DB_CONFLICTS_KEY])) - self._other_generations = content[self.U1DB_OTHER_GENERATIONS_KEY] + self._other_generations = json.loads( + b64decode(content[self.U1DB_OTHER_GENERATIONS_KEY])) self._indexes = self._load_indexes_from_json( b64decode(content[self.U1DB_INDEXES_KEY])) - self._replica_uid = content[self.U1DB_REPLICA_UID_KEY] + self._replica_uid = b64decode(content[self.U1DB_REPLICA_UID_KEY]) # save couch _rev self._couch_rev = cdoc[self.COUCH_REV_KEY] @@ -349,14 +353,16 @@ class CouchDatabase(ObjectStoreDatabase): """ doc = self._factory(doc_id=self.U1DB_DATA_DOC_ID) doc.content = { - self.U1DB_TRANSACTION_LOG_KEY: self._transaction_log, # Here, the b64 encode ensures that document content # does not cause strange behaviour in couchdb because # of encoding. + self.U1DB_TRANSACTION_LOG_KEY: + b64encode(json.dumps(self._transaction_log)), self.U1DB_CONFLICTS_KEY: b64encode(json.dumps(self._conflicts)), - self.U1DB_OTHER_GENERATIONS_KEY: self._other_generations, + self.U1DB_OTHER_GENERATIONS_KEY: + b64encode(json.dumps(self._other_generations)), self.U1DB_INDEXES_KEY: b64encode(self._dump_indexes_as_json()), - self.U1DB_REPLICA_UID_KEY: self._replica_uid, + self.U1DB_REPLICA_UID_KEY: b64encode(self._replica_uid), self.COUCH_REV_KEY: self._couch_rev} self._put_doc(doc) |