Skip to content
Snippets Groups Projects
Verified Commit d627675a authored by drebs's avatar drebs
Browse files

[bug] add BlobNotFound exception to methods interface

parent 5a3d6cd0
No related branches found
No related tags found
1 merge request!175#8989 - Support range header when downloading blobs
......@@ -104,6 +104,8 @@ class FilesystemBlobsBackend(object):
def read_blob(self, user, blob_id, consumer, namespace='', range=None):
logger.info('reading blob: %s - %s@%s' % (user, blob_id, namespace))
path = self._get_path(user, blob_id, namespace)
if not os.path.isfile(path):
raise BlobNotFound((user, blob_id))
logger.debug('blob path: %s' % path)
with open(path) as fd:
if range is None:
......@@ -122,7 +124,7 @@ class FilesystemBlobsBackend(object):
except Exception as e:
return defer.fail(e)
if not os.path.isfile(path):
return defer.fail(BlobNotFound())
return defer.fail(BlobNotFound((user, blob_id)))
if not os.path.isfile(path + '.flags'):
return defer.succeed([])
with open(path + '.flags', 'r') as flags_file:
......@@ -135,7 +137,7 @@ class FilesystemBlobsBackend(object):
except Exception as e:
return defer.fail(e)
if not os.path.isfile(path):
return defer.fail(BlobNotFound())
return defer.fail(BlobNotFound((user, blob_id)))
for flag in flags:
if flag not in ACCEPTED_FLAGS:
return defer.fail(InvalidFlag(flag))
......@@ -184,7 +186,7 @@ class FilesystemBlobsBackend(object):
except Exception as e:
return defer.fail(e)
if not os.path.isfile(blob_path):
return defer.fail(BlobNotFound())
return defer.fail(BlobNotFound((user, blob_id)))
self.__touch(blob_path + '.deleted')
os.unlink(blob_path)
try:
......@@ -198,6 +200,8 @@ class FilesystemBlobsBackend(object):
blob_path = self._get_path(user, blob_id, namespace)
except Exception as e:
return defer.fail(e)
if not os.path.isfile(blob_path):
return defer.fail(BlobNotFound((user, blob_id)))
size = os.stat(blob_path).st_size
return defer.succeed(size)
......@@ -270,7 +274,7 @@ class FilesystemBlobsBackend(object):
except Exception as e:
return defer.fail(e)
if not os.path.isfile(blob_path):
return defer.fail(BlobNotFound())
return defer.fail(BlobNotFound((user, blob_id)))
with open(blob_path) as doc_file:
doc_file.seek(-16, 2)
tag = base64.urlsafe_b64encode(doc_file.read())
......
......@@ -206,6 +206,8 @@ class BlobsResource(resource.Resource):
d = self._handler.get_blob_size(user, blob_id, namespace=namespace)
d.addCallback(_handleRangeHeader)
d.addErrback(_catchBlobNotFound, request, user, blob_id)
d.addErrback(_catchAllErrors, request)
return NOT_DONE_YET
def render_DELETE(self, request):
......
......@@ -44,6 +44,9 @@ class IBlobsBackend(Interface):
:return: A deferred that fires when the blob has been written to the
consumer.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
"""
def write_blob(user, blob_id, producer, namespace=''):
......@@ -80,6 +83,9 @@ class IBlobsBackend(Interface):
:return: A deferred that fires when the blob has been deleted.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
"""
def get_blob_size(user, blob_id, namespace=''):
......@@ -95,6 +101,9 @@ class IBlobsBackend(Interface):
:return: A deferred that fires with the size of the blob.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
"""
def count(user, namespace=''):
......@@ -168,6 +177,9 @@ class IBlobsBackend(Interface):
:return: A deferred that fires with the tag of the blob.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
"""
def get_flags(user, blob_id, namespace=''):
......@@ -183,6 +195,9 @@ class IBlobsBackend(Interface):
:return: A deferred that fires with the list of flags for a blob.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
"""
def set_flags(user, blob_id, flags, namespace=''):
......@@ -200,4 +215,8 @@ class IBlobsBackend(Interface):
:return: A deferred that fires when the flags have been set.
:rtype: twisted.internet.defer.Deferred
:raise BlobNotFound: Raised (asynchronously) when the blob was not
found in the backend.
:raise InvalidFlag: Raised when one of the flags passed is invalid.
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment