From 5bb90c783e8a87b932bdfbae0aaff8571aa9e627 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 21 Aug 2024 15:48:47 +0200 Subject: [PATCH 1/3] ensure the arguments of socket API commands are valid fix string data being invalid when using QStringView Signed-off-by: Matthieu Gallien --- src/gui/socketapi/socketapi.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index a3f306fb71cd5..a3c0186e3ad5f 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -403,9 +403,9 @@ void SocketApi::slotReadSocket() return out; }(); - const auto argument = argPos != -1 ? line.mid(argPos + 1) : QStringView(); + const auto argument = QString{argPos != -1 ? line.mid(argPos + 1) : QString()}; if (command.startsWith("ASYNC_")) { - auto arguments = argument.split('|'); + const auto arguments = argument.split('|'); if (arguments.size() != 2) { listener->sendError(QStringLiteral("argument count is wrong")); return; @@ -416,7 +416,7 @@ void SocketApi::slotReadSocket() auto jobId = arguments[0]; auto socketApiJob = QSharedPointer( - new SocketApiJob(jobId.toString(), listener, json), &QObject::deleteLater); + new SocketApiJob(jobId, listener, json), &QObject::deleteLater); if (indexOfMethod != -1) { staticMetaObject.method(indexOfMethod) .invoke(this, Qt::QueuedConnection, @@ -430,7 +430,7 @@ void SocketApi::slotReadSocket() QJsonParseError error{}; const auto json = QJsonDocument::fromJson(argument.toUtf8(), &error).object(); if (error.error != QJsonParseError::NoError) { - qCWarning(lcSocketApi()) << "Invalid json" << argument.toString() << error.errorString(); + qCWarning(lcSocketApi()) << "Invalid json" << argument << error.errorString(); listener->sendError(error.errorString()); return; } @@ -448,7 +448,7 @@ void SocketApi::slotReadSocket() if (indexOfMethod != -1) { ASSERT(thread() == QThread::currentThread()) staticMetaObject.method(indexOfMethod) - .invoke(this, Qt::QueuedConnection, Q_ARG(QString, argument.toString()), + .invoke(this, Qt::QueuedConnection, Q_ARG(QString, argument), Q_ARG(SocketListener *, listener.data())); } } else { @@ -456,7 +456,7 @@ void SocketApi::slotReadSocket() // to ensure that listener is still valid we need to call it with Qt::DirectConnection ASSERT(thread() == QThread::currentThread()) staticMetaObject.method(indexOfMethod) - .invoke(this, Qt::DirectConnection, Q_ARG(QString, argument.toString()), + .invoke(this, Qt::DirectConnection, Q_ARG(QString, argument), Q_ARG(SocketListener *, listener.data())); } } From 1c3743d67005ba6e30557e8231f7ee5b2c16e497 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 21 Aug 2024 15:50:04 +0200 Subject: [PATCH 2/3] only add encrypt menu entry for top folders with current end-to-end encryption only top folders can be encrypted limit the availability of the menu entry to top folders Signed-off-by: Matthieu Gallien --- src/gui/socketapi/socketapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index a3c0186e3ad5f..5b7206713e674 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1257,7 +1257,7 @@ void SocketApi::sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo, ancestor = ancestor.parentFolder(); } - if (!anyAncestorEncrypted) { + if (!anyAncestorEncrypted && !fileData.parentFolder().journalRecord().isValid()) { const auto isOnTheServer = fileData.journalRecord().isValid(); const auto flagString = isOnTheServer ? QLatin1String("::") : QLatin1String(":d:"); listener->sendMessage(QStringLiteral("MENU_ITEM:ENCRYPT") + flagString + tr("Encrypt")); From 539be0a16a8ebc1996e43891c60ba76bd17c1bea Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 21 Aug 2024 17:41:35 +0200 Subject: [PATCH 3/3] only empty top folders offer the menu entry to encrypt in the contextual menu shown in files explorer will show encrypt menu entry only for top folders that are non-encrypted and empty Signed-off-by: Matthieu Gallien --- src/gui/socketapi/socketapi.cpp | 12 +++++++++++- src/gui/socketapi/socketapi.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 5b7206713e674..81d98040596fb 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1242,7 +1242,8 @@ void SocketApi::sendEncryptFolderCommandMenuEntries(const QFileInfo &fileInfo, !fileData.folder->accountState()->account() || !fileData.folder->accountState()->account()->capabilities().clientSideEncryptionAvailable() || !FileSystem::isDir(fileInfo.absoluteFilePath()) || - isE2eEncryptedPath) { + isE2eEncryptedPath || + !fileData.isFolderEmpty()) { return; } @@ -1328,6 +1329,15 @@ QString SocketApi::FileData::folderRelativePathNoVfsSuffix() const return result; } +bool SocketApi::FileData::isFolderEmpty() const +{ + if (FileSystem::isDir(localPath)) { + const auto nativeFolder = QDir{localPath}; + return nativeFolder.isEmpty(); + } + return false; +} + SyncFileStatus SocketApi::FileData::syncFileStatus() const { if (!folder) diff --git a/src/gui/socketapi/socketapi.h b/src/gui/socketapi/socketapi.h index 7f25772cd9e3c..bf95d780cd821 100644 --- a/src/gui/socketapi/socketapi.h +++ b/src/gui/socketapi/socketapi.h @@ -98,6 +98,8 @@ private slots: // Relative path of the file locally, without any vfs suffix [[nodiscard]] QString folderRelativePathNoVfsSuffix() const; + [[nodiscard]] bool isFolderEmpty() const; + Folder *folder = nullptr; // Absolute path of the file locally. (May be a virtual file) QString localPath;