diff options
author | drebs <drebs@leap.se> | 2017-02-23 10:46:38 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-04-04 18:27:32 +0200 |
commit | 59d3136226e8f87a906f92e315f00d7705292c89 (patch) | |
tree | dc46db28887fc78d86c98dad2ffd19ca874b7589 /client/src/leap | |
parent | 73b35a9217a2e27d4d2297dff111a93fbbee2252 (diff) |
[bug] handle case when blob is not found in server
Diffstat (limited to 'client/src/leap')
-rw-r--r-- | client/src/leap/soledad/client/_blobs.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py index 3126fc30..3de67569 100644 --- a/client/src/leap/soledad/client/_blobs.py +++ b/client/src/leap/soledad/client/_blobs.py @@ -191,6 +191,12 @@ class BlobManager(object): uri = self.remote + self.user + '/' + blob_id buf = DecrypterBuffer(doc_id, rev, self.secret) data = yield treq.get(uri) + + if data.code == 404: + logger.warn("Blob not found in server: %s" % blob_id) + defer.returnValue(None) + + # incrementally collect the body of the response yield treq.collect(data, buf.write) fd, size = yield buf.close() logger.info("Finished download: (%s, %d)" % (blob_id, size)) @@ -337,13 +343,18 @@ def testit(reactor): @defer.inlineCallbacks def _download(blob_id): - logger.info(":: Starting download only...") + logger.info(":: Starting download only: %s" % blob_id) manager = BlobManager( '/tmp/blobs', 'http://localhost:9000/', 'A' * 32, 'secret', 'user') - payload = yield manager._download_and_decrypt(blob_id, 'mydoc', '1') - defer.returnValue(payload) - logger.info(":: Finished download only.") + result = yield manager._download_and_decrypt(blob_id, 'mydoc', '1') + logger.info(":: Result of download: %s" % str(result)) + if not result: + logger.info(":: Download failed for: %s" % blob_id) + else: + fd, _ = result + logger.info(":: Content of blob %s: %s" % (blob_id, fd.getvalue())) + logger.info(":: Finished download only: %s" % blob_id) def _put(blob_id, payload): pass @@ -361,8 +372,7 @@ def testit(reactor): if args.action == 'upload': yield _upload(args.blob_id, args.payload) elif args.action == 'download': - fd, _ = yield _download(args.blob_id) - logger.info(":: Result of download: " + fd.getvalue()) + yield _download(args.blob_id) elif args.action == 'put': yield _put(args.blob_id, args.payload) elif args.action == 'get': |