Skip to content

Commit

Permalink
Merge pull request #1522 from janbar/fix_resume_partial_download
Browse files Browse the repository at this point in the history
try to clean up partial download on resume
  • Loading branch information
Framstag authored Nov 10, 2023
2 parents a9aabce + 7c1303f commit b6d06f2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 15 additions & 4 deletions libosmscout-client-qt/src/osmscoutclientqt/MapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"<<target.canonicalPath()<<"!";
onJobFailed("Directory already exists", false);
return;
}

if (!target.mkpath(target.path())) {
Expand Down Expand Up @@ -221,6 +226,12 @@ bool MapDirectory::deleteDatabase()
for (const auto &fileName: fileNames) {
if(dir.exists(fileName)){
result&=dir.remove(fileName);
} else {
// check for partial download
QString tempfileName = fileName + FileDownloaderConfig::TemporaryFileSuffix;
if (dir.exists(tempfileName)){
result&=dir.remove(tempfileName);
}
}
}
QDir parent=dir;
Expand Down

0 comments on commit b6d06f2

Please sign in to comment.