diff options
author | drebs <drebs@leap.se> | 2012-12-05 16:48:56 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2012-12-05 16:48:56 -0200 |
commit | 492c3f711927e09acd044db9aa76ce7a05c946c7 (patch) | |
tree | 479ebef2e4e9a6f847047f08f21e48cad1128388 /src/leap/soledad | |
parent | e60d2f46a5372a0a6d0d468a919eefde40d4807a (diff) |
OpenStack backend can delete docs.
Diffstat (limited to 'src/leap/soledad')
-rw-r--r-- | src/leap/soledad/openstack.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/leap/soledad/openstack.py b/src/leap/soledad/openstack.py index ebb97ac5..e7d62751 100644 --- a/src/leap/soledad/openstack.py +++ b/src/leap/soledad/openstack.py @@ -41,9 +41,12 @@ class OpenStackDatabase(CommonBackend): Conflicts do not happen on server side, so there's no need to check for them. """ - response, contents = self._connection.get_object(self._container, doc_id) - rev = response['x-object-meta-rev'] - return self._factory(doc_id, rev, contents) + try: + response, contents = self._connection.get_object(self._container, doc_id) + rev = response['x-object-meta-rev'] + return self._factory(doc_id, rev, contents) + except: swiftclient.ClientException + return None def get_doc(self, doc_id, include_deleted=False): doc = self._get_doc(doc_id, check_for_conflicts=True) @@ -83,7 +86,20 @@ class OpenStackDatabase(CommonBackend): return new_rev def delete_doc(self, doc): - raise NotImplementedError(self.delete_doc) + old_doc = self._get_doc(doc.doc_id, check_for_conflicts=True) + if old_doc is None: + raise errors.DocumentDoesNotExist + if old_doc.rev != doc.rev: + raise errors.RevisionConflict() + if old_doc.is_tombstone(): + raise errors.DocumentAlreadyDeleted + if old_doc.has_conflicts: + raise errors.ConflictedDoc() + new_rev = self._allocate_doc_rev(doc.rev) + doc.rev = new_rev + doc.make_tombstone() + self._put_doc(olddoc) + return new_rev # start of index-related methods: these are not supported by this backend. |