vfs: Don't always load plugins, check metadata

This commit is contained in:
Christian Kamm 2018-11-26 10:41:14 +01:00 committed by Kevin Ottens
parent cc912f4d02
commit 1e5e884805
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
4 changed files with 40 additions and 5 deletions

View file

@ -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)

View file

@ -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) {

View file

@ -0,0 +1,4 @@
{
"type": "vfs",
"version": "@MIRALL_VERSION_STRING@"
}

View file

@ -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)
};