Fix issues with the updater
* Bad URLs used for downloading update files * MD5ETagDownload resetting the expected ETag after failure to the failed file MD5 checksum * Delete MD5ETagDownload downloaded files if the download fails.
This commit is contained in:
parent
0f6ad12fd8
commit
01dbebdfc8
@ -23,7 +23,6 @@ MD5EtagDownload::MD5EtagDownload(QUrl url, QString target_path) : NetAction()
|
|||||||
{
|
{
|
||||||
m_url = url;
|
m_url = url;
|
||||||
m_target_path = target_path;
|
m_target_path = target_path;
|
||||||
m_check_md5 = false;
|
|
||||||
m_status = Job_NotStarted;
|
m_status = Job_NotStarted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,22 +33,26 @@ void MD5EtagDownload::start()
|
|||||||
// if there already is a file and md5 checking is in effect and it can be opened
|
// if there already is a file and md5 checking is in effect and it can be opened
|
||||||
if (m_output_file.exists() && m_output_file.open(QIODevice::ReadOnly))
|
if (m_output_file.exists() && m_output_file.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
// check the md5 against the expected one
|
// get the md5 of the local file.
|
||||||
QString hash =
|
m_local_md5 =
|
||||||
QCryptographicHash::hash(m_output_file.readAll(), QCryptographicHash::Md5)
|
QCryptographicHash::hash(m_output_file.readAll(), QCryptographicHash::Md5)
|
||||||
.toHex()
|
.toHex()
|
||||||
.constData();
|
.constData();
|
||||||
m_output_file.close();
|
m_output_file.close();
|
||||||
// skip this file if they match
|
// if we are expecting some md5sum, compare it with the local one
|
||||||
if (m_check_md5 && hash == m_expected_md5)
|
if (!m_expected_md5.isEmpty())
|
||||||
{
|
{
|
||||||
QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
|
// skip if they match
|
||||||
emit succeeded(m_index_within_job);
|
if(m_local_md5 == m_expected_md5)
|
||||||
return;
|
{
|
||||||
|
QLOG_INFO() << "Skipping " << m_url.toString() << ": md5 match.";
|
||||||
|
emit succeeded(m_index_within_job);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_expected_md5 = hash;
|
// no expected md5. we use the local md5sum as an ETag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ensureFilePathExists(filename))
|
if (!ensureFilePathExists(filename))
|
||||||
@ -58,9 +61,18 @@ void MD5EtagDownload::start()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLOG_INFO() << "Downloading " << m_url.toString() << " expecting " << m_expected_md5;
|
|
||||||
QNetworkRequest request(m_url);
|
QNetworkRequest request(m_url);
|
||||||
request.setRawHeader(QString("If-None-Match").toLatin1(), m_expected_md5.toLatin1());
|
|
||||||
|
QLOG_INFO() << "Downloading " << m_url.toString() << " got " << m_local_md5;
|
||||||
|
|
||||||
|
if(!m_local_md5.isEmpty())
|
||||||
|
{
|
||||||
|
QLOG_INFO() << "Got " << m_local_md5;
|
||||||
|
request.setRawHeader(QString("If-None-Match").toLatin1(), m_local_md5.toLatin1());
|
||||||
|
}
|
||||||
|
if(!m_expected_md5.isEmpty())
|
||||||
|
QLOG_INFO() << "Expecting " << m_expected_md5;
|
||||||
|
|
||||||
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
|
||||||
|
|
||||||
// Go ahead and try to open the file.
|
// Go ahead and try to open the file.
|
||||||
@ -107,7 +119,10 @@ void MD5EtagDownload::downloadFinished()
|
|||||||
m_status = Job_Finished;
|
m_status = Job_Finished;
|
||||||
m_output_file.close();
|
m_output_file.close();
|
||||||
|
|
||||||
|
// FIXME: compare with the real written data md5sum
|
||||||
|
// this is just an ETag
|
||||||
QLOG_INFO() << "Finished " << m_url.toString() << " got " << m_reply->rawHeader("ETag").constData();
|
QLOG_INFO() << "Finished " << m_url.toString() << " got " << m_reply->rawHeader("ETag").constData();
|
||||||
|
|
||||||
m_reply.reset();
|
m_reply.reset();
|
||||||
emit succeeded(m_index_within_job);
|
emit succeeded(m_index_within_job);
|
||||||
return;
|
return;
|
||||||
@ -116,6 +131,7 @@ void MD5EtagDownload::downloadFinished()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_output_file.close();
|
m_output_file.close();
|
||||||
|
m_output_file.remove();
|
||||||
m_reply.reset();
|
m_reply.reset();
|
||||||
emit failed(m_index_within_job);
|
emit failed(m_index_within_job);
|
||||||
return;
|
return;
|
||||||
|
@ -23,12 +23,10 @@ class MD5EtagDownload : public NetAction
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
/// if true, check the md5sum against a provided md5sum
|
/// the expected md5 checksum. Only set from outside
|
||||||
/// also, if a file exists, perform an md5sum first and don't download only if they don't
|
|
||||||
/// match
|
|
||||||
bool m_check_md5;
|
|
||||||
/// the expected md5 checksum
|
|
||||||
QString m_expected_md5;
|
QString m_expected_md5;
|
||||||
|
/// the md5 checksum of a file that already exists.
|
||||||
|
QString m_local_md5;
|
||||||
/// if saving to file, use the one specified in this string
|
/// if saving to file, use the one specified in this string
|
||||||
QString m_target_path;
|
QString m_target_path;
|
||||||
/// this is the output file, if any
|
/// this is the output file, if any
|
||||||
|
@ -396,7 +396,6 @@ DownloadUpdateTask::processFileLists(NetJob *job,
|
|||||||
// We need to download the file to the updatefiles folder and add a task
|
// We need to download the file to the updatefiles folder and add a task
|
||||||
// to copy it to its install path.
|
// to copy it to its install path.
|
||||||
auto download = MD5EtagDownload::make(source.url, dlPath);
|
auto download = MD5EtagDownload::make(source.url, dlPath);
|
||||||
download->m_check_md5 = true;
|
|
||||||
download->m_expected_md5 = entry.md5;
|
download->m_expected_md5 = entry.md5;
|
||||||
job->addNetAction(download);
|
job->addNetAction(download);
|
||||||
}
|
}
|
||||||
@ -487,9 +486,13 @@ bool DownloadUpdateTask::writeInstallScript(UpdateOperationList &opsList, QStrin
|
|||||||
|
|
||||||
QString DownloadUpdateTask::preparePath(const QString &path)
|
QString DownloadUpdateTask::preparePath(const QString &path)
|
||||||
{
|
{
|
||||||
QString foo = path;
|
if(path.startsWith("$PWD"))
|
||||||
foo.replace("$PWD", qApp->applicationDirPath());
|
{
|
||||||
return QUrl::fromLocalFile(foo).toString(QUrl::FullyEncoded);
|
QString foo = path;
|
||||||
|
foo.replace("$PWD", qApp->applicationDirPath());
|
||||||
|
return QUrl::fromLocalFile(foo).toString(QUrl::FullyEncoded);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadUpdateTask::fileDownloadFinished()
|
void DownloadUpdateTask::fileDownloadFinished()
|
||||||
|
Loading…
Reference in New Issue
Block a user