summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-11-09 02:41:28 -0300
committerVictor Shyba <victor1984@riseup.net>2017-11-10 23:06:18 -0300
commit69090db9acfa7eb33cd431a45c6c28068a20ec66 (patch)
tree817106f27b5ed666dd7d8eb6b55291f6e14e0289
parente9990fb314857d818796d8493c7eb4df052431cd (diff)
[bug] mark deletion as pending_delete if offline
This commit creates a PENDING_DELETE sync status which can be used to keep track of whats deleted locally in order to propagate to server later. -- Related: #8961
-rw-r--r--src/leap/soledad/client/_db/blobs/__init__.py5
-rw-r--r--src/leap/soledad/client/_db/blobs/sql.py1
-rw-r--r--tests/blobs/test_blob_manager.py28
3 files changed, 34 insertions, 0 deletions
diff --git a/src/leap/soledad/client/_db/blobs/__init__.py b/src/leap/soledad/client/_db/blobs/__init__.py
index 2df315dc..45fae024 100644
--- a/src/leap/soledad/client/_db/blobs/__init__.py
+++ b/src/leap/soledad/client/_db/blobs/__init__.py
@@ -405,10 +405,15 @@ class BlobManager(BlobsSynchronizer):
@defer.inlineCallbacks
def _delete(self, blob_id, namespace):
+ logger.info("Marking blobs as PENDING_DELETE: %s" % blob_id)
+ yield self.local.update_sync_status(
+ blob_id, SyncStatus.PENDING_DELETE, namespace=namespace)
logger.info("Staring deletion of blob: %s" % blob_id)
yield self._delete_from_remote(blob_id, namespace=namespace)
if (yield self.local.exists(blob_id, namespace=namespace)):
yield self.local.delete(blob_id, namespace=namespace)
+ yield self.local.update_sync_status(
+ blob_id, SyncStatus.SYNCED, namespace=namespace)
@defer.inlineCallbacks
def _delete_from_remote(self, blob_id, namespace=''):
diff --git a/src/leap/soledad/client/_db/blobs/sql.py b/src/leap/soledad/client/_db/blobs/sql.py
index 8d8ae158..c9a025a2 100644
--- a/src/leap/soledad/client/_db/blobs/sql.py
+++ b/src/leap/soledad/client/_db/blobs/sql.py
@@ -41,6 +41,7 @@ class SyncStatus:
PENDING_DOWNLOAD = 3
FAILED_UPLOAD = 4
FAILED_DOWNLOAD = 5
+ PENDING_DELETE = 6
UNAVAILABLE_STATUSES = (3, 5)
diff --git a/tests/blobs/test_blob_manager.py b/tests/blobs/test_blob_manager.py
index d36b3cda..58f99790 100644
--- a/tests/blobs/test_blob_manager.py
+++ b/tests/blobs/test_blob_manager.py
@@ -171,6 +171,34 @@ class BlobManagerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
+ def test_offline_delete_marks_as_pending_download(self):
+ deletion_failure = defer.fail(Exception())
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ self.manager._delete_from_remote = Mock(return_value=deletion_failure)
+ content, blob_id = "Blob content", uuid4().hex
+ doc1 = BlobDoc(BytesIO(content), blob_id)
+ yield self.manager.put(doc1, len(content))
+ with pytest.raises(Exception):
+ yield self.manager.delete(blob_id)
+ sync_progress = yield self.manager.sync_progress
+ expected = {'PENDING_DELETE': 1}
+ self.assertEquals(expected, sync_progress)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_online_delete_marks_as_synced(self):
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ self.manager._delete_from_remote = Mock(return_value=None)
+ content, blob_id = "Blob content", uuid4().hex
+ doc1 = BlobDoc(BytesIO(content), blob_id)
+ yield self.manager.put(doc1, len(content))
+ yield self.manager.delete(blob_id)
+ sync_progress = yield self.manager.sync_progress
+ expected = {'SYNCED': 1}
+ self.assertEquals(expected, sync_progress)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
def test_local_sync_status_pending_upload(self):
upload_failure = defer.fail(Exception())
self.manager._encrypt_and_upload = Mock(return_value=upload_failure)