From 397ab17211a8b61d4cf8d6f82dc7be7f1ea90ddf Mon Sep 17 00:00:00 2001 From: David Hampton Date: Mon, 25 Dec 2006 20:18:36 +0000 Subject: [PATCH] Protect against setting an existing tree node as the new root of the tree. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/remove-group2@15257 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/engine/Account.c b/src/engine/Account.c index e7e0d5262f..8e08c82d86 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -168,6 +168,15 @@ gnc_coll_set_root_account (QofCollection *col, Account *root) old_root = gnc_coll_get_root_account (col); if (old_root == root) return; + /* If the new root is already linked into the tree somewhere, then + * remove it from its current position before adding it at the + * top. */ + if (root->parent) { + xaccAccountBeginEdit(root); + gnc_account_remove_child(root->parent, root); + xaccAccountCommitEdit(root); + } + qof_collection_set_data (col, root); if (old_root) {