From 8ee7aa78afd3d3dee6e333953d51aa72cb227441 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Dec 2014 15:14:45 +0100 Subject: qt_mac_loadMenuNib: Prevent stale NIB files by diffing file size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we're changing the contents of the nib files in Qt, we need to overwrite the nib files that we write to /tmp, as QFile::copy() does not overwrite files. This also catches the case where the files in /tmp are empty due to a possible broken qrc-run, where re-runs of qrc to fix the resources would still leave the corrupt nib in /tmp, resulting in: -[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver? And as a consequence: qt_mac_loadMenuNib: could not instantiate nib ASSERT: "mainMenu" in file qcocoamenuloader.mm, line 154 Change-Id: I2907a32d1a56c23a27343c81839a06b65a529372 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoamenuloader.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index 9340e945fb..0075dea805 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -87,7 +87,11 @@ void qt_mac_loadMenuNib(QCocoaMenuLoader *qtMenuLoader) return; } foreach (const QFileInfo &file, nibResource.entryInfoList()) { - QFile::copy(file.absoluteFilePath(), nibDir + QLatin1String("/") + file.fileName()); + QFileInfo destinationFile(nibDir + QLatin1String("/") + file.fileName()); + if (destinationFile.exists() && destinationFile.size() != file.size()) + QFile::remove(destinationFile.absoluteFilePath()); + + QFile::copy(file.absoluteFilePath(), destinationFile.absoluteFilePath()); } // Load and instantiate nib file from temp -- cgit v1.2.3