From 89702040cd43f6b4c5dd4c7e79bf79f30413749e Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 21 Jan 2025 17:39:40 +0100 Subject: [PATCH] Plugins: Fix Plugin installation from archive / file Previously the spec returned and used was initialized from the temporary folder after extraction. That folder is deleted though once the install wizard is done. We now re-create the spec after copying the files to their final destination. Change-Id: Ia6b2f3c67a9d89687fece97e59143c00689ae513 Reviewed-by: Eike Ziller --- src/libs/extensionsystem/pluginspec.cpp | 10 ++++++++++ src/plugins/coreplugin/plugininstallwizard.cpp | 17 ++++++++++++++++- src/plugins/lua/luaplugin.cpp | 12 +++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/libs/extensionsystem/pluginspec.cpp b/src/libs/extensionsystem/pluginspec.cpp index b7456c49b34..c01f21b47ab 100644 --- a/src/libs/extensionsystem/pluginspec.cpp +++ b/src/libs/extensionsystem/pluginspec.cpp @@ -1405,6 +1405,16 @@ static QList createCppPluginsFromArchive(const FilePath &path) { QList results; + if (path.isFile()) { + if (QLibrary::isLibrary(path.toFSPathString())) { + expected_str> spec = readCppPluginSpec(path); + QTC_CHECK_EXPECTED(spec); + if (spec) + results.push_back(spec->release()); + } + return results; + } + // look for plugin QDirIterator it(path.path(), diff --git a/src/plugins/coreplugin/plugininstallwizard.cpp b/src/plugins/coreplugin/plugininstallwizard.cpp index 1a0ce9247be..40145d9418d 100644 --- a/src/plugins/coreplugin/plugininstallwizard.cpp +++ b/src/plugins/coreplugin/plugininstallwizard.cpp @@ -533,7 +533,15 @@ bool executePluginInstallWizard(const FilePath &archive) const FilePath installPath = data.pluginSpec->installLocation( !data.installIntoApplication); if (hasLibSuffix(data.sourcePath)) { - return copyPluginFile(data.sourcePath, installPath); + if (!copyPluginFile(data.sourcePath, installPath)) + return false; + + auto specs = pluginSpecsFromArchive(installPath.resolvePath( + data.pluginSpec->filePath().relativePathFrom(data.extractedPath))); + + QTC_ASSERT(specs.size() == 1, return false); + data.pluginSpec.reset(specs.front()); + } else { QString error; FileUtils::CopyAskingForOverwrite copy(ICore::dialogParent(), postCopyOperation()); @@ -542,6 +550,13 @@ bool executePluginInstallWizard(const FilePath &archive) ICore::dialogParent(), Tr::tr("Failed to Copy Plugin Files"), error); return false; } + + auto specs = pluginSpecsFromArchive(installPath.resolvePath( + data.pluginSpec->filePath().relativePathFrom(data.extractedPath))); + + QTC_ASSERT(specs.size() == 1, return false); + data.pluginSpec.reset(specs.front()); + return true; } } diff --git a/src/plugins/lua/luaplugin.cpp b/src/plugins/lua/luaplugin.cpp index 07661245121..37d195c99cb 100644 --- a/src/plugins/lua/luaplugin.cpp +++ b/src/plugins/lua/luaplugin.cpp @@ -317,7 +317,17 @@ public: setupLuaExpander(globalMacroExpander()); - pluginSpecsFromArchiveFactories().push_back([](const FilePath &path) { + pluginSpecsFromArchiveFactories().push_back([](const FilePath &path) -> QList { + if (path.isFile()) { + if (path.suffix() == "lua") { + Utils::expected_str spec = loadPlugin(path); + QTC_CHECK_EXPECTED(spec); + if (spec) + return {*spec}; + } + return {}; + } + QList plugins; auto dirs = path.dirEntries(QDir::Dirs | QDir::NoDotAndDotDot); for (const auto &dir : dirs) {