kio/CopyJob-Check-if-destination-dir-is-a-symlink.patch
Luca Beltrame d320b8b2e8 Accepting request 805891 from home:wolfi323:test
- Add Fix-service-file-specifying-Run-in-terminal-giving-error.patch
  to fix starting services that use "Run in terminal" (kde#421374)
- Add CopyJob-Check-if-destination-dir-is-a-symlink.patch to fix
  copying files to symlinked folders (kde#421213)

OBS-URL: https://build.opensuse.org/request/show/805891
OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks5/kio?expand=0&rev=294
2020-05-15 21:52:33 +00:00

96 lines
3.5 KiB
Diff

From 8769b6360d87c1b688eac4d0ce97594351bad13c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A9ven=20Car?= <meven29@gmail.com>
Date: Fri, 15 May 2020 12:44:35 +0200
Subject: CopyJob: Check if destination dir is a symlink
Summary:
BUG: 421213
FIXED-IN: 5.71
Test Plan: ctest
Reviewers: #frameworks, dfaure, ngraham
Reviewed By: dfaure
Subscribers: kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D29767
---
autotests/jobtest.cpp | 30 ++++++++++++++++++++++++++++++
autotests/jobtest.h | 1 +
src/core/copyjob.cpp | 2 +-
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/autotests/jobtest.cpp b/autotests/jobtest.cpp
index 5d5117a..0602319 100644
--- a/autotests/jobtest.cpp
+++ b/autotests/jobtest.cpp
@@ -619,6 +619,36 @@ void JobTest::copyDirectoryToExistingDirectory()
copyLocalDirectory(src, dest, AlreadyExists);
}
+void JobTest::copyDirectoryToExistingSymlinkedDirectory()
+{
+ // qDebug();
+ // just the same as copyDirectoryToSamePartition, but this time dest is a symlink.
+ // So we get a file in the symlink dir, "dirFromHome_symlink/dirFromHome" and
+ // "dirFromHome_symOrigin/dirFromHome"
+ const QString src = homeTmpDir() + "dirFromHome";
+ const QString origSymlink = homeTmpDir() + "dirFromHome_symOrigin";
+ const QString targetSymlink = homeTmpDir() + "dirFromHome_symlink";
+ createTestDirectory(src);
+ createTestDirectory(origSymlink);
+
+ bool ok = KIOPrivate::createSymlink(origSymlink, targetSymlink);
+ if (!ok) {
+ qFatal("couldn't create symlink: %s", strerror(errno));
+ }
+ QVERIFY(QFileInfo(targetSymlink).isSymLink());
+ QVERIFY(QFileInfo(targetSymlink).isDir());
+
+ KIO::Job *job = KIO::copy(QUrl::fromLocalFile(src), QUrl::fromLocalFile(targetSymlink), KIO::HideProgressInfo);
+ job->setUiDelegate(nullptr);
+ job->setUiDelegateExtension(nullptr);
+ QVERIFY2(job->exec(), qPrintable(job->errorString()));
+ QVERIFY(QFile::exists(src)); // still there
+
+ // file is visible in both places due to symlink
+ QVERIFY(QFileInfo(origSymlink + "/dirFromHome").isDir());;
+ QVERIFY(QFileInfo(targetSymlink + "/dirFromHome").isDir());
+}
+
void JobTest::copyFileToOtherPartition()
{
// qDebug();
diff --git a/autotests/jobtest.h b/autotests/jobtest.h
index d8ac33f..9ebb2ad 100644
--- a/autotests/jobtest.h
+++ b/autotests/jobtest.h
@@ -49,6 +49,7 @@ private Q_SLOTS:
void copyFileToSamePartition();
void copyDirectoryToSamePartition();
void copyDirectoryToExistingDirectory();
+ void copyDirectoryToExistingSymlinkedDirectory();
void copyFileToOtherPartition();
void copyDirectoryToOtherPartition();
void copyRelativeSymlinkToSamePartition();
diff --git a/src/core/copyjob.cpp b/src/core/copyjob.cpp
index 06e0612..ec15543 100644
--- a/src/core/copyjob.cpp
+++ b/src/core/copyjob.cpp
@@ -366,7 +366,7 @@ void CopyJobPrivate::slotStart()
state = STATE_STATING;
const QUrl dest = m_asMethod ? m_dest.adjusted(QUrl::RemoveFilename) : m_dest;
// We need isDir() and UDS_LOCAL_PATH (for slaves who set it). Let's assume the latter is part of StatBasic too.
- KIO::Job *job = KIO::statDetails(dest, StatJob::DestinationSide, KIO::StatBasic, KIO::HideProgressInfo);
+ KIO::Job *job = KIO::statDetails(dest, StatJob::DestinationSide, KIO::StatBasic | KIO::StatResolveSymlink, KIO::HideProgressInfo);
qCDebug(KIO_COPYJOB_DEBUG) << "CopyJob: stating the dest" << dest;
q->addSubjob(job);
}
--
cgit v1.1