[frameworks/kfilemetadata] src: [ExtractorPlugin] Allow alias names when matching extractor mimetypes
Stefan Brüns <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 097f04951b2e29e6d3e910f1a1579653714ab8af by Stefan Brüns.
Committed on 10/08/2026 at 17:02.
Pushed by bruns into branch 'master'.
[ExtractorPlugin] Allow alias names when matching extractor mimetypes
Shared-Mime-Info has renamed mimetypes occasionaly to follow
upstream changes (e.g. new RFCs, changes due to new IANA policies, ...),
but keeps the old names as aliases.
This has happened in the past for audio/x-wav -> audio/vnd.wave, and
will likely happen in the future. So if an extractor supports a mimetype
by its deprecated (alias) name, match it as well. This decouples the
mimetype matching from the exact SMI version.
BUG: 522678
M +10 -1 src/extractorcollection.cpp
M +8 -1 src/extractorplugin.cpp
https://invent.kde.org/frameworks/kfilemetadata/-/commit/097f04951b2e29e6d3e910f1a1579653714ab8af
diff --git a/src/extractorcollection.cpp b/src/extractorcollection.cpp
index 1cf22c6a..6b68c2d4 100644
--- a/src/extractorcollection.cpp
+++ b/src/extractorcollection.cpp
@@ -165,9 +165,18 @@ QList<Extractor*> ExtractorCollection::fetchExtractors(const QString& mimetype)
return plugins;
}
- // try to find the best matching more generic extractor by mimetype inheritance
QMimeDatabase db;
auto type = db.mimeTypeForName(mimetype);
+ const QStringList aliases = type.aliases();
+ for (const auto &alias: aliases) {
+ QList<Extractor*> plugins = d->getExtractors(alias);
+ if (!plugins.isEmpty()) {
+ qCDebug(KFILEMETADATA_LOG) << "Using deprecated mimetype" << alias << "for" << mimetype;
+ return plugins;
+ }
+ }
+
+ // try to find the best matching more generic extractor by mimetype inheritance
const QStringList ancestors = type.allAncestors();
for (const auto &ancestor : ancestors) {
diff --git a/src/extractorplugin.cpp b/src/extractorplugin.cpp
index 99925170..04766cb6 100644
--- a/src/extractorplugin.cpp
+++ b/src/extractorplugin.cpp
@@ -72,13 +72,20 @@ QString ExtractorPlugin::getSupportedMimeType(const QString& mimetype) const
QMimeDatabase db;
auto type = db.mimeTypeForName(mimetype);
+
+ const QStringList aliases = type.aliases();
+ for (auto alias : aliases) {
+ if (allTypes.contains(alias)) {
+ return alias;
+ }
+ }
+
const QStringList ancestors = type.allAncestors();
for (auto ancestor : ancestors) {
if (allTypes.contains(ancestor)) {
return ancestor;
}
}
-
return QString();
}