[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,10 +66,13 @@ boost::filesystem::path CachedDownloader::download(const std::string & url)
|
|||||||
auto it = m_cache.find(url);
|
auto it = m_cache.find(url);
|
||||||
if (it != m_cache.end())
|
if (it != m_cache.end())
|
||||||
{
|
{
|
||||||
return m_cacheDir / it->second;
|
auto cachedFilename = m_cacheDir / it->second;
|
||||||
}
|
if (boost::filesystem::exists(cachedFilename))
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
return cachedFilename;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto fileName = boost::filesystem::unique_path();
|
auto fileName = boost::filesystem::unique_path();
|
||||||
auto tmpFile = m_cacheDir / fileName;
|
auto tmpFile = m_cacheDir / fileName;
|
||||||
{
|
{
|
||||||
@ -79,7 +82,6 @@ boost::filesystem::path CachedDownloader::download(const std::string & url)
|
|||||||
m_cache[url] = fileName.string();
|
m_cache[url] = fileName.string();
|
||||||
addToCache(m_cacheDir / cacheListFilename, url, fileName.string());
|
addToCache(m_cacheDir / cacheListFilename, url, fileName.string());
|
||||||
return tmpFile;
|
return tmpFile;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CachedDownloader::clearCache()
|
void CachedDownloader::clearCache()
|
||||||
|
|||||||
@ -27,6 +27,7 @@ void ModuleManager::applyUpdate(Module & module, const ModuleUpdate & update)
|
|||||||
auto hash = calcSHA256(updatePath);
|
auto hash = calcSHA256(updatePath);
|
||||||
if (hash != boost::algorithm::to_upper_copy(update.checksum))
|
if (hash != boost::algorithm::to_upper_copy(update.checksum))
|
||||||
{
|
{
|
||||||
|
fs::remove(updatePath);
|
||||||
throw std::runtime_error("Integrity check of the update has failed");
|
throw std::runtime_error("Integrity check of the update has failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user