Skip to content

Bulk asynchronous downloader for multiple file hosts

remove temp file upon race condition.

Julesc2aebd93ad1e
diff --git a/utils/downloaders.py b/utils/downloaders.py
index 42ec35eb6..26b9b1715 100644
--- a/utils/downloaders.py
+++ b/utils/downloaders.py
@@ -5,6 +5,7 @@ from pathlib import Path
from typing import Any, Callable, Iterable, List, Optional, Type, TypeVar, Union, cast, Dict
from urllib.parse import urljoin
import aiofiles
+import aiofiles.os
import aiohttp
import aiohttp.client_exceptions
from requests.structures import CaseInsensitiveDict
@@ -130,10 +131,11 @@ class Downloader:
async def rename_file(self, filename: str) -> None:
"""Rename complete file."""
complete_file = (self.folder / self.title / filename)
+ temp_file = complete_file.with_suffix(".download")
if complete_file.exists():
logger.debug(str(self.folder / self.title / filename) + " Already Exists")
+ await aiofiles.os.remove(temp_file)
else:
- temp_file = complete_file.with_suffix(".download")
temp_file.rename(complete_file)
logger.debug("Finished " + filename)