From a7413ae6278e42fdf90c85c510890fa5fbc155df Mon Sep 17 00:00:00 2001 From: Brian Moran Date: Thu, 16 Mar 2023 20:49:08 -0700 Subject: [PATCH] create the directory if one is supplied that doesn't exist --- Network/FileDownload.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Network/FileDownload.cpp b/Network/FileDownload.cpp index 06c481e09..3a306022c 100644 --- a/Network/FileDownload.cpp +++ b/Network/FileDownload.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include "qt_helpers.hpp" #include "Logger.hpp" @@ -187,12 +187,21 @@ void FileDownload::download(QUrl qurl) QFileInfo destination_file(destination_filename_); QString const tmpfile_base = destination_file.fileName(); - QString const tmpfile_path = destination_file.absolutePath(); - destfile_.setFileName(destination_file.absoluteFilePath()); - if (!destfile_.open(QSaveFile::WriteOnly)) + QString const &tmpfile_path = destination_file.absolutePath(); + QDir tmpdir{}; + if (!tmpdir.mkpath(tmpfile_path)) { - LOG_INFO(QString{"FileDownload [%1]: Unable to open the temporary file based on %2"}.arg(user_agent_).arg(tmpfile_path)); - return; + LOG_INFO(QString{"FileDownload [%1]: Directory %2 does not exist"}.arg(user_agent_).arg(tmpfile_path).arg( + destfile_.errorString())); + } + + if (url_valid_) { + destfile_.setFileName(destination_file.absoluteFilePath()); + if (!destfile_.open(QSaveFile::WriteOnly | QIODevice::WriteOnly)) { + LOG_INFO(QString{"FileDownload [%1]: Unable to open %2: %3"}.arg(user_agent_).arg(destfile_.fileName()).arg( + destfile_.errorString())); + return; + } } }