Improve plugin install wizard on macOS

Downloaded files get a quarantine flag on macOS, which prevents loading
them as a plugin in Qt Creator. Remove the quarantine flag when copying
the plugin.

Change-Id: I3edef3ddfbab299be750e728a9fac0536634ba1b
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Eike Ziller
2021-02-12 16:06:24 +01:00
parent 5168af3144
commit 27300c66fe
3 changed files with 25 additions and 4 deletions

View File

@@ -37,6 +37,7 @@
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
#include <utils/synchronousprocess.h>
#include <utils/temporarydirectory.h>
#include <utils/wizard.h>
#include <utils/wizardpage.h>
@@ -418,6 +419,19 @@ private:
Data *m_data = nullptr;
};
static std::function<void(QFileInfo)> postCopyOperation()
{
return [](const QFileInfo &fi) {
if (!HostOsInfo::isMacHost())
return;
// On macOS, downloaded files get a quarantine flag, remove it, otherwise it is a hassle
// to get it loaded as a plugin in Qt Creator.
SynchronousProcess xattr;
xattr.setTimeoutS(1);
xattr.runBlocking({"/usr/bin/xattr", {"-d", "com.apple.quarantine", fi.absoluteFilePath()}});
};
}
static bool copyPluginFile(const FilePath &src, const FilePath &dest)
{
const FilePath destFile = dest.pathAppended(src.fileName());
@@ -444,6 +458,7 @@ static bool copyPluginFile(const FilePath &src, const FilePath &dest)
.arg(destFile.toUserOutput()));
return false;
}
postCopyOperation()(destFile.toFileInfo());
return true;
}
@@ -475,8 +490,8 @@ bool PluginInstallWizard::exec()
if (!FileUtils::copyRecursively(data.extractedPath,
installPath,
&error,
FileUtils::CopyAskingForOverwrite(
ICore::dialogParent()))) {
FileUtils::CopyAskingForOverwrite(ICore::dialogParent(),
postCopyOperation()))) {
QMessageBox::warning(ICore::dialogParent(),
PluginInstallWizard::tr("Failed to Copy Plugin Files"),
error);