Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KDESKTOP-823-Emptying-the-trash-from-webapp-generate-a-lot-of-unneccessary-log #116

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions src/libsyncengine/jobs/network/getfileinfojob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,47 @@ GetFileInfoJob::GetFileInfoJob(int driveDbId, const NodeId &nodeId)
}

bool GetFileInfoJob::handleResponse(std::istream &is) {
if (!AbstractTokenNetworkJob::handleResponse(is)) {
if (!AbstractTokenNetworkJob::handleResponse(is)) return false;

if (!jsonRes()) return true;

Poco::JSON::Object::Ptr dataObj = jsonRes()->getObject(dataKey);
if (!dataObj) return true;

if (!JsonParserUtility::extractValue(dataObj, parentIdKey, _parentNodeId)) {
return false;
}
if (!JsonParserUtility::extractValue(dataObj, createdAtKey, _creationTime)) {
return false;
}
if (!JsonParserUtility::extractValue(dataObj, lastModifiedAtKey, _modtime)) {
return false;
}
std::string tmp;
if (!JsonParserUtility::extractValue(dataObj, typeKey, tmp)) {
return false;
}
bool isDir = tmp == dirKey;
ClementKunz marked this conversation as resolved.
Show resolved Hide resolved
if (!isDir) {
if (!JsonParserUtility::extractValue(dataObj, sizeKey, _size)) {
return false;
}
}

if (jsonRes()) {
Poco::JSON::Object::Ptr dataObj = jsonRes()->getObject(dataKey);
if (dataObj) {
if (!JsonParserUtility::extractValue(dataObj, parentIdKey, _parentNodeId)) {
return false;
}
if (!JsonParserUtility::extractValue(dataObj, createdAtKey, _creationTime)) {
return false;
}
if (!JsonParserUtility::extractValue(dataObj, lastModifiedAtKey, _modtime)) {
return false;
}

std::string symbolicLink;
if (JsonParserUtility::extractValue(dataObj, symbolicLinkKey, symbolicLink, false)) {
_isLink = !symbolicLink.empty();
}
std::string symbolicLink;
if (JsonParserUtility::extractValue(dataObj, symbolicLinkKey, symbolicLink, false)) {
_isLink = !symbolicLink.empty();
}

if (_withPath) {
std::string str;
if (!JsonParserUtility::extractValue(dataObj, pathKey, str)) {
return false;
}
if (Utility::startsWith(str, "/")) {
str.erase(0, 1);
}
_path = str;
}
if (_withPath) {
std::string str;
if (!JsonParserUtility::extractValue(dataObj, pathKey, str)) {
return false;
}
if (Utility::startsWith(str, "/")) {
str.erase(0, 1);
}
_path = str;
}

return true;
Expand Down
10 changes: 6 additions & 4 deletions src/libsyncengine/jobs/network/getfileinfojob.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class GetFileInfoJob : public AbstractTokenNetworkJob {
inline SyncTime creationTime() const { return _creationTime; }
inline SyncTime modtime() const { return _modtime; }
inline bool isLink() const { return _isLink; }
inline int64_t size() const { return _size; }

inline void setWithPath(bool val) { _withPath = val; }
inline SyncPath path() const { return _path; }
Expand All @@ -49,10 +50,11 @@ class GetFileInfoJob : public AbstractTokenNetworkJob {
NodeId _nodeId;
NodeId _parentNodeId;
std::string _name;
SyncTime _creationTime = 0;
SyncTime _modtime = 0;
bool _isLink = false;
bool _withPath = false;
SyncTime _creationTime {0};
SyncTime _modtime {0};
bool _isLink {false};
bool _withPath {false};
int64_t _size {-1};
SyncPath _path;
};

Expand Down
48 changes: 47 additions & 1 deletion src/libsyncengine/jobs/network/networkjobsparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,53 @@
#include "networkjobsparams.h"

#include <map>
#include <unordered_map>

namespace KDC {

struct StringHash {
using is_transparent = void; // Enables heterogeneous operations.

std::size_t operator()(std::string_view sv) const {
std::hash<std::string_view> hasher;
return hasher(sv);
}
};

ActionCode getActionCode(const std::string &action) noexcept {
static const std::unordered_map<std::string, ActionCode, StringHash, std::equal_to<>> actionMap = {
{"file_create", ActionCode::actionCodeCreate},
{"file_rename", ActionCode::actionCodeRename},
{"file_update", ActionCode::actionCodeEdit},
{"file_access", ActionCode::actionCodeAccess},
{"file_trash", ActionCode::actionCodeTrash},
{"file_delete", ActionCode::actionCodeDelete},
{"file_move", ActionCode::actionCodeMoveIn},
{"file_move_out", ActionCode::actionCodeMoveOut},
{"file_restore", ActionCode::actionCodeRestore},
{"file_share_create", ActionCode::actionCodeRestoreFileShareCreate},
{"file_share_delete", ActionCode::actionCodeRestoreFileShareDelete},
{"share_link_create", ActionCode::actionCodeRestoreShareLinkCreate},
{"share_link_delete", ActionCode::actionCodeRestoreShareLinkDelete},
{"acl_insert", ActionCode::actionCodeAccessRightInsert},
{"acl_update", ActionCode::actionCodeAccessRightUpdate},
{"acl_remove", ActionCode::actionCodeAccessRightRemove},
{"acl_user_insert", ActionCode::actionCodeAccessRightUserInsert},
{"acl_user_update", ActionCode::actionCodeAccessRightUserUpdate},
{"acl_user_remove", ActionCode::actionCodeAccessRightUserRemove},
{"acl_team_insert", ActionCode::actionCodeAccessRightTeamInsert},
{"acl_team_update", ActionCode::actionCodeAccessRightTeamUpdate},
{"acl_team_remove", ActionCode::actionCodeAccessRightTeamRemove},
{"acl_main_users_insert", ActionCode::actionCodeAccessRightMainUsersInsert},
{"acl_main_users_update", ActionCode::actionCodeAccessRightMainUsersUpdate},
{"acl_main_users_remove", ActionCode::actionCodeAccessRightMainUsersRemove}
};

if (const auto it = actionMap.find(action); it != actionMap.cend()) return it->second;

return ActionCode::actionCodeUnknown;
};

NetworkErrorCode getNetworkErrorCode(const std::string &errorCode) noexcept {
static const std::map<std::string, NetworkErrorCode, std::less<std::string>> errorCodeMap = {
{"forbidden_error", NetworkErrorCode::forbiddenError},
Expand Down Expand Up @@ -50,5 +95,6 @@ NetworkErrorReason getNetworkErrorReason(const std::string &errorReason) noexcep
if (const auto it = errorReasonMap.find(errorReason); it != errorReasonMap.cend()) return it->second;

return NetworkErrorReason::unknownReason;
};
}

} // namespace KDC
59 changes: 30 additions & 29 deletions src/libsyncengine/jobs/network/networkjobsparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static const uint64_t chunkMinSize = 10 * 1024 * 1024; // 10MB
static const uint64_t chunkMaxSize = 100 * 1024 * 1024; // 100MB
static const uint64_t useUploadSessionThreshold = 100 * 1024 * 1024; // if file size > 100MB -> start upload session
static const uint64_t optimalTotalChunks = 200;
static const uint64_t maxTotalChunks = 10000; // Theorical max. file size 10'000 * 100MB = 1TB
static const uint64_t maxTotalChunks = 10000; // Theoretical max. file size 10'000 * 100MB = 1TB

/*
* Static string
Expand Down Expand Up @@ -118,33 +118,34 @@ static const std::string urlKey = "url";
static const std::string symbolicLinkKey = "symbolic_link";

/// Action type
static const std::string createAction = "file_create";
static const std::string renameAction = "file_rename";
static const std::string editAction = "file_update";
static const std::string accessAction = "file_access";
static const std::string trashAction = "file_trash";
static const std::string deleteAction = "file_delete";
static const std::string moveInAction = "file_move";
static const std::string moveOutAction = "file_move_out";
static const std::string restoreAction = "file_restore";
static const std::string restoreFileShareCreate = "file_share_create";
static const std::string restoreFileShareDelete = "file_share_delete";
static const std::string restoreShareLinkCreate = "share_link_create";
static const std::string restoreShareLinkDelete = "share_link_delete";
//// Rights
/// TODO : implement all rights
static const std::string accessRightInsert = "acl_insert";
static const std::string accessRightUpdate = "acl_update";
static const std::string accessRightRemove = "acl_remove";
static const std::string accessRightUserInsert = "acl_user_insert";
static const std::string accessRightUserUpdate = "acl_user_update";
static const std::string accessRightUserRemove = "acl_user_remove";
static const std::string accessRightTeamInsert = "acl_team_insert";
static const std::string accessRightTeamUpdate = "acl_team_update";
static const std::string accessRightTeamRemove = "acl_team_remove";
static const std::string accessRightMainUsersInsert = "acl_main_users_insert";
static const std::string accessRightMainUsersUpdate = "acl_main_users_update";
static const std::string accessRightMainUsersRemove = "acl_main_users_remove";
enum class ActionCode {
actionCodeCreate,
actionCodeRename,
actionCodeEdit,
actionCodeAccess,
actionCodeTrash, // The file has been put into the trash
actionCodeDelete, // The file has been completely deleted from the trash
actionCodeMoveIn,
actionCodeMoveOut,
actionCodeRestore,
actionCodeRestoreFileShareCreate,
actionCodeRestoreFileShareDelete,
actionCodeRestoreShareLinkCreate,
actionCodeRestoreShareLinkDelete,
actionCodeAccessRightInsert,
actionCodeAccessRightUpdate,
actionCodeAccessRightRemove,
actionCodeAccessRightUserInsert,
actionCodeAccessRightUserUpdate,
actionCodeAccessRightUserRemove,
actionCodeAccessRightTeamInsert,
actionCodeAccessRightTeamUpdate,
actionCodeAccessRightTeamRemove,
actionCodeAccessRightMainUsersInsert,
actionCodeAccessRightMainUsersUpdate,
actionCodeAccessRightMainUsersRemove,
actionCodeUnknown
};

/// Visibility
static const std::string isRootKey = "is_root";
Expand All @@ -160,7 +161,6 @@ static const std::string codeKey = "code";
static const std::string descriptionKey = "description";
static const std::string contextKey = "context";
/// Error codes

enum class NetworkErrorCode {
forbiddenError,
notAuthorized,
Expand All @@ -186,6 +186,7 @@ enum class NetworkErrorReason {
unknownReason // None of the handled reasons
};

ActionCode getActionCode(const std::string &action) noexcept;
NetworkErrorCode getNetworkErrorCode(const std::string &errorCode) noexcept;
NetworkErrorReason getNetworkErrorReason(const std::string &errorCode) noexcept;

Expand Down
2 changes: 1 addition & 1 deletion src/libsyncengine/syncpal/operationprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool OperationProcessor::isPseudoConflict(std::shared_ptr<Node> node, std::share

bool useContentChecksum =
!snapshot->contentChecksum(*node->id()).empty() && !otherSnapshot->contentChecksum(*correspondingNode->id()).empty();
bool sameSizeAndDate = snapshot->lastModifed(*node->id()) == otherSnapshot->lastModifed(*correspondingNode->id()) &&
bool sameSizeAndDate = snapshot->lastModified(*node->id()) == otherSnapshot->lastModified(*correspondingNode->id()) &&
snapshot->size(*node->id()) == otherSnapshot->size(*correspondingNode->id());
if (node->type() == NodeType::NodeTypeFile && correspondingNode->type() == node->type() &&
node->hasChangeEvent((OperationTypeCreate | OperationTypeEdit)) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ ExitCode ComputeFSOperationWorker::exploreDbTree(std::unordered_set<NodeId> &loc
}
}

const SyncTime snapshotLastModified = snapshot->lastModifed(nodeId);
const SyncTime snapshotLastModified = snapshot->lastModified(nodeId);
if (snapshotLastModified != dbLastModified && dbNode.type() == NodeType::NodeTypeFile) {
// Edit operation
FSOpPtr fsOp = std::make_shared<FSOperation>(OperationType::OperationTypeEdit, nodeId, NodeType::NodeTypeFile,
Expand Down Expand Up @@ -454,7 +454,7 @@ ExitCode ComputeFSOperationWorker::exploreSnapshotTree(ReplicaSide side, const s

NodeType type = snapshot->type(*snapIdIt);
if (checkOnlyDir && type != NodeTypeDirectory) {
// In first loop, we check only directory
// In first loop, we check only directories
snapIdIt++;
continue;
}
Expand All @@ -466,7 +466,7 @@ ExitCode ComputeFSOperationWorker::exploreSnapshotTree(ReplicaSide side, const s
if (snapshot->isOrphan(snapshot->parentId(nodeId))) {
// Ignore orphans
if (ParametersCache::instance()->parameters().extendedLog()) {
LOGW_SYNCPAL_DEBUG(_logger, L"Ignoring ophan node " << SyncName2WStr(snapshot->name(nodeId)).c_str() << L" ("
LOGW_SYNCPAL_DEBUG(_logger, L"Ignoring orphan node " << SyncName2WStr(snapshot->name(nodeId)).c_str() << L" ("
<< Utility::s2ws(nodeId).c_str() << L")");
}
continue;
Expand Down Expand Up @@ -510,7 +510,7 @@ ExitCode ComputeFSOperationWorker::exploreSnapshotTree(ReplicaSide side, const s
// Create operation
FSOpPtr fsOp =
std::make_shared<FSOperation>(OperationType::OperationTypeCreate, nodeId, type, snapshot->createdAt(nodeId),
snapshot->lastModifed(nodeId), snapshotSize, snapPath);
snapshot->lastModified(nodeId), snapshotSize, snapPath);
opSet->insertOp(fsOp);
logOperationGeneration(snapshot->side(), fsOp);
}
Expand Down Expand Up @@ -562,8 +562,8 @@ ExitCode ComputeFSOperationWorker::checkFileIntegrity(const DbNode &dbNode) {

int64_t localSnapshotSize = _syncPal->_localSnapshot->size(dbNode.nodeIdLocal().value());
int64_t remoteSnapshotSize = _syncPal->_remoteSnapshot->size(dbNode.nodeIdRemote().value());
SyncTime localSnapshotLastModified = _syncPal->_localSnapshot->lastModifed(dbNode.nodeIdLocal().value());
SyncTime remoteSnapshotLastModified = _syncPal->_remoteSnapshot->lastModifed(dbNode.nodeIdRemote().value());
SyncTime localSnapshotLastModified = _syncPal->_localSnapshot->lastModified(dbNode.nodeIdLocal().value());
SyncTime remoteSnapshotLastModified = _syncPal->_remoteSnapshot->lastModified(dbNode.nodeIdRemote().value());

// A mismatch is detected if all timestamps are equal but the sizes in snapshots differ.
if (localSnapshotSize != remoteSnapshotSize && localSnapshotLastModified == dbNode.lastModifiedLocal().value() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void LocalFileSystemObserverWorker::changesDetected(const std::list<std::pair<st
bool changed = false;
IoError ioError = IoErrorSuccess;
const bool success = IoHelper::checkIfFileChanged(absolutePath, _snapshot->size(nodeId),
_snapshot->lastModifed(nodeId), changed, ioError);
_snapshot->lastModified(nodeId), changed, ioError);
if (!success) {
LOGW_SYNCPAL_WARN(
_logger, L"Error in IoHelper::checkIfFileChanged: " << Utility::formatIoError(absolutePath, ioError).c_str());
Expand Down Expand Up @@ -344,7 +344,7 @@ void LocalFileSystemObserverWorker::changesDetected(const std::list<std::pair<st
continue;
}

if (fileStat.modtime > _snapshot->lastModifed(nodeId)) {
if (fileStat.modtime > _snapshot->lastModified(nodeId)) {
// This is an edit operation
#ifdef __APPLE__
if (_syncPal->_vfsMode == VirtualFileModeMac) {
Expand Down
Loading
Loading