From 7b485d13b0eae291e42b106c9282c480078f5255 Mon Sep 17 00:00:00 2001 From: lzzy12 Date: Sat, 12 Oct 2019 22:45:30 +0530 Subject: [PATCH] Fix crashes related to cancel mirror Signed-off-by: lzzy12 --- bot/modules/cancel_mirror.py | 2 -- bot/modules/mirror.py | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bot/modules/cancel_mirror.py b/bot/modules/cancel_mirror.py index 8d0ff88..b3a3bd2 100644 --- a/bot/modules/cancel_mirror.py +++ b/bot/modules/cancel_mirror.py @@ -30,8 +30,6 @@ def cancel_mirror(update: Update, context): @run_async def cancel_all(update, context): aria2.pause_all(True) - with download_dict_lock: - download_dict.clear() sendMessage('Cancelled all downloads!', context, update) clean_download(DOWNLOAD_DIR) diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index 7c45b24..a9b80b1 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -37,7 +37,11 @@ class MirrorListener(listeners.MirrorListeners): if self.isTar: with download_dict_lock: download_dict[self.uid].is_archiving = True - path = fs_utils.tar(f'{DOWNLOAD_DIR}{self.uid}/{progress_status_list[index].name()}') + try: + path = fs_utils.tar(f'{DOWNLOAD_DIR}{self.uid}/{progress_status_list[index].name()}') + except FileNotFoundError: + self.onUploadError('Download cancelled!', progress_status_list, index) + return else: path = f'{DOWNLOAD_DIR}{self.uid}/{progress_status_list[index].name()}' name = pathlib.PurePath(path).name @@ -51,8 +55,15 @@ class MirrorListener(listeners.MirrorListeners): LOGGER.error(error) with status_reply_dict_lock: if len(status_reply_dict) == 1: - deleteMessage(self.context, status_reply_dict[self.update.effective_chat.id]) - del status_reply_dict[self.update.effective_chat.id] + try: + deleteMessage(self.context, status_reply_dict[self.update.effective_chat.id]) + except KeyError: + pass + LOGGER.info(self.update.effective_chat.id) + try: + del status_reply_dict[self.update.effective_chat.id] + except KeyError: + pass with download_dict_lock: del download_dict[self.uid] fs_utils.clean_download(progress_status_list[index].path()) @@ -80,7 +91,7 @@ class MirrorListener(listeners.MirrorListeners): def onUploadError(self, error: str, progress_status: list, index: int): LOGGER.error(error) - editMessage(error, self.context, self.reply_message) + sendMessage(error, self.context, self.update) with download_dict_lock: del download_dict[self.message.message_id] fs_utils.clean_download(progress_status[index].path())