From 85f41887fd5f70d38ff016dff634f24bcefaa758 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Mon, 11 Feb 2019 18:27:14 -0500 Subject: [PATCH] don't create BlobFile object when deleting if it doesn't already exist --- lbrynet/blob/blob_manager.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lbrynet/blob/blob_manager.py b/lbrynet/blob/blob_manager.py index 73c2b0573..8e0a5d2e6 100644 --- a/lbrynet/blob/blob_manager.py +++ b/lbrynet/blob/blob_manager.py @@ -64,15 +64,21 @@ class BlobFileManager: return [blob.blob_hash for blob in blobs if blob.get_is_verified()] async def delete_blob(self, blob_hash: str): - 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 not is_valid_blobhash(blob_hash): + raise Exception("invalid blob hash to delete") + if blob_hash not in self.blobs: + if os.path.isfile(os.path.join(self.blob_dir, blob_hash)): + 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: 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): bh_to_delete_from_db = []