[impl] Check if the file from download cache really exists before returning it
[impl] Remove downloaded update file if checksum is invalid
This commit is contained in:
parent
4e1edd2a33
commit
2b751fe84e
@ -66,20 +66,22 @@ boost::filesystem::path CachedDownloader::download(const std::string & url)
|
||||
auto it = m_cache.find(url);
|
||||
if (it != m_cache.end())
|
||||
{
|
||||
return m_cacheDir / it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto fileName = boost::filesystem::unique_path();
|
||||
auto tmpFile = m_cacheDir / fileName;
|
||||
auto cachedFilename = m_cacheDir / it->second;
|
||||
if (boost::filesystem::exists(cachedFilename))
|
||||
{
|
||||
std::ofstream os(tmpFile.string(), std::ofstream::binary);
|
||||
m_httpClient.get(url, os);
|
||||
return cachedFilename;
|
||||
}
|
||||
m_cache[url] = fileName.string();
|
||||
addToCache(m_cacheDir / cacheListFilename, url, fileName.string());
|
||||
return tmpFile;
|
||||
}
|
||||
|
||||
auto fileName = boost::filesystem::unique_path();
|
||||
auto tmpFile = m_cacheDir / fileName;
|
||||
{
|
||||
std::ofstream os(tmpFile.string(), std::ofstream::binary);
|
||||
m_httpClient.get(url, os);
|
||||
}
|
||||
m_cache[url] = fileName.string();
|
||||
addToCache(m_cacheDir / cacheListFilename, url, fileName.string());
|
||||
return tmpFile;
|
||||
}
|
||||
|
||||
void CachedDownloader::clearCache()
|
||||
|
||||
@ -27,6 +27,7 @@ void ModuleManager::applyUpdate(Module & module, const ModuleUpdate & update)
|
||||
auto hash = calcSHA256(updatePath);
|
||||
if (hash != boost::algorithm::to_upper_copy(update.checksum))
|
||||
{
|
||||
fs::remove(updatePath);
|
||||
throw std::runtime_error("Integrity check of the update has failed");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user