summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-11-04 10:05:39 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-11-05 10:09:56 +0100
commit8af62166bad24a260960e77f6d40453997635de5 (patch)
treec2bc2738eaa48a1422d0c7f15e65eb152b710c8a
parente75afb9ab5746b97cb2d9f1538f7fd9ec943bb10 (diff)
windeployqt: Do not patch Qt5Core.dll unless necessary
Check whether the content is already is patched to avoid unnecessarily touching files. Fixes: QTBUG-78732 Change-Id: I061927e8908793b78211b4634c3dc772c12c7915 Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r--src/shared/winutils/utils.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/shared/winutils/utils.cpp b/src/shared/winutils/utils.cpp
index 00a205438..263efbe18 100644
--- a/src/shared/winutils/utils.cpp
+++ b/src/shared/winutils/utils.cpp
@@ -991,18 +991,21 @@ bool patchQtCore(const QString &path, QString *errorMessage)
std::wcout << "Patching " << QFileInfo(path).fileName() << "...\n";
QFile file(path);
- if (!file.open(QIODevice::ReadWrite)) {
+ if (!file.open(QIODevice::ReadOnly)) {
*errorMessage = QString::fromLatin1("Unable to patch %1: %2").arg(
QDir::toNativeSeparators(path), file.errorString());
return false;
}
- QByteArray content = file.readAll();
+ const QByteArray oldContent = file.readAll();
- if (content.isEmpty()) {
+ if (oldContent.isEmpty()) {
*errorMessage = QString::fromLatin1("Unable to patch %1: Could not read file content").arg(
QDir::toNativeSeparators(path));
return false;
}
+ file.close();
+
+ QByteArray content = oldContent;
QByteArray prfxpath("qt_prfxpath=");
int startPos = content.indexOf(prfxpath);
@@ -1023,11 +1026,13 @@ bool patchQtCore(const QString &path, QString *errorMessage)
QByteArray replacement = QByteArray(endPos - startPos, char(0));
replacement[0] = '.';
content.replace(startPos, endPos - startPos, replacement);
+ if (content == oldContent)
+ return true;
- if (!file.seek(0)
- || (file.write(content) != content.size())) {
- *errorMessage = QString::fromLatin1("Unable to patch %1: Could not write to file").arg(
- QDir::toNativeSeparators(path));
+ if (!file.open(QIODevice::WriteOnly)
+ || (file.write(content) != content.size())) {
+ *errorMessage = QString::fromLatin1("Unable to patch %1: Could not write to file: %2").arg(
+ QDir::toNativeSeparators(path), file.errorString());
return false;
}
return true;