diff options
author | David Faure <david.faure@kdab.com> | 2020-12-31 21:28:51 +0100 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-01-05 18:31:54 +0000 |
commit | 0cbbba2aa5b472241d45b4be6959a792062fbc30 (patch) | |
tree | e6e3b3352a4cd38b6d4cbe67d30328104815b71b /src/corelib/mimetypes/qmimeprovider.cpp | |
parent | e688b99995b8c624dbcea296c99fb89262d29e15 (diff) |
Update shared-mime-info to the 2.1 release, adjust implementation
The spec hasn't changed, but I made the same mistake in xdgmime
(the reference implementation) and in Qt: when multiple globs match,
and the result from magic sniffing is unrelated to any of those globs,
then I used the magic result, but that's wrong, globs have priority
and one of them should be picked up.
This is now fixed in xdgmime
(https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/3)
and in the expected results in shared-mime-info
(https://gitlab.freedesktop.org/xdg/shared-mime-info/-/merge_requests/99)
which this commit is also tested against.
This change also optimizes QMimeBinaryProvider::addFileNameMatches
to have the same logic as xdgmime for glob matching:
literals > extensions > other globs
As soon as one category matches, we can stop there.
This makes no difference in the overall results, in practice.
The user bug report (against the Qt implementation, actually)
is https://gitlab.freedesktop.org/xdg/shared-mime-info/-/issues/138
as well as https://bugs.kde.org/show_bug.cgi?id=411718
Pick-to: 6.0 5.15
Change-Id: Ia0a34080427daff43c732609443ee6df8f41447c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/mimetypes/qmimeprovider.cpp')
-rw-r--r-- | src/corelib/mimetypes/qmimeprovider.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/mimetypes/qmimeprovider.cpp b/src/corelib/mimetypes/qmimeprovider.cpp index 39f4bbba2e..11643b8a1e 100644 --- a/src/corelib/mimetypes/qmimeprovider.cpp +++ b/src/corelib/mimetypes/qmimeprovider.cpp @@ -244,15 +244,18 @@ void QMimeBinaryProvider::addFileNameMatches(const QString &fileName, QMimeGlobM const QString lowerFileName = fileName.toLower(); // Check literals (e.g. "Makefile") matchGlobList(result, m_cacheFile, m_cacheFile->getUint32(PosLiteralListOffset), fileName); - // Check complex globs (e.g. "callgrind.out[0-9]*") - matchGlobList(result, m_cacheFile, m_cacheFile->getUint32(PosGlobListOffset), fileName); // Check the very common *.txt cases with the suffix tree - const int reverseSuffixTreeOffset = m_cacheFile->getUint32(PosReverseSuffixTreeOffset); - const int numRoots = m_cacheFile->getUint32(reverseSuffixTreeOffset); - const int firstRootOffset = m_cacheFile->getUint32(reverseSuffixTreeOffset + 4); - matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, lowerFileName, lowerFileName.length() - 1, false); + if (result.m_matchingMimeTypes.isEmpty()) { + const int reverseSuffixTreeOffset = m_cacheFile->getUint32(PosReverseSuffixTreeOffset); + const int numRoots = m_cacheFile->getUint32(reverseSuffixTreeOffset); + const int firstRootOffset = m_cacheFile->getUint32(reverseSuffixTreeOffset + 4); + matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, lowerFileName, lowerFileName.length() - 1, false); + if (result.m_matchingMimeTypes.isEmpty()) + matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true); + } + // Check complex globs (e.g. "callgrind.out[0-9]*" or "README*") if (result.m_matchingMimeTypes.isEmpty()) - matchSuffixTree(result, m_cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true); + matchGlobList(result, m_cacheFile, m_cacheFile->getUint32(PosGlobListOffset), fileName); } void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName) |