diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-09-25 14:11:30 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-10-05 05:41:40 -0300 |
commit | 0e2dca49d70082f51c43cd6873f36fee6a9b62ad (patch) | |
tree | 5348bf8dbd690cd81dd283a1c3908dc51e4f6bcd /src | |
parent | 5d797ddbfe226a2fb6ebff5b4f4184bb41b1b34d (diff) |
[feature] blob get/put handle unavailable statuses
PENDING_DOWNLOAD is an empty blob, so during blob_manager.get we need to
return empty as it's not available. This status is used during sync.
During put, if we have an empty unavailable blob, then we delete and
replace with is being put, marking it as SYNCED.
-- Related: #8822
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/soledad/client/_db/blobs.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py index e23b1cf9..75f196c7 100644 --- a/src/leap/soledad/client/_db/blobs.py +++ b/src/leap/soledad/client/_db/blobs.py @@ -552,6 +552,11 @@ class SQLiteBlobBackend(object): @defer.inlineCallbacks def put(self, blob_id, blob_fd, size=None, namespace='', status=SyncStatus.PENDING_UPLOAD): + previous_state = yield self.get_sync_status(blob_id) + unavailable = SyncStatus.UNAVAILABLE_STATUSES + if previous_state and previous_state[0] in unavailable: + yield self.delete(blob_id, namespace) + status = SyncStatus.SYNCED logger.info("Saving blob in local database...") insert = 'INSERT INTO blobs (blob_id, namespace, payload, sync_status)' insert += ' VALUES (?, ?, zeroblob(?), ?)' @@ -565,7 +570,12 @@ class SQLiteBlobBackend(object): # TODO we can also stream the blob value using sqlite # incremental interface for blobs - and just return the raw fd instead select = 'SELECT payload FROM blobs WHERE blob_id = ? AND namespace= ?' - result = yield self.dbpool.runQuery(select, (blob_id, namespace,)) + values = (blob_id, namespace,) + avoid_values = SyncStatus.UNAVAILABLE_STATUSES + select += ' AND sync_status NOT IN (%s)' + select %= ','.join(['?' for _ in avoid_values]) + values += avoid_values + result = yield self.dbpool.runQuery(select, values) if result: defer.returnValue(BytesIO(str(result[0][0]))) |