mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
vfs: Don't always load plugins, check metadata
This commit is contained in:
parent
cc912f4d02
commit
1e5e884805
4 changed files with 40 additions and 5 deletions
|
@ -12,3 +12,5 @@ set(common_SOURCES
|
|||
${CMAKE_CURRENT_LIST_DIR}/vfs.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/plugin.cpp
|
||||
)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/vfspluginmetadata.json.in ${CMAKE_CURRENT_BINARY_DIR}/vfspluginmetadata.json)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "vfs.h"
|
||||
#include "plugin.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <QPluginLoader>
|
||||
#include <QLoggingCategory>
|
||||
|
@ -74,6 +75,8 @@ static QString modeToPluginName(Vfs::Mode mode)
|
|||
return QString();
|
||||
}
|
||||
|
||||
Q_LOGGING_CATEGORY(lcPlugin, "plugins", QtInfoMsg)
|
||||
|
||||
bool OCC::isVfsPluginAvailable(Vfs::Mode mode)
|
||||
{
|
||||
if (mode == Vfs::Off)
|
||||
|
@ -81,7 +84,30 @@ bool OCC::isVfsPluginAvailable(Vfs::Mode mode)
|
|||
auto name = modeToPluginName(mode);
|
||||
if (name.isEmpty())
|
||||
return false;
|
||||
return QPluginLoader(pluginFileName("vfs", name)).load();
|
||||
auto pluginPath = pluginFileName("vfs", name);
|
||||
QPluginLoader loader(pluginPath);
|
||||
|
||||
auto basemeta = loader.metaData();
|
||||
if (basemeta.isEmpty() || !basemeta.contains("IID")) {
|
||||
qCDebug(lcPlugin) << "Plugin doesn't exist" << pluginPath;
|
||||
return false;
|
||||
}
|
||||
if (basemeta["IID"].toString() != "org.owncloud.PluginFactory") {
|
||||
qCWarning(lcPlugin) << "Plugin has wrong IID" << pluginPath << basemeta["IID"];
|
||||
return false;
|
||||
}
|
||||
|
||||
auto metadata = basemeta["MetaData"].toObject();
|
||||
if (metadata["type"].toString() != "vfs") {
|
||||
qCWarning(lcPlugin) << "Plugin has wrong type" << pluginPath << metadata["type"];
|
||||
return false;
|
||||
}
|
||||
if (metadata["version"].toString() != MIRALL_VERSION_STRING) {
|
||||
qCWarning(lcPlugin) << "Plugin has wrong version" << pluginPath << metadata["version"];
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Vfs::Mode OCC::bestAvailableVfsMode()
|
||||
|
@ -94,8 +120,6 @@ Vfs::Mode OCC::bestAvailableVfsMode()
|
|||
return Vfs::Off;
|
||||
}
|
||||
|
||||
Q_LOGGING_CATEGORY(lcPlugin, "plugins", QtInfoMsg)
|
||||
|
||||
std::unique_ptr<Vfs> OCC::createVfsFromPlugin(Vfs::Mode mode)
|
||||
{
|
||||
if (mode == Vfs::Off)
|
||||
|
@ -104,8 +128,13 @@ std::unique_ptr<Vfs> OCC::createVfsFromPlugin(Vfs::Mode mode)
|
|||
auto name = modeToPluginName(mode);
|
||||
if (name.isEmpty())
|
||||
return nullptr;
|
||||
|
||||
auto pluginPath = pluginFileName("vfs", name);
|
||||
|
||||
if (!isVfsPluginAvailable(mode)) {
|
||||
qCWarning(lcPlugin) << "Could not load plugin: not existant or bad metadata" << pluginPath;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QPluginLoader loader(pluginPath);
|
||||
auto plugin = loader.instance();
|
||||
if (!plugin) {
|
||||
|
|
4
src/common/vfspluginmetadata.json.in
Normal file
4
src/common/vfspluginmetadata.json.in
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "vfs",
|
||||
"version": "@MIRALL_VERSION_STRING@"
|
||||
}
|
|
@ -51,7 +51,7 @@ public:
|
|||
class SuffixVfsPluginFactory : public QObject, public DefaultPluginFactory<VfsSuffix>
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.owncloud.PluginFactory")
|
||||
Q_PLUGIN_METADATA(IID "org.owncloud.PluginFactory" FILE "vfspluginmetadata.json")
|
||||
Q_INTERFACES(OCC::PluginFactory)
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue