Skip to content

Commit

Permalink
[KDESKTOP-1248] Fix crash in Node::deleteChildren caused by empty roo…
Browse files Browse the repository at this point in the history
…t node (#329)

* Fix crash

* Fix logging issue

* Fix logging issue

* Fix logging issue

* Address Luc's comments
  • Loading branch information
ChristopheLarchier authored Sep 30, 2024
1 parent a8adb2a commit 10474bb
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node> 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());
Expand Down Expand Up @@ -978,6 +995,12 @@ ExitCode UpdateTreeWorker::createMoveNodes(const NodeType &nodeType) {
bool UpdateTreeWorker::updateNodeId(std::shared_ptr<Node> 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);

Expand Down

0 comments on commit 10474bb

Please sign in to comment.