From 492c3f711927e09acd044db9aa76ce7a05c946c7 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 5 Dec 2012 16:48:56 -0200 Subject: OpenStack backend can delete docs. --- src/leap/soledad/openstack.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src') 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. -- cgit v1.2.3