Skip to content

Commit

Permalink
feat: Add a clean parameter to API.remove to delete aria2 control file
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 20, 2019
1 parent 77451e6 commit d4b9a51
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/aria2p/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,15 @@ def move_to_bottom(self, download):
"""
return self.client.change_position(download.gid, 0, "POS_END")

def remove(self, downloads, force=False, files=False):
def remove(self, downloads, force=False, files=False, clean=True):
"""
Remove the given downloads from the list.
Args:
downloads (list of :class:`~aria2p.downloads.Download`): the list of downloads to remove.
force (bool): whether to force the removal or not.
files (bool): whether to remove downloads files as well.
clean (bool): whether to remove the aria2 control file as well.
Returns:
list of bool: Success or failure of the operation for each given download.
Expand Down Expand Up @@ -372,6 +373,16 @@ def remove(self, downloads, force=False, files=False):
except ClientException as error2:
logger.debug(f"Failed to remove download result {removed_gid}")
logger.opt(exception=True).trace(error2)

if clean:
# FUTURE: use missing_ok parameter on Python 3.8
try:
download.control_file_path.unlink()
except FileNotFoundError:
logger.debug(f"aria2 control file {download.control_file_path} was not found")
else:
logger.debug(f"Removed control file {download.control_file_path}")

if files and result[-1]:
self.remove_files([download], force=True)

Expand Down

0 comments on commit d4b9a51

Please sign in to comment.