From e85dda296f425be323e058e232f83de6cbbca204 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 3 Aug 2020 17:45:41 +0200 Subject: Don't fail when creating root node as part of initial database creation. --- src/nodetree.cc | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/nodetree.cc b/src/nodetree.cc index f0877ff..f4baebb 100644 --- a/src/nodetree.cc +++ b/src/nodetree.cc @@ -111,11 +111,6 @@ NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id, { NodeIdList affectedNodes; - if(parentid == id) - { - throw Error::NewParentIsSelf(); // Node and new parent are the same node. - } - // Initialized? if(!root) { @@ -124,24 +119,28 @@ NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id, root = node; node->data = data; affectedNodes.push_back(id); + return affectedNodes; } - else + + if(parentid == id) { - if(!hasId(parentid)) - { - throw Error::MissingParent(); - } + throw Error::NewParentIsSelf(); // Node and new parent are the same node. + } - Node* parent = id2node.at(parentid); - Node* child = createNode(id); + if(!hasId(parentid)) + { + throw Error::MissingParent(); + } - child->data = data; - insertChild(parent, child, insertBeforeId); - affectedNodes.push_back(id); + Node* parent = id2node.at(parentid); + Node* child = createNode(id); - NodeIdList ancestors = ancestorList(id); - concatNodeIdLists(affectedNodes, ancestors); - } + child->data = data; + insertChild(parent, child, insertBeforeId); + affectedNodes.push_back(id); + + NodeIdList ancestors = ancestorList(id); + concatNodeIdLists(affectedNodes, ancestors); return affectedNodes; } -- cgit v1.2.3