summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2020-08-03 17:45:41 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2020-08-03 17:45:41 +0200
commite85dda296f425be323e058e232f83de6cbbca204 (patch)
treec0fc2250d0ea092dd6a5e8b703bdde844184dda2
parent095a77f1a13aa4024c4ceba9c9dfac4ad948d3c7 (diff)
Don't fail when creating root node as part of initial database creation.
-rw-r--r--src/nodetree.cc35
1 files 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;
}