[BUGFIX] Clear working directory before starting any downloads

This commit is contained in:
Jesse Bannon 2022-11-30 14:08:58 -08:00
parent 96e741c71d
commit df88ae99ba

View file

@ -95,9 +95,10 @@ class SubscriptionDownload(BaseSubscription, ABC):
entry=entry, entry=entry,
) )
def _delete_working_directory(self, is_error: bool) -> None: def _delete_working_directory(self, is_error: bool = False) -> None:
_ = is_error _ = is_error
shutil.rmtree(self.working_directory) if os.path.isdir(self.working_directory):
shutil.rmtree(self.working_directory)
@contextlib.contextmanager @contextlib.contextmanager
def _prepare_working_directory(self): def _prepare_working_directory(self):
@ -105,6 +106,7 @@ class SubscriptionDownload(BaseSubscription, ABC):
Context manager to create all directories to the working directory. Deletes the entire Context manager to create all directories to the working directory. Deletes the entire
working directory when cleaning up. working directory when cleaning up.
""" """
self._delete_working_directory()
os.makedirs(self.working_directory, exist_ok=True) os.makedirs(self.working_directory, exist_ok=True)
try: try:
@ -113,7 +115,7 @@ class SubscriptionDownload(BaseSubscription, ABC):
self._delete_working_directory(is_error=True) self._delete_working_directory(is_error=True)
raise exc raise exc
else: else:
self._delete_working_directory(is_error=False) self._delete_working_directory()
@contextlib.contextmanager @contextlib.contextmanager
def _maintain_archive_file(self): def _maintain_archive_file(self):