Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to clean up partial download on resume #1522

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading