From c066971f13d6806e180473cf2fd15733fa7d9543 Mon Sep 17 00:00:00 2001 From: jonnieey <47189744+jonnieey@users.noreply.github.com> Date: Wed, 4 Nov 2020 02:04:50 +0300 Subject: [PATCH] fix: Fix TUI crashes when removing files for downloads without Pull Request: https://github.com/pawamoy/aria2p/pull/74 --- src/aria2p/api.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/aria2p/api.py b/src/aria2p/api.py index 50c70c3..6d3147e 100644 --- a/src/aria2p/api.py +++ b/src/aria2p/api.py @@ -694,10 +694,21 @@ def remove_files( # noqa: WPS602 (static method) if download.is_complete or force: for path in download.root_files_paths: if path.is_dir(): - shutil.rmtree(str(path)) + try: + shutil.rmtree(str(path)) + except OSError: + logger.error(f"Could not delete directory '{path}'") + logger.opt(exception=True).trace(error) + results.append(False) + else: + results.append(True) else: - path.unlink() - results.append(True) + try: + path.unlink() + except FileNotFoundError as error: + logger.warning(f"File '{path}' did not exist when trying to delete it") + logger.opt(exception=True).trace(error) + results.append(True) else: results.append(False) return results