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:
parent
be8974633c
commit
672fcbe9c6
@ -77,9 +77,11 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
|
|||||||
m_matchingPatternLength = pattern.length();
|
m_matchingPatternLength = pattern.length();
|
||||||
m_weight = weight;
|
m_weight = weight;
|
||||||
}
|
}
|
||||||
m_matchingMimeTypes.append(mimeType);
|
if (!m_matchingMimeTypes.contains(mimeType)) {
|
||||||
if (pattern.startsWith(QLatin1String("*.")))
|
m_matchingMimeTypes.append(mimeType);
|
||||||
m_foundSuffix = pattern.mid(2);
|
if (pattern.startsWith(QLatin1String("*.")))
|
||||||
|
m_foundSuffix = pattern.mid(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -876,7 +876,10 @@ void tst_QMimeDatabase::installNewLocalMimeType()
|
|||||||
QDir().mkpath(destDir);
|
QDir().mkpath(destDir);
|
||||||
const QString destFile = destDir + QLatin1String(yastFileName);
|
const QString destFile = destDir + QLatin1String(yastFileName);
|
||||||
QFile::remove(destFile);
|
QFile::remove(destFile);
|
||||||
|
const QString destQmlFile = destDir + QLatin1String(qmlAgainFileName);
|
||||||
|
QFile::remove(destQmlFile);
|
||||||
QVERIFY(QFile::copy(m_yastMimeTypes, destFile));
|
QVERIFY(QFile::copy(m_yastMimeTypes, destFile));
|
||||||
|
QVERIFY(QFile::copy(m_qmlAgainFileName, destQmlFile));
|
||||||
if (!runUpdateMimeDatabase(mimeDir)) {
|
if (!runUpdateMimeDatabase(mimeDir)) {
|
||||||
const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
|
const QString skipWarning = QStringLiteral("shared-mime-info not found, skipping mime.cache test (")
|
||||||
+ QDir::toNativeSeparators(mimeDir) + QLatin1Char(')');
|
+ QDir::toNativeSeparators(mimeDir) + QLatin1Char(')');
|
||||||
@ -888,8 +891,17 @@ void tst_QMimeDatabase::installNewLocalMimeType()
|
|||||||
QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
|
QVERIFY(db.mimeTypeForName(QLatin1String("text/x-suse-ymp")).isValid());
|
||||||
checkHasMimeType("text/x-suse-ymp");
|
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(destFile);
|
||||||
|
QFile::remove(destQmlFile);
|
||||||
if (!waitAndRunUpdateMimeDatabase(mimeDir))
|
if (!waitAndRunUpdateMimeDatabase(mimeDir))
|
||||||
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
QSKIP("shared-mime-info not found, skipping mime.cache test");
|
||||||
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
QCOMPARE(db.mimeTypeForFile(QLatin1String("foo.ymu"), QMimeDatabase::MatchExtension).name(),
|
||||||
|
Loading…
Reference in New Issue
Block a user