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

@@ -990,8 +990,10 @@ QTextStream &operator<<(QTextStream &s, const FilePath &fn)
} }
#ifdef QT_GUI_LIB #ifdef QT_GUI_LIB
FileUtils::CopyAskingForOverwrite::CopyAskingForOverwrite(QWidget *dialogParent) FileUtils::CopyAskingForOverwrite::CopyAskingForOverwrite(
QWidget *dialogParent, const std::function<void(QFileInfo)> &postOperation)
: m_parent(dialogParent) : m_parent(dialogParent)
, m_postOperation(postOperation)
{} {}
bool FileUtils::CopyAskingForOverwrite::operator()(const QFileInfo &src, bool FileUtils::CopyAskingForOverwrite::operator()(const QFileInfo &src,
@@ -1036,6 +1038,8 @@ bool FileUtils::CopyAskingForOverwrite::operator()(const QFileInfo &src,
} }
return false; return false;
} }
if (m_postOperation)
m_postOperation(dest);
} }
m_files.append(dest.absoluteFilePath()); m_files.append(dest.absoluteFilePath());
return true; return true;

View File

@@ -168,13 +168,15 @@ public:
class QTCREATOR_UTILS_EXPORT CopyAskingForOverwrite class QTCREATOR_UTILS_EXPORT CopyAskingForOverwrite
{ {
public: public:
CopyAskingForOverwrite(QWidget *dialogParent); CopyAskingForOverwrite(QWidget *dialogParent,
const std::function<void(QFileInfo)> &postOperation = {});
bool operator()(const QFileInfo &src, const QFileInfo &dest, QString *error); bool operator()(const QFileInfo &src, const QFileInfo &dest, QString *error);
QStringList files() const; QStringList files() const;
private: private:
QWidget *m_parent; QWidget *m_parent;
QStringList m_files; QStringList m_files;
std::function<void(QFileInfo)> m_postOperation;
bool m_overwriteAll = false; bool m_overwriteAll = false;
bool m_skipAll = false; bool m_skipAll = false;
}; };

View File

@@ -37,6 +37,7 @@
#include <utils/pathchooser.h> #include <utils/pathchooser.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/runextensions.h> #include <utils/runextensions.h>
#include <utils/synchronousprocess.h>
#include <utils/temporarydirectory.h> #include <utils/temporarydirectory.h>
#include <utils/wizard.h> #include <utils/wizard.h>
#include <utils/wizardpage.h> #include <utils/wizardpage.h>
@@ -418,6 +419,19 @@ private:
Data *m_data = nullptr; 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) static bool copyPluginFile(const FilePath &src, const FilePath &dest)
{ {
const FilePath destFile = dest.pathAppended(src.fileName()); const FilePath destFile = dest.pathAppended(src.fileName());
@@ -444,6 +458,7 @@ static bool copyPluginFile(const FilePath &src, const FilePath &dest)
.arg(destFile.toUserOutput())); .arg(destFile.toUserOutput()));
return false; return false;
} }
postCopyOperation()(destFile.toFileInfo());
return true; return true;
} }
@@ -475,8 +490,8 @@ bool PluginInstallWizard::exec()
if (!FileUtils::copyRecursively(data.extractedPath, if (!FileUtils::copyRecursively(data.extractedPath,
installPath, installPath,
&error, &error,
FileUtils::CopyAskingForOverwrite( FileUtils::CopyAskingForOverwrite(ICore::dialogParent(),
ICore::dialogParent()))) { postCopyOperation()))) {
QMessageBox::warning(ICore::dialogParent(), QMessageBox::warning(ICore::dialogParent(),
PluginInstallWizard::tr("Failed to Copy Plugin Files"), PluginInstallWizard::tr("Failed to Copy Plugin Files"),
error); error);