diff options
author | Tim Jenssen <tim.jenssen@digia.com> | 2013-11-13 13:56:17 +0100 |
---|---|---|
committer | Tim Jenssen <tim.jenssen@digia.com> | 2013-11-13 13:56:17 +0100 |
commit | c205faa465095a54d5a4de99b23522f4e0fbf37a (patch) | |
tree | b7d14125a5dd0343299a4ed6a0f0ac469bf8514c /src | |
parent | e8d3f737a5233f6799efd7e4104dc3316429cee4 (diff) | |
parent | a359a80cc564e3decefb88804fe92430ebc5bed7 (diff) |
Merge remote-tracking branch 'origin/1.4' into 1.5
Change-Id: I0bba1ced9316861cb6723ec1677a4d01e3b91d2f
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/installer/binaryformat.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/libs/installer/binaryformat.cpp b/src/libs/installer/binaryformat.cpp index df2366946..7aa4d94ab 100644 --- a/src/libs/installer/binaryformat.cpp +++ b/src/libs/installer/binaryformat.cpp @@ -216,6 +216,10 @@ QByteArray QInstaller::retrieveCompressedData(QIODevice *in, qint64 size) return qUncompress(ba); } +/*! + Search through 1MB, if smaller through the whole file. Note: QFile::map() does + not change QFile::pos(). Fallback to read the file content in case we can't map it. +*/ qint64 QInstaller::findMagicCookie(QFile *in, quint64 magicCookie) { Q_ASSERT(in); @@ -224,18 +228,28 @@ qint64 QInstaller::findMagicCookie(QFile *in, quint64 magicCookie) const qint64 fileSize = in->size(); const size_t markerSize = sizeof(qint64); - - // Search through 1MB, if smaller through the whole file. Note: QFile::map() does not change QFile::pos(). const qint64 maxSearch = qMin((1024LL * 1024LL), fileSize); - const uchar *const mapped = in->map(fileSize - maxSearch, maxSearch); + + QByteArray data(maxSearch, Qt::Uninitialized); + uchar *const mapped = in->map(fileSize - maxSearch, maxSearch); if (!mapped) { - throw Error(QObject::tr("Could not map %1 from file %2: %3").arg(QString::number(maxSearch), - in->fileName(), in->errorString())); + const int pos = in->pos(); + try { + in->seek(fileSize - maxSearch); + blockingRead(in, data.data(), maxSearch); + in->seek(pos); + } catch (const Error &error) { + in->seek(pos); + throw error; + } + } else { + data = QByteArray((const char*)mapped, maxSearch); + in->unmap(mapped); } qint64 searched = maxSearch - markerSize; while (searched >= 0) { - if (memcmp(&magicCookie, (mapped + searched), markerSize) == 0) + if (memcmp(&magicCookie, (data.data() + searched), markerSize) == 0) return (fileSize - maxSearch) + searched; --searched; } |