don't create BlobFile object when deleting if it doesn't already exist

This commit is contained in:
Jack Robison 2019-02-11 18:27:14 -05:00
parent 8eede6dfc7
commit 85f41887fd
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -64,15 +64,21 @@ class BlobFileManager:
return [blob.blob_hash for blob in blobs if blob.get_is_verified()] return [blob.blob_hash for blob in blobs if blob.get_is_verified()]
async def delete_blob(self, blob_hash: str): async def delete_blob(self, blob_hash: str):
try: if not is_valid_blobhash(blob_hash):
blob = self.get_blob(blob_hash) raise Exception("invalid blob hash to delete")
await blob.delete() if blob_hash not in self.blobs:
except Exception as e: if os.path.isfile(os.path.join(self.blob_dir, blob_hash)):
log.warning("Failed to delete blob file. Reason: %s", e) os.remove(os.path.join(self.blob_dir, blob_hash))
else:
try:
blob = self.get_blob(blob_hash)
await blob.delete()
except Exception as e:
log.warning("Failed to delete blob file. Reason: %s", e)
if blob_hash in self.blobs:
del self.blobs[blob_hash]
if blob_hash in self.completed_blob_hashes: if blob_hash in self.completed_blob_hashes:
self.completed_blob_hashes.remove(blob_hash) self.completed_blob_hashes.remove(blob_hash)
if blob_hash in self.blobs:
del self.blobs[blob_hash]
async def delete_blobs(self, blob_hashes: typing.List[str], delete_from_db: typing.Optional[bool] = True): async def delete_blobs(self, blob_hashes: typing.List[str], delete_from_db: typing.Optional[bool] = True):
bh_to_delete_from_db = [] bh_to_delete_from_db = []