mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
xmlbuilder: Improve error report if we might unlink root node
This commit is contained in:
parent
d9e82f984c
commit
aba9d82bac
@ -188,7 +188,7 @@ def _build_xpath_node(ctx, xpath, addnode=None):
|
||||
return parentnode
|
||||
|
||||
|
||||
def _remove_xpath_node(ctx, xpath, dofree=True):
|
||||
def _remove_xpath_node(ctx, xpath, dofree=True, root_name=None):
|
||||
"""
|
||||
Remove an XML node tree if it has no content
|
||||
"""
|
||||
@ -219,6 +219,13 @@ def _remove_xpath_node(ctx, xpath, dofree=True):
|
||||
white.unlinkNode()
|
||||
white.freeNode()
|
||||
|
||||
# Don't unlink the root node. This is usually a programming error,
|
||||
# but the error usually cascades to a different spot and is hard
|
||||
# to pin down. With this we usually get invalid XML which is
|
||||
# easier to debug.
|
||||
if root_name and node.name == root_name:
|
||||
break
|
||||
|
||||
node.unlinkNode()
|
||||
if dofree:
|
||||
node.freeNode()
|
||||
@ -551,7 +558,8 @@ class XMLProperty(property):
|
||||
use_xpath = node.nodePath()
|
||||
|
||||
if val is None or val is False:
|
||||
_remove_xpath_node(root_node, use_xpath)
|
||||
_remove_xpath_node(root_node, use_xpath,
|
||||
root_name=root_node.name)
|
||||
continue
|
||||
|
||||
if not node:
|
||||
|
Loading…
Reference in New Issue
Block a user