From e22b64ced5242bb41aa3ce572da0a1c77ab2ee8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Kunz?= Date: Mon, 13 May 2024 16:36:25 +0200 Subject: [PATCH] KDESKTOP-823 - Fix SonarCloud issues again --- .../remotefilesystemobserverworker.cpp | 64 +++++++------------ .../remotefilesystemobserverworker.h | 2 +- .../snapshot/snapshot.cpp | 12 ++++ .../snapshot/snapshotitem.h | 8 +-- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp index 7a9727091..90515fa3c 100644 --- a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.cpp @@ -394,19 +394,16 @@ ExitCode RemoteFileSystemObserverWorker::getItemsInDir(const NodeId &dirId, cons auto nodeIdIt = nodeIds.begin(); while (nodeIdIt != nodeIds.end()) { if (_snapshot->isOrphan(*nodeIdIt)) { - LOG_SYNCPAL_DEBUG(_logger, - L"Node " << SyncName2WStr(_snapshot->name(*nodeIdIt)).c_str() - << L" (" << Utility::s2ws(*nodeIdIt).c_str() - << L") is orphan. Removing it from " - << Utility::s2ws(Utility::side2Str(_snapshot->side())).c_str() << L" snapshot."); + LOG_SYNCPAL_DEBUG(_logger, L"Node " << SyncName2WStr(_snapshot->name(*nodeIdIt)).c_str() << L" (" + << Utility::s2ws(*nodeIdIt).c_str() << L") is orphan. Removing it from " + << Utility::s2ws(Utility::side2Str(_snapshot->side())).c_str() << L" snapshot."); _snapshot->removeItem(*nodeIdIt); } nodeIdIt++; } std::chrono::duration elapsed_seconds = std::chrono::steady_clock::now() - start; - LOG_SYNCPAL_DEBUG(_logger, - "End reply parsing in " << elapsed_seconds.count() << "s for " << itemCount << " items"); + LOG_SYNCPAL_DEBUG(_logger, "End reply parsing in " << elapsed_seconds.count() << "s for " << itemCount << " items"); return ExitCodeOk; } @@ -485,7 +482,7 @@ ExitCode RemoteFileSystemObserverWorker::sendLongPoll(bool &changes) { ExitCode RemoteFileSystemObserverWorker::processActions(Poco::JSON::Array::Ptr actionArray) { if (!actionArray) return ExitCodeOk; - std::unordered_set movedItems; + std::set> movedItems; for (auto it = actionArray->begin(); it != actionArray->end(); ++it) { if (stopAsked()) { @@ -593,10 +590,10 @@ ExitCode RemoteFileSystemObserverWorker::extractActionInfo(const Poco::JSON::Obj return ExitCodeOk; } -ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, const ActionInfo &actionInfo - , std::unordered_set &movedItems) { - SnapshotItem item(actionInfo.nodeId, actionInfo.parentNodeId, usedName, actionInfo.createdAt, actionInfo.modtime - , actionInfo.type, actionInfo.size, actionInfo.canWrite); +ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, const ActionInfo &actionInfo, + std::set> &movedItems) { + SnapshotItem item(actionInfo.nodeId, actionInfo.parentNodeId, usedName, actionInfo.createdAt, actionInfo.modtime, + actionInfo.type, actionInfo.size, actionInfo.canWrite); // Process action switch (actionInfo.actionCode) { @@ -608,16 +605,15 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, case actionCodeAccessRightTeamInsert: case actionCodeAccessRightTeamUpdate: case actionCodeAccessRightMainUsersInsert: - case actionCodeAccessRightMainUsersUpdate: - { + case actionCodeAccessRightMainUsersUpdate: { bool hasRights = false; SyncTime createdAt = 0; SyncTime modtime = 0; int64_t size = 0; if (getFileInfo(actionInfo.nodeId, hasRights, createdAt, modtime, size) != ExitCodeOk) { LOGW_SYNCPAL_WARN(_logger, L"Error while determining access rights on item: " - << SyncName2WStr(actionInfo.name).c_str() << L" (" << Utility::s2ws(actionInfo.nodeId).c_str() - << L")"); + << SyncName2WStr(actionInfo.name).c_str() << L" (" + << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); invalidateSnapshot(); return ExitCodeBackError; } @@ -631,10 +627,8 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, case actionCodeMoveIn: case actionCodeRestore: case actionCodeCreate: - if (_snapshot->updateItem(item)) { - LOGW_SYNCPAL_INFO(_logger, L"File/directory updated: " << SyncName2WStr(usedName).c_str() << L" (" - << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); - } + _snapshot->updateItem(item); + if (actionInfo.type == NodeTypeDirectory && actionInfo.actionCode != ActionCode::actionCodeCreate) { // Retrieve all children ExitCode exitCode = exploreDirectory(actionInfo.nodeId); @@ -655,35 +649,27 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, // Item renamed case actionCodeRename: _syncPal->removeItemFromTmpBlacklist(actionInfo.nodeId, ReplicaSideRemote); - if (_snapshot->updateItem(item)) { - LOGW_SYNCPAL_INFO(_logger, L"File/directory: " << SyncName2WStr(actionInfo.name).c_str() << L" (" - << Utility::s2ws(actionInfo.nodeId).c_str() << L") renamed"); - } + _snapshot->updateItem(item); break; // Item edited case actionCodeEdit: - if (_snapshot->updateItem(item)) { - LOGW_SYNCPAL_INFO(_logger, L"File/directory: " << SyncName2WStr(actionInfo.name).c_str() << L" (" - << Utility::s2ws(actionInfo.nodeId).c_str() - << L") edited at:" << actionInfo.modtime); - } + _snapshot->updateItem(item); break; // Item removed case actionCodeAccessRightRemove: case actionCodeAccessRightUserRemove: case actionCodeAccessRightTeamRemove: - case actionCodeAccessRightMainUsersRemove: - { + case actionCodeAccessRightMainUsersRemove: { bool hasRights = false; SyncTime createdAt = 0; SyncTime modtime = 0; int64_t size = 0; if (getFileInfo(actionInfo.nodeId, hasRights, createdAt, modtime, size) != ExitCodeOk) { LOGW_SYNCPAL_WARN(_logger, L"Error while determining access rights on item: " - << SyncName2WStr(actionInfo.name).c_str() << L" (" << Utility::s2ws(actionInfo.nodeId).c_str() - << L")"); + << SyncName2WStr(actionInfo.name).c_str() << L" (" + << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); invalidateSnapshot(); return ExitCodeBackError; } @@ -696,12 +682,7 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, [[fallthrough]]; case actionCodeTrash: _syncPal->removeItemFromTmpBlacklist(actionInfo.nodeId, ReplicaSideRemote); - if (_snapshot->removeItem(actionInfo.nodeId)) { - if (ParametersCache::instance()->parameters().extendedLog()) { - LOGW_SYNCPAL_DEBUG(_logger, L"Item removed from remote snapshot: " << SyncName2WStr(actionInfo.name).c_str() << L" (" - << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); - } - } else { + if (!_snapshot->removeItem(actionInfo.nodeId)) { LOGW_SYNCPAL_WARN(_logger, L"Fail to remove item: " << SyncName2WStr(actionInfo.name).c_str() << L" (" << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); invalidateSnapshot(); @@ -721,7 +702,8 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, default: LOGW_SYNCPAL_DEBUG(_logger, L"Unknown operation received on file: " << SyncName2WStr(actionInfo.name).c_str() << L" (" - << Utility::s2ws(actionInfo.nodeId).c_str() << L")"); + << Utility::s2ws(actionInfo.nodeId).c_str() + << L")"); } @@ -729,7 +711,7 @@ ExitCode RemoteFileSystemObserverWorker::processAction(const SyncName &usedName, } ExitCode RemoteFileSystemObserverWorker::getFileInfo(const NodeId &nodeId, bool &hasRights, SyncTime &createdAt, - SyncTime &modtime, int64_t &size) { + SyncTime &modtime, int64_t &size) { GetFileInfoJob job(_syncPal->driveDbId(), nodeId); job.runSynchronously(); if (job.hasHttpError() || job.exitCode() != ExitCodeOk) { diff --git a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h index f36fce6bc..25fbde9a5 100644 --- a/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h +++ b/src/libsyncengine/update_detection/file_system_observer/remotefilesystemobserverworker.h @@ -60,7 +60,7 @@ class RemoteFileSystemObserverWorker : public FileSystemObserverWorker { }; ExitCode processActions(Poco::JSON::Array::Ptr filesArray); ExitCode extractActionInfo(const Poco::JSON::Object::Ptr actionObj, ActionInfo &actionInfo); - ExitCode processAction(const SyncName &usedName, const ActionInfo &actionInfo, std::unordered_set &movedItems); + ExitCode processAction(const SyncName &usedName, const ActionInfo &actionInfo, std::set> &movedItems); ExitCode getFileInfo(const NodeId &nodeId, bool &hasRights, SyncTime &createdAt, SyncTime &modtime, int64_t &size); diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp index 807d2a8a0..b3958c6ed 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshot.cpp @@ -18,6 +18,7 @@ #include "snapshot.h" #include "libcommonserver/log/log.h" +#include "requests/parameterscache.h" #include #include @@ -84,6 +85,12 @@ bool Snapshot::updateItem(const SnapshotItem &newItem) { startUpdate(); } + if (ParametersCache::instance()->parameters().extendedLog()) { + LOGW_DEBUG(Log::instance()->getLogger(), L"File/directory: " << SyncName2WStr(newItem.name()).c_str() << L" (" + << Utility::s2ws(newItem.id()).c_str() << L") updated at:" + << newItem.lastModified()); + } + return true; } @@ -113,6 +120,11 @@ bool Snapshot::removeItem(const NodeId &id) { } _items.erase(id); + + if (ParametersCache::instance()->parameters().extendedLog()) { + LOG_DEBUG(Log::instance()->getLogger(), "Item " << id.c_str() << "removed from remote snapshot."); + } + return true; } diff --git a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h index 1045cf488..a4018e95a 100644 --- a/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h +++ b/src/libsyncengine/update_detection/file_system_observer/snapshot/snapshotitem.h @@ -35,13 +35,13 @@ class SnapshotItem { bool canShare = true); SnapshotItem(const SnapshotItem &other); - inline NodeId id() const { return _id; } + inline const NodeId & id() const { return _id; } inline void setId(const NodeId &id) { _id = id; } - inline NodeId parentId() const { return _parentId; } + inline const NodeId & parentId() const { return _parentId; } inline void setParentId(const NodeId &newParentId) { _parentId = newParentId; } inline const std::unordered_set &childrenIds() const { return _childrenIds; } inline void setChildrenIds(const std::unordered_set &newChildrenIds) { _childrenIds = newChildrenIds; } - inline SyncName name() const { return _name; } + inline const SyncName & name() const { return _name; } inline void setName(const SyncName &newName) { _name = newName; } inline SyncTime createdAt() const { return _createdAt; } inline void setCreatedAt(SyncTime newCreatedAt) { _createdAt = newCreatedAt; } @@ -51,7 +51,7 @@ class SnapshotItem { inline void setType(NodeType type) { _type = type; } inline int64_t size() const { return _size; } inline void setSize(uint64_t newSize) { _size = newSize; } - inline std::string contentChecksum() const { return _contentChecksum; } + inline const std::string & contentChecksum() const { return _contentChecksum; } inline void setContentChecksum(const std::string &newChecksum) { _contentChecksum = newChecksum; } inline bool canWrite() const { return _canWrite; } inline void setCanWrite(bool canWrite) { _canWrite = canWrite; }