diff --git a/CHANGELOG.md b/CHANGELOG.md index 4365525a..66ce37e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixes +- General + - single thread downloader (**wget**) does not create the directory where the file will be stored + - Arch - **wget** as a hard requirement for Arch package management diff --git a/bauh/view/core/downloader.py b/bauh/view/core/downloader.py index 0d61d5b0..5c17d92c 100644 --- a/bauh/view/core/downloader.py +++ b/bauh/view/core/downloader.py @@ -6,8 +6,9 @@ import time import traceback from io import StringIO from math import floor +from pathlib import Path from threading import Thread -from typing import Iterable, List, Tuple +from typing import Iterable, List from bauh.api.abstract.download import FileDownloader from bauh.api.abstract.handler import ProcessWatcher @@ -130,10 +131,20 @@ class AdaptableFileDownloader(FileDownloader): success = False ti = time.time() try: - if output_path and os.path.exists(output_path): - self.logger.info(f'Removing old file found before downloading: {output_path}') - os.remove(output_path) - self.logger.info(f'Old file {output_path} removed') + if output_path: + if os.path.exists(output_path): + self.logger.info(f'Removing old file found before downloading: {output_path}') + os.remove(output_path) + self.logger.info(f'Old file {output_path} removed') + else: + output_dir = os.path.dirname(output_path) + + try: + Path(output_dir).mkdir(exist_ok=True, parents=True) + except OSError: + self.logger.error(f"Could not make download directory '{output_dir}'") + watcher.print(self.i18n['error.mkdir'].format(dir=output_dir)) + return False client = self.get_available_multithreaded_tool() if client: