From e90a424575b04c99696805adbd2cd01a0f4c7e46 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 22 Mar 2017 00:02:51 -0300 Subject: [bug] copy returns a closed handle copy call returns a closed file handler, instead we can query for the blob after insertion and use the returned file handle to be consumed for upload. A better solution would be to "pipe" the writes into the database into the upload, but that involves solving a larger set of issues to be done later. --- client/src/leap/soledad/client/_blobs.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'client/src/leap/soledad') diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py index 2c613a80..92aa42cf 100644 --- a/client/src/leap/soledad/client/_blobs.py +++ b/client/src/leap/soledad/client/_blobs.py @@ -18,7 +18,6 @@ Clientside BlobBackend Storage. """ -from copy import copy from urlparse import urljoin import os @@ -169,8 +168,10 @@ class BlobManager(object): 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. - yield self.local.put(doc.blob_id, fd) - fd.seek(0) + yield self.local.put(doc.blob_id, fd, size=size) + # In fact, some kind of pipe is needed here, where each write on db + # handle gets forwarded into a write on the connection handle + fd = yield self.local.get(doc.blob_id) yield self._encrypt_and_upload(doc.blob_id, doc.doc_id, doc.rev, fd) @defer.inlineCallbacks @@ -274,7 +275,7 @@ class SQLiteBlobBackend(object): # FIXME should remove this duplication! # have a look at how treq does cope with closing the handle # for uploading a file - producer = FileBodyProducer(copy(blob_fd)) + producer = FileBodyProducer(blob_fd) done = yield producer.startProducing(handle) logger.info("Finished saving blob in local database.") defer.returnValue(done) -- cgit v1.2.3