QMimeDatabase: follow symlinks when checking for FIFO etc.
This was documented, but not what the code did. Task-number: QTBUG-48529 Change-Id: I4849778c61dcae13be27c62b24717693c0c07d78 Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
9871c3d8bd
commit
72b4f0d474
|
|
@ -354,9 +354,10 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mo
|
|||
|
||||
#ifdef Q_OS_UNIX
|
||||
// Cannot access statBuf.st_mode from the filesystem engine, so we have to stat again.
|
||||
// In addition we want to follow symlinks.
|
||||
const QByteArray nativeFilePath = QFile::encodeName(file.fileName());
|
||||
QT_STATBUF statBuffer;
|
||||
if (QT_LSTAT(nativeFilePath.constData(), &statBuffer) == 0) {
|
||||
if (QT_STAT(nativeFilePath.constData(), &statBuffer) == 0) {
|
||||
if (S_ISCHR(statBuffer.st_mode))
|
||||
return d->mimeTypeForName(QLatin1String("inode/chardevice"));
|
||||
if (S_ISBLK(statBuffer.st_mode))
|
||||
|
|
|
|||
|
|
@ -35,6 +35,11 @@
|
|||
|
||||
#include "qstandardpaths.h"
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QFileInfo>
|
||||
|
|
@ -646,6 +651,28 @@ void tst_QMimeDatabase::knownSuffix()
|
|||
QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.tar.bz2")), QString::fromLatin1("tar.bz2"));
|
||||
}
|
||||
|
||||
void tst_QMimeDatabase::symlinkToFifo() // QTBUG-48529
|
||||
{
|
||||
#ifdef Q_OS_UNIX
|
||||
QTemporaryDir tempDir;
|
||||
QVERIFY(tempDir.isValid());
|
||||
const QString dir = tempDir.path();
|
||||
const QString fifo = dir + "/fifo";
|
||||
QCOMPARE(mkfifo(QFile::encodeName(fifo), 0006), 0);
|
||||
|
||||
QMimeDatabase db;
|
||||
QCOMPARE(db.mimeTypeForFile(fifo).name(), QString::fromLatin1("inode/fifo"));
|
||||
|
||||
// Now make a symlink to the fifo
|
||||
const QString link = dir + "/link";
|
||||
QVERIFY(QFile::link(fifo, link));
|
||||
QCOMPARE(db.mimeTypeForFile(link).name(), QString::fromLatin1("inode/fifo"));
|
||||
|
||||
#else
|
||||
QSKIP("This test requires pipes and symlinks");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_QMimeDatabase::findByFileName_data()
|
||||
{
|
||||
QTest::addColumn<QString>("filePath");
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ private slots:
|
|||
void suffixes_data();
|
||||
void suffixes();
|
||||
void knownSuffix();
|
||||
void symlinkToFifo();
|
||||
void fromThreads();
|
||||
|
||||
// shared-mime-info test suite
|
||||
|
|
|
|||
Loading…
Reference in New Issue