summaryrefslogtreecommitdiff
path: root/src/leap/soledad/server/_blobs.py
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-09-29 18:38:48 -0300
committerdrebs <drebs@riseup.net>2017-09-29 19:20:40 -0300
commit7555e20158df4fa4a724be26eeb5d68ed2ef4508 (patch)
tree603709ec9fd6ecb19f16f71e5080b6001784d4b4 /src/leap/soledad/server/_blobs.py
parent6212a53f6cc7cea01eb514afa696448d125b276f (diff)
[bug] check all http response status codes
Diffstat (limited to 'src/leap/soledad/server/_blobs.py')
-rw-r--r--src/leap/soledad/server/_blobs.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 790a9b51..cacfe38d 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -124,8 +124,11 @@ class FilesystemBlobsBackend(object):
with open(path, 'wb') as blobfile:
yield fbp.startProducing(blobfile)
- def delete_blob(self, user, blob_id, namespace=''):
+ def delete_blob(self, user, blob_id, request, namespace=''):
blob_path = self._get_path(user, blob_id, namespace)
+ if not os.path.isfile(blob_path):
+ request.setResponseCode(404)
+ return "Blob doesn't exists: %s" % blob_id
os.unlink(blob_path)
try:
os.unlink(blob_path + '.flags')
@@ -175,7 +178,12 @@ class FilesystemBlobsBackend(object):
return self._get_disk_usage(self._get_path(user))
def add_tag_header(self, user, blob_id, request, namespace=''):
- with open(self._get_path(user, blob_id, namespace)) as doc_file:
+ blob_path = self._get_path(user, blob_id, namespace)
+ if not os.path.isfile(blob_path):
+ # 404 - Not Found
+ request.setResponseCode(404)
+ return "Blob doesn't exists: %s" % blob_id
+ with open(blob_path) as doc_file:
doc_file.seek(-16, 2)
tag = base64.urlsafe_b64encode(doc_file.read())
request.responseHeaders.setRawHeaders('Tag', [tag])
@@ -202,6 +210,10 @@ class FilesystemBlobsBackend(object):
raise Exception(err)
return desired_path
+ def exists(self, user, blob_id, namespace):
+ return os.path.isfile(
+ self._get_path(user, blob_id=blob_id, namespace=namespace))
+
def _get_path(self, user, blob_id='', namespace=''):
parts = [user]
if blob_id:
@@ -262,7 +274,7 @@ class BlobsResource(resource.Resource):
def render_DELETE(self, request):
logger.info("http put: %s" % request.path)
user, blob_id, namespace = self._validate(request)
- self._handler.delete_blob(user, blob_id, namespace)
+ self._handler.delete_blob(user, blob_id, request, namespace=namespace)
return ''
def render_PUT(self, request):