kio/0001-MimeTypeFinderJob-Resolve-symlinks-for-a-local-file.patch
Wolfgang Bauer ec2550ad7f Accepting request 893118 from home:Vogtinator:branches:KDE:Frameworks5
- Add patches to fix issues with MimeTypeFinderJob (kde#398908):
  * 0001-MimeTypeFinderJob-Resolve-symlinks-for-a-local-file.patch
  * 0002-MimeTypeFinderJob-the-StatJob-details-should-include.patch
  * 0003-kio_file-pass-the-absolute-path-to-QMimeDatabase-mim.patch

OBS-URL: https://build.opensuse.org/request/show/893118
OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5/kio?expand=0&rev=335
2021-05-15 08:23:41 +00:00

71 lines
2.9 KiB
Diff

From 542a74b8fa70fa530a436ee3222a9b0562155708 Mon Sep 17 00:00:00 2001
From: Jonathan Marten <jjm@keelhaul.me.uk>
Date: Sat, 8 May 2021 15:20:39 +0000
Subject: [PATCH 1/3] MimeTypeFinderJob: Resolve symlinks for a local file
(cherry picked from commit e79da836c34fce66231e396c7215314d0eba51b4)
---
autotests/mimetypefinderjobtest.cpp | 18 +++++++++++++++++-
src/core/mimetypefinderjob.cpp | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/autotests/mimetypefinderjobtest.cpp b/autotests/mimetypefinderjobtest.cpp
index 72296b9b..f494ff3b 100644
--- a/autotests/mimetypefinderjobtest.cpp
+++ b/autotests/mimetypefinderjobtest.cpp
@@ -48,6 +48,7 @@ void MimeTypeFinderJobTest::determineMimeType_data()
QTest::newRow("text_file_no_extension") << "text/plain" << "srcfile";
QTest::newRow("desktop_file") << "application/x-desktop" << "foo.desktop";
QTest::newRow("script") << "application/x-shellscript" << "srcfile.sh";
+ QTest::newRow("directory") << "inode/directory" << "srcdir";
/* clang-format on */
}
@@ -60,7 +61,12 @@ void MimeTypeFinderJobTest::determineMimeType()
QTemporaryDir tempDir;
const QString srcDir = tempDir.path();
const QString srcFile = srcDir + QLatin1Char('/') + fileName;
- createSrcFile(srcFile);
+ if (mimeType == "inode/directory") {
+ QVERIFY(QDir(srcDir).mkdir(fileName));
+ } else {
+ createSrcFile(srcFile);
+ }
+
QVERIFY(QFile::exists(srcFile));
const QUrl url = QUrl::fromLocalFile(srcFile);
@@ -68,6 +74,16 @@ void MimeTypeFinderJobTest::determineMimeType()
KIO::MimeTypeFinderJob *job = new KIO::MimeTypeFinderJob(url, this);
QVERIFY2(job->exec(), qPrintable(job->errorString()));
QCOMPARE(job->mimeType(), mimeType);
+
+ // Check that the result is the same when accessing the source
+ // file through a symbolic link (bug #436708)
+ const QString srcLink = srcDir + QLatin1String("/link_") + fileName;
+ QVERIFY(QFile::link(srcFile, srcLink));
+ const QUrl linkUrl = QUrl::fromLocalFile(srcLink);
+
+ job = new KIO::MimeTypeFinderJob(linkUrl, this);
+ QVERIFY2(job->exec(), qPrintable(job->errorString()));
+ QCOMPARE(job->mimeType(), mimeType);
}
void MimeTypeFinderJobTest::invalidUrl()
diff --git a/src/core/mimetypefinderjob.cpp b/src/core/mimetypefinderjob.cpp
index f5e50cdc..48fc8c28 100644
--- a/src/core/mimetypefinderjob.cpp
+++ b/src/core/mimetypefinderjob.cpp
@@ -122,7 +122,7 @@ void KIO::MimeTypeFinderJobPrivate::statFile()
{
Q_ASSERT(m_mimeTypeName.isEmpty());
- KIO::StatJob *job = KIO::statDetails(m_url, KIO::StatJob::SourceSide, KIO::StatBasic, KIO::HideProgressInfo);
+ KIO::StatJob *job = KIO::statDetails(m_url, KIO::StatJob::SourceSide, KIO::StatBasic | KIO::StatResolveSymlink, KIO::HideProgressInfo);
if (!m_authPrompts) {
job->addMetaData(QStringLiteral("no-auth-prompt"), QStringLiteral("true"));
}
--
2.25.1