diff --git a/src/core/global.h b/src/core/global.h --- a/src/core/global.h +++ b/src/core/global.h @@ -245,7 +245,9 @@ ERR_DROP_ON_ITSELF = KJob::UserDefinedError + 70, ///< from KIO::DropJob, @since 5.6 ERR_CANNOT_MOVE_INTO_ITSELF = KJob::UserDefinedError + 71, ///< emitted by KIO::move, @since 5.18 ERR_PASSWD_SERVER = KJob::UserDefinedError + 72, ///< returned by SlaveBase::openPasswordDialogV2, @since 5.24 - ERR_CANNOT_CREATE_SLAVE = KJob::UserDefinedError + 73 ///< used by Slave::createSlave, @since 5.30 + ERR_CANNOT_CREATE_SLAVE = KJob::UserDefinedError + 73, ///< used by Slave::createSlave, @since 5.30 + + ERR_PRIVILEGE_NOT_REQUIRED = KJob::UserDefinedError + 74 ///< used by file ioslave, @since 5.50 }; /** diff --git a/src/core/job_error.cpp b/src/core/job_error.cpp --- a/src/core/job_error.cpp +++ b/src/core/job_error.cpp @@ -245,6 +245,9 @@ case KIO::ERR_CANNOT_CREATE_SLAVE: result = i18n("Unable to create io-slave. %1", errorText); break; + case KIO::ERR_PRIVILEGE_NOT_REQUIRED: + result = i18n("Privilege escalation is not necessary because \n'%1' is owned by the current user.\nPlease retry after changing permissions.", errorText); + break; default: result = i18n("Unknown error code %1\n%2\nPlease send a full bug report at http://bugs.kde.org.", errorCode, errorText); break; diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -851,6 +851,19 @@ return PrivilegeOperationReturnValue::failure(errcode); } + const QUrl targetUrl = QUrl::fromLocalFile(args.first().toString()); // target is always the first item. + const bool useParent = action != CHOWN && action != CHMOD && action != UTIME; + const QString targetPath = useParent ? targetUrl.adjusted(QUrl::RemoveFilename).toLocalFile() : targetUrl.toLocalFile(); + bool userIsOwner = QFileInfo(targetPath).ownerId() == getuid(); + if (action == RENAME) { // for rename check src and dest owner + QString dest = QUrl(args[1].toString()).toLocalFile(); + userIsOwner = userIsOwner && QFileInfo(dest).ownerId() == getuid(); + } + if (userIsOwner) { + error(KIO::ERR_PRIVILEGE_NOT_REQUIRED, targetPath); + return PrivilegeOperationReturnValue::canceled(); + } + QByteArray helperArgs; QDataStream out(&helperArgs, QIODevice::WriteOnly); out << action;