[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

@@ -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: