diff options
author | Ivan Solovev <[email protected]> | 2024-12-10 14:02:06 +0100 |
---|---|---|
committer | Ivan Solovev <[email protected]> | 2025-01-02 15:45:37 +0100 |
commit | 5feca3da725e33b70cf8f27b7e923c727224c11e (patch) | |
tree | 4ce45f18b78da3dbf8775ed92df63dff89f55e55 | |
parent | 5525779b2ea9e2805c5d4a1b6b070ca8b4838396 (diff) |
macdeployqt: port to QSaveFile
... to avoid loosing file content in case of write errors.
Change-Id: If3f7af1e7260e3b9c3df201ed869988b0bd6df2a
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Joerg Bornemann <[email protected]>
-rw-r--r-- | src/tools/macdeployqt/shared/shared.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/tools/macdeployqt/shared/shared.cpp b/src/tools/macdeployqt/shared/shared.cpp index 19137d15944..fedc8bfd092 100644 --- a/src/tools/macdeployqt/shared/shared.cpp +++ b/src/tools/macdeployqt/shared/shared.cpp @@ -19,6 +19,7 @@ #include <QJsonArray> #include <QJsonValue> #include <QRegularExpression> +#include <QSaveFile> #include "shared.h" #ifdef Q_OS_DARWIN @@ -134,18 +135,21 @@ void patch_debugInInfoPlist(const QString &infoPlistPath) { // Older versions of qmake may have the "_debug" binary as // the value for CFBundleExecutable. Remove it. - QFile infoPlist(infoPlistPath); - if (infoPlist.open(QIODevice::ReadOnly)) { + if (QFile infoPlist(infoPlistPath); infoPlist.open(QIODevice::ReadOnly)) { QByteArray contents = infoPlist.readAll(); infoPlist.close(); - if (infoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + QSaveFile writableInfoPlist(infoPlistPath); + bool success = writableInfoPlist.open(QIODevice::WriteOnly | QIODevice::Truncate); + if (success) { contents.replace("_debug", ""); // surely there are no legit uses of "_debug" in an Info.plist - infoPlist.write(contents); - } else { - LogError() << "failed to write Info.plist file" << infoPlistPath; + writableInfoPlist.write(contents); + success = writableInfoPlist.commit(); + } + if (!success) { + LogError() << "Failed to write Info.plist file" << infoPlistPath; } } else { - LogError() << "failed to read Info.plist file" << infoPlistPath; + LogError() << "Failed to read Info.plist file" << infoPlistPath; } } @@ -1228,8 +1232,7 @@ void createQtConf(const QString &appBundlePath) QDir().mkpath(filePath); - QFile qtconf(fileName); - if (qtconf.exists() && !alwaysOwerwriteEnabled) { + if (QFile::exists(fileName) && !alwaysOwerwriteEnabled) { LogWarning(); LogWarning() << fileName << "already exists, will not overwrite."; LogWarning() << "To make sure the plugins are loaded from the correct location,"; @@ -1239,7 +1242,8 @@ void createQtConf(const QString &appBundlePath) return; } - if (qtconf.open(QIODevice::WriteOnly) && qtconf.write(contents) != -1) { + if (QSaveFile qtconf(fileName); qtconf.open(QIODevice::WriteOnly) + && qtconf.write(contents) != -1 && qtconf.commit()) { LogNormal() << "Created configuration file:" << fileName; LogNormal() << "This file sets the plugin search path to" << appBundlePath + "/Contents/PlugIns"; } |