From 9ac7832b859bfcbc88448c4ae0f6dc14b2d54a06 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 15 Aug 2017 14:41:36 +0200 Subject: [File KIO slave] Fix applying special file attributes QFile does not support special attributes like sticky. This would cause us to always discard them. BUG: 365795 Differential Revision: https://phabricator.kde.org/D7326 --- autotests/jobtest.cpp | 20 ++++++++++++++++++++ autotests/jobtest.h | 3 +++ src/ioslaves/file/file.cpp | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/autotests/jobtest.cpp b/autotests/jobtest.cpp index 80a8921..557d1b5 100644 --- a/autotests/jobtest.cpp +++ b/autotests/jobtest.cpp @@ -1473,6 +1473,26 @@ void JobTest::chmodFile() QFile::remove(filePath); } +#ifdef Q_OS_UNIX +void JobTest::chmodSticky() +{ + const QString filePath = homeTmpDir() + "fileForChmodSticky"; + createTestFile(filePath); + KFileItem item(QUrl::fromLocalFile(filePath)); + const mode_t origPerm = item.permissions(); + mode_t newPerm = origPerm ^ S_ISVTX; + QVERIFY(newPerm != origPerm); + KFileItemList items({item}); + KIO::Job *job = KIO::chmod(items, newPerm, S_ISVTX, QString(), QString(), false, KIO::HideProgressInfo); + job->setUiDelegate(nullptr); + QVERIFY(job->exec()); + + KFileItem newItem(QUrl::fromLocalFile(filePath)); + QCOMPARE(QString::number(newItem.permissions(), 8), QString::number(newPerm, 8)); + QFile::remove(filePath); +} +#endif + void JobTest::chmodFileError() { // chown(root) should fail diff --git a/autotests/jobtest.h b/autotests/jobtest.h index 96b4264..e3d800a 100644 --- a/autotests/jobtest.h +++ b/autotests/jobtest.h @@ -84,6 +84,9 @@ private Q_SLOTS: #endif void mostLocalUrl(); void chmodFile(); +#ifdef Q_OS_UNIX + void chmodSticky(); +#endif void chmodFileError(); void mimeType(); void mimeTypeError(); diff --git a/src/ioslaves/file/file.cpp b/src/ioslaves/file/file.cpp index 47fb0a5..a7f1a47 100644 --- a/src/ioslaves/file/file.cpp +++ b/src/ioslaves/file/file.cpp @@ -225,7 +225,12 @@ void FileProtocol::chmod(const QUrl &url, int permissions) const QString path(url.toLocalFile()); const QByteArray _path(QFile::encodeName(path)); /* FIXME: Should be atomic */ +#ifdef Q_OS_UNIX + // QFile::Permissions does not support special attributes like sticky + if (::chmod(QFile::encodeName(path).constData(), permissions) == -1 || +#else if (!QFile::setPermissions(path, modeToQFilePermissions(permissions)) || +#endif (setACL(_path.data(), permissions, false) == -1) || /* if not a directory, cannot set default ACLs */ (setACL(_path.data(), permissions, true) == -1 && errno != ENOTDIR)) { -- cgit v0.11.2