QMimeDatabase: Fix handling of duplicate mimetype definitions (2/2).

7721c3d27c fixed the case where two similar definitions are in the same
directory. This commit fixes the case where two similar definitions are
in different directories, both in the search path (GenericDataLocation).

If the file extension gives us the same mimetype twice, there's no conflict,
i.e. no reason to fallback to determination from contents.

Change-Id: I72c56004b6d5e88964159e53ec160ce8b06c2264
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2013-07-28 20:03:57 +02:00 committed by The Qt Project
parent be8974633c
commit 672fcbe9c6
2 changed files with 18 additions and 4 deletions

View File

@ -77,10 +77,12 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
m_matchingPatternLength = pattern.length();
m_weight = weight;
}
if (!m_matchingMimeTypes.contains(mimeType)) {
m_matchingMimeTypes.append(mimeType);
if (pattern.startsWith(QLatin1String("*.")))
m_foundSuffix = pattern.mid(2);
}
}
/*!
\internal

View File

@ -876,7 +876,10 @@ void tst_QMimeDatabase::installNewLocalMimeType()
QDir().mkpath(destDir);
const QString destFile = destDir + QLatin1String(yastFileName);
QFile::remove(destFile);
const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName);
QFile::remove(destQmlFile);
QVERIFY(QFile::copy(m_yastMimeTypes, destFile));
QVERIFY(QFile::copy(m_qmlAgainFileName, destQmlFile));
if (!runUpdateMimeDatabase(mimeDir)) {
const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
+ QDir::toNativeSeparators(mimeDir) + QLatin1Char(')');
@ -888,8 +891,17 @@ void tst_QMimeDatabase::installNewLocalMimeType()
QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
checkHasMimeType("text/x-suse-ymp");
// Now test removing it again (note, this leaves a mostly-empty mime.cache file)
// Test that a double-definition of a mimetype doesn't lead to sniffing ("conflicting globs").
const QString qmlTestFile = QFINDTESTDATA("test.qml");
QVERIFY2(!qmlTestFile.isEmpty(),
qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'").
arg("test.qml", QDir::currentPath())));
QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(),
QString::fromLatin1("text/x-qml"));
// Now test removing the local mimetypes again (note, this leaves a mostly-empty mime.cache file)
QFile::remove(destFile);
QFile::remove(destQmlFile);
if (!waitAndRunUpdateMimeDatabase(mimeDir))
QSKIP("shared-mime-info not found, skipping mime.cache test");
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),