Skip to content

Commit

Permalink
fix: Fix TUI crashes when removing files for downloads without
Browse files Browse the repository at this point in the history
Pull Request: #74
  • Loading branch information
jonnieey committed Nov 3, 2020
1 parent e801089 commit c066971
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/aria2p/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c066971

Please sign in to comment.