summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-05-01 03:28:09 -0300
committerVictor Shyba <victor1984@riseup.net>2017-05-01 03:31:14 -0300
commit967c91c5bb7ecca3575c6ef7d0fb4461de4dafc7 (patch)
tree9992c4e7bcb1e7c383a26404b6ebf5fcfbbd95d8 /client
parent336211e2526c71c34a82c4ec48ef32f8bb82fd1f (diff)
[bug] fail locally if blob exists
We can't let the local DB try an isertion before making sure doc isn't already there. - Resolves: #8845
Diffstat (limited to 'client')
-rw-r--r--client/src/leap/soledad/client/_blobs.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py
index 6f692f6b..1475b302 100644
--- a/client/src/leap/soledad/client/_blobs.py
+++ b/client/src/leap/soledad/client/_blobs.py
@@ -194,6 +194,9 @@ class BlobManager(object):
@defer.inlineCallbacks
def put(self, doc, size):
+ if (yield self.local.exists(doc.blob_id)):
+ error_message = "Blob already exists: %s" % doc.blob_id
+ raise BlobAlreadyExistsError(error_message)
fd = doc.blob_fd
# TODO this is a tee really, but ok... could do db and upload
# concurrently. not sure if we'd gain something.
@@ -326,6 +329,12 @@ class SQLiteBlobBackend(object):
else:
defer.returnValue([])
+ @defer.inlineCallbacks
+ def exists(self, blob_id):
+ query = 'SELECT blob_id from blobs WHERE blob_id = ?'
+ result = yield self.dbpool.runQuery(query, (blob_id,))
+ defer.returnValue(bool(len(result)))
+
def _init_blob_table(conn):
maybe_create = (