Galaxy: Fix segfault when getting download url fails

This commit is contained in:
Sude 2018-09-30 20:05:06 +03:00
parent f5afc8957d
commit 8683fe0a4e

View File

@ -3610,6 +3610,7 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con
}
}
bool bChunkFailure = false;
std::time_t timestamp = -1;
for (unsigned int j = start_chunk; j < item.chunks.size(); ++j)
{
@ -3636,6 +3637,15 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con
else
json = galaxy->getSecureLink(item.product_id, galaxy->hashToGalaxyPath(item.chunks[j].md5_compressed));
if (json.empty())
{
bChunkFailure = true;
std::string error_message = path.string() + ": Empty JSON response (product: " + item.product_id + ", chunk #"+ std::to_string(j) + ": " + item.chunks[j].md5_compressed + ")";
msgQueue.push(Message(error_message, MSGTYPE_ERROR, msg_prefix));
free(chunk.memory);
break;
}
// Handle priority of CDNs
struct urlPriority
{
@ -3696,6 +3706,14 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con
cdnUrls.push_back(cdnurl);
}
if (cdnUrls.empty())
{
bChunkFailure = true;
msgQueue.push(Message(path.string() + ": Failed to get download url", MSGTYPE_ERROR, msg_prefix));
free(chunk.memory);
break;
}
// Sort urls by priority (lowest score first)
std::sort(cdnUrls.begin(), cdnUrls.end(),
[](urlPriority a, urlPriority b)
@ -3767,6 +3785,12 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con
free(chunk.memory);
}
if (bChunkFailure)
{
msgQueue.push(Message(path.string() + ": Chunk failure, skipping file", MSGTYPE_ERROR, msg_prefix));
continue;
}
// Set timestamp for downloaded file to same value as file on server
if (boost::filesystem::exists(path) && timestamp >= 0)
boost::filesystem::last_write_time(path, timestamp);