diff options
author | kh1 <karsten.heimrich@nokia.com> | 2012-10-01 15:40:53 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2012-10-17 09:19:26 +0200 |
commit | b878ca377795e5e5bad16428683de711c3e60cdc (patch) | |
tree | c916da1b9620806c78050a073261a8b5c59a4a56 /src/libs/installer/downloadarchivesjob.cpp | |
parent | ba31ab511d9b1f5cfd581bf8ed2f35671dd26136 (diff) |
Add data to the cryptographic hash while downloading.
Task-number: QTIFW-10
Add the data on the fly, fixes re-reading the whole file to
compute the checksum.
Change-Id: I764019ab051e1faef2868d13cb17da101fad2fa8
Reviewed-by: Niels Weber <niels.weber@digia.com>
Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'src/libs/installer/downloadarchivesjob.cpp')
-rw-r--r-- | src/libs/installer/downloadarchivesjob.cpp | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/src/libs/installer/downloadarchivesjob.cpp b/src/libs/installer/downloadarchivesjob.cpp index 49abee339..f7aa2c896 100644 --- a/src/libs/installer/downloadarchivesjob.cpp +++ b/src/libs/installer/downloadarchivesjob.cpp @@ -217,31 +217,24 @@ void DownloadArchivesJob::registerFile() { Q_ASSERT(m_downloader != 0); - const QString tempFile = m_downloader->downloadedFileName(); - if (m_core->testChecksum()) { - QFile archiveFile(tempFile); - if (archiveFile.open(QFile::ReadOnly)) { - const QByteArray archiveHash = QInstaller::calculateHash(&archiveFile, QCryptographicHash::Sha1) - .toHex(); - if ((archiveHash != m_currentHash) && (!m_canceled)) { - //TODO: Maybe we should try to download the file again automatically - const QMessageBox::Button res = - MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), - QLatin1String("DownloadError"), tr("Download Error"), tr("Hash verification while " - "downloading failed. This is a temporary error, please retry."), - QMessageBox::Retry | QMessageBox::Cancel, QMessageBox::Cancel); - - if (res == QMessageBox::Cancel) { - finishWithError(tr("Could not verify Hash")); - return; - } - - fetchNextArchiveHash(); - return; - } - } else { - finishWithError(tr("Could not open %1").arg(tempFile)); + if (m_canceled) + return; + + if (m_core->testChecksum() && m_currentHash != m_downloader->sha1Sum().toHex()) { + //TODO: Maybe we should try to download the file again automatically + const QMessageBox::Button res = + MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), + QLatin1String("DownloadError"), tr("Download Error"), tr("Hash verification while " + "downloading failed. This is a temporary error, please retry."), + QMessageBox::Retry | QMessageBox::Cancel, QMessageBox::Cancel); + + if (res == QMessageBox::Cancel) { + finishWithError(tr("Could not verify Hash")); + return; } + + fetchNextArchiveHash(); + return; } ++m_archivesDownloaded; @@ -251,9 +244,10 @@ void DownloadArchivesJob::registerFile() emit progressChanged(double(m_archivesDownloaded) / m_archivesToDownloadCount); } - m_temporaryFiles.insert(tempFile); + m_temporaryFiles.insert(m_downloader->downloadedFileName()); const QPair<QString, QString> pair = m_archivesToDownload.takeFirst(); - QInstallerCreator::BinaryFormatEngineHandler::instance()->registerArchive(pair.first, tempFile); + QInstallerCreator::BinaryFormatEngineHandler::instance()->registerArchive(pair.first, + m_downloader->downloadedFileName()); fetchNextArchiveHash(); } |