Skip to content

Commit

Permalink
KDESKTOP-823 - Fix SonarCloud issues again
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementKunz committed May 13, 2024
1 parent 8f7fe08 commit e22b64c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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;
}
Expand Down Expand Up @@ -485,7 +482,7 @@ ExitCode RemoteFileSystemObserverWorker::sendLongPoll(bool &changes) {
ExitCode RemoteFileSystemObserverWorker::processActions(Poco::JSON::Array::Ptr actionArray) {
if (!actionArray) return ExitCodeOk;

std::unordered_set<NodeId> movedItems;
std::set<NodeId, std::equal_to<>> movedItems;

for (auto it = actionArray->begin(); it != actionArray->end(); ++it) {
if (stopAsked()) {
Expand Down Expand Up @@ -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<NodeId> &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<NodeId, std::equal_to<>> &movedItems) {
SnapshotItem item(actionInfo.nodeId, actionInfo.parentNodeId, usedName, actionInfo.createdAt, actionInfo.modtime,
actionInfo.type, actionInfo.size, actionInfo.canWrite);

// Process action
switch (actionInfo.actionCode) {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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();
Expand All @@ -721,15 +702,16 @@ 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")");
}


return ExitCodeOk;
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeId> &movedItems);
ExitCode processAction(const SyncName &usedName, const ActionInfo &actionInfo, std::set<NodeId, std::equal_to<>> &movedItems);

ExitCode getFileInfo(const NodeId &nodeId, bool &hasRights, SyncTime &createdAt, SyncTime &modtime, int64_t &size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "snapshot.h"
#include "libcommonserver/log/log.h"
#include "requests/parameterscache.h"

#include <filesystem>
#include <queue>
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeId> &childrenIds() const { return _childrenIds; }
inline void setChildrenIds(const std::unordered_set<NodeId> &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; }
Expand All @@ -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; }
Expand Down

0 comments on commit e22b64c

Please sign in to comment.