From 7c1303fe361b62841d1788ce1d8133a4f9ede30c Mon Sep 17 00:00:00 2001 From: janbar Date: Thu, 9 Nov 2023 18:39:10 +0100 Subject: [PATCH] try to clean up partial download on resume --- .../include/osmscoutclientqt/FileDownloader.h | 1 + .../src/osmscoutclientqt/FileDownloader.cpp | 2 +- .../src/osmscoutclientqt/MapManager.cpp | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libosmscout-client-qt/include/osmscoutclientqt/FileDownloader.h b/libosmscout-client-qt/include/osmscoutclientqt/FileDownloader.h index ad809057f..f2ba32551 100644 --- a/libosmscout-client-qt/include/osmscoutclientqt/FileDownloader.h +++ b/libosmscout-client-qt/include/osmscoutclientqt/FileDownloader.h @@ -46,6 +46,7 @@ static constexpr std::chrono::seconds DownloadReadTimeout{60}; ///< Download rea static constexpr std::chrono::seconds BackOffInitial{1}; ///< Initial back-off time static constexpr std::chrono::seconds BackOffMax{300}; ///< Maximum back-off time static constexpr int MaxDownloadRetries{-1}; ///< Maximal number of download retries before cancelling download +static constexpr char const *TemporaryFileSuffix{".download"}; ///< suffix of file being downloaded } /// \brief Downloads a file specified by URL diff --git a/libosmscout-client-qt/src/osmscoutclientqt/FileDownloader.cpp b/libosmscout-client-qt/src/osmscoutclientqt/FileDownloader.cpp index d785e4cef..cc737ab36 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/FileDownloader.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/FileDownloader.cpp @@ -62,7 +62,7 @@ FileDownloader::FileDownloader(QNetworkAccessManager *manager, return; } - file.setFileName(path + ".download"); + file.setFileName(path + FileDownloaderConfig::TemporaryFileSuffix); if (!file.open(QIODevice::WriteOnly)) { isOk = false; qWarning() << "Cannot open file:" << file.fileName(); diff --git a/libosmscout-client-qt/src/osmscoutclientqt/MapManager.cpp b/libosmscout-client-qt/src/osmscoutclientqt/MapManager.cpp index 7a0b20697..8097c7a8a 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/MapManager.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/MapManager.cpp @@ -62,11 +62,16 @@ void MapDownloadJob::start() mapDir.getCreation() == map.getCreation()) { // directory contains partial download // (contains downloader metadata, but not all required files) - // TODO: continue partial download + if (!mapDir.deleteDatabase()) { + qWarning() << "Failed to clean up partial download" << target.canonicalPath()<<"!"; + onJobFailed("Directory already exists", false); + return; + } + } else { + qWarning() << "Directory already exists" << target.canonicalPath()<<"!"; + onJobFailed("Directory already exists", false); + return; } - qWarning() << "Directory already exists"<