diff --git a/src/libsyncengine/update_detection/update_detector/updatetreeworker.cpp b/src/libsyncengine/update_detection/update_detector/updatetreeworker.cpp index 8c38b42f2..eb436b754 100644 --- a/src/libsyncengine/update_detection/update_detector/updatetreeworker.cpp +++ b/src/libsyncengine/update_detection/update_detector/updatetreeworker.cpp @@ -506,8 +506,25 @@ ExitCode UpdateTreeWorker::step5CreateDirectory() { continue; } + if (createOp->path().empty()) { + LOG_SYNCPAL_WARN(_logger, "Invalid create operation on nodeId=" << createOp->nodeId().c_str()); + assert(false); + SentryHandler::instance()->captureMessage(SentryLevel::Warning, "UpdateTreeWorker::step5CreateDirectory", + "Invalid create operation"); + continue; + } + // find node by path because it may have been created before std::shared_ptr currentNode = getOrCreateNodeFromExistingPath(createOp->path()); + if (currentNode == nullptr) { + LOG_SYNCPAL_WARN(_logger, "Error in UpdateTreeWorker::getOrCreateNodeFromExistingPath"); + return ExitCode::DataError; + } else if (currentNode == _updateTree->rootNode()) { + LOG_SYNCPAL_WARN(_logger, "No operation allowed on the root node"); + assert(false); + return ExitCode::DataError; + } + if (currentNode->hasChangeEvent(OperationType::Delete)) { // A directory has been deleted and another one has been created with the same name currentNode->setPreviousId(currentNode->id()); @@ -978,6 +995,12 @@ ExitCode UpdateTreeWorker::createMoveNodes(const NodeType &nodeType) { bool UpdateTreeWorker::updateNodeId(std::shared_ptr node, const NodeId &newId) { const NodeId oldId = node->id().has_value() ? *node->id() : ""; + if (!node->parentNode()) { + LOG_SYNCPAL_WARN(_logger, "Bad parameters"); + assert(false); + return false; + } + node->parentNode()->deleteChildren(node); node->setId(newId);