diff --git a/kerfuffle/pluginmanager.h b/kerfuffle/pluginmanager.h --- a/kerfuffle/pluginmanager.h +++ b/kerfuffle/pluginmanager.h @@ -133,9 +133,14 @@ static QStringList sortByComment(const QSet &mimeTypes); /** - * Workaround for libarchive >= 3.3 not linking against liblzo. + * @return a filtered list of mimetypes supported */ - static bool libarchiveHasLzo(); + void filterAvailableMimeTypes(QSet &mimeTypes) const; + + /** + * @return Thes dependencies of libarchive + */ + static QByteArray libarchiveDependencies(); QVector m_plugins; QHash> m_preferredPluginsCache; diff --git a/kerfuffle/pluginmanager.cpp b/kerfuffle/pluginmanager.cpp --- a/kerfuffle/pluginmanager.cpp +++ b/kerfuffle/pluginmanager.cpp @@ -133,20 +133,7 @@ } } - // Remove entry for lrzipped tar if lrzip executable not found in path. - if (QStandardPaths::findExecutable(QStringLiteral("lrzip")).isEmpty()) { - supported.remove(QStringLiteral("application/x-lrzip-compressed-tar")); - } - - // Remove entry for lz4-compressed tar if lz4 executable not found in path. - if (QStandardPaths::findExecutable(QStringLiteral("lz4")).isEmpty()) { - supported.remove(QStringLiteral("application/x-lz4-compressed-tar")); - } - - // Remove entry for lzo-compressed tar if libarchive not linked against lzo and lzop executable not found in path. - if (!libarchiveHasLzo() && QStandardPaths::findExecutable(QStringLiteral("lzop")).isEmpty()) { - supported.remove(QStringLiteral("application/x-tzo")); - } + filterAvailableMimeTypes(supported); if (mode == SortByComment) { return sortByComment(supported); @@ -169,6 +156,18 @@ } } + + filterAvailableMimeTypes(supported); + + if (mode == SortByComment) { + return sortByComment(supported); + } + + return supported.toList(); +} + +void PluginManager::filterAvailableMimeTypes(QSet &supported) const +{ // Remove entry for lrzipped tar if lrzip executable not found in path. if (QStandardPaths::findExecutable(QStringLiteral("lrzip")).isEmpty()) { supported.remove(QStringLiteral("application/x-lrzip-compressed-tar")); @@ -179,16 +178,39 @@ supported.remove(QStringLiteral("application/x-lz4-compressed-tar")); } + QByteArray libArchiveDependencies; + bool dependenciesFetched = false; + // Remove entry for lzo-compressed tar if libarchive not linked against lzo and lzop executable not found in path. - if (!libarchiveHasLzo() && QStandardPaths::findExecutable(QStringLiteral("lzop")).isEmpty()) { - supported.remove(QStringLiteral("application/x-tzo")); + if (QStandardPaths::findExecutable(QStringLiteral("lzop")).isEmpty()) { + libArchiveDependencies = libarchiveDependencies(); + dependenciesFetched = true; + if (!libArchiveDependencies.contains(QByteArrayLiteral("lzo"))) { + supported.remove(QStringLiteral("application/x-tzo")); + } } - if (mode == SortByComment) { - return sortByComment(supported); + // Remove entry for zstd-compressed tar if libarchive not linked against zst and zstd executable not found in path. + if (QStandardPaths::findExecutable(QStringLiteral("zstd")).isEmpty()) { + if (!dependenciesFetched) { + libArchiveDependencies = libarchiveDependencies(); + dependenciesFetched = true; + } + if (!libArchiveDependencies.contains(QByteArrayLiteral("ztsd"))) { + supported.remove(QStringLiteral("application/x-zstd-compressed-tar")); + } } - return supported.toList(); + // Remove entry for lzma-compressed tar if libarchive not linked against lzma and lzma executable not found in path. + if (QStandardPaths::findExecutable(QStringLiteral("lzma")).isEmpty()) { + if (!dependenciesFetched) { + libArchiveDependencies = libarchiveDependencies(); + dependenciesFetched = true; + } + if (!libArchiveDependencies.contains(QByteArrayLiteral("lzma"))) { + supported.remove(QStringLiteral("application/x-lzma-compressed-tar")); + } + } } QVector PluginManager::filterBy(const QVector &plugins, const QMimeType &mimeType) const @@ -260,8 +282,7 @@ return sortedMimeTypes; } -bool PluginManager::libarchiveHasLzo() -{ +QByteArray PluginManager::libarchiveDependencies() { // Step 1: look for the libarchive plugin, which is built against libarchive. const QString pluginPath = []() { const QStringList paths = QCoreApplication::libraryPaths(); @@ -288,15 +309,15 @@ const QString output = QString::fromUtf8(dependencyTool.readAllStandardOutput()); QRegularExpression regex(QStringLiteral("/.*/libarchive.so|/.*/libarchive.*.dylib")); if (!regex.match(output).hasMatch()) { - return false; + return ""; } - // Step 3: check whether libarchive links against liblzo. + // Step 3: check whether libarchive links against lib. const QStringList libarchivePath(regex.match(output).captured(0)); dependencyTool.setArguments(args + libarchivePath); dependencyTool.start(); dependencyTool.waitForFinished(); - return dependencyTool.readAllStandardOutput().contains(QByteArrayLiteral("lzo")); + return dependencyTool.readAllStandardOutput(); } }