[view] fix: single thread downloader does not create the directory where the file will be stored

This commit is contained in:
Vinicius Moreira
2021-11-24 15:01:22 -03:00
parent 63dd4963cf
commit ef254d611a
2 changed files with 19 additions and 5 deletions

View File

@@ -21,6 +21,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixes ### Fixes
- General
- single thread downloader (**wget**) does not create the directory where the file will be stored
- Arch - Arch
- **wget** as a hard requirement for Arch package management - **wget** as a hard requirement for Arch package management

View File

@@ -6,8 +6,9 @@ import time
import traceback import traceback
from io import StringIO from io import StringIO
from math import floor from math import floor
from pathlib import Path
from threading import Thread 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.download import FileDownloader
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
@@ -130,10 +131,20 @@ class AdaptableFileDownloader(FileDownloader):
success = False success = False
ti = time.time() ti = time.time()
try: try:
if output_path and os.path.exists(output_path): if output_path:
self.logger.info(f'Removing old file found before downloading: {output_path}') if os.path.exists(output_path):
os.remove(output_path) self.logger.info(f'Removing old file found before downloading: {output_path}')
self.logger.info(f'Old file {output_path} removed') 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() client = self.get_available_multithreaded_tool()
if client: if client: