mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virsh: virshMakeCloneXML: Use virXPathNode instead of xmlXPathEval
Refactor the code to use the XPath helpers instead of open-coding them. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
5f3d21abf8
commit
e9b7f06140
@ -505,28 +505,22 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
|
||||
return true;
|
||||
}
|
||||
|
||||
static xmlChar *
|
||||
static char *
|
||||
virshMakeCloneXML(const char *origxml, const char *newname)
|
||||
{
|
||||
g_autoptr(xmlDoc) doc = NULL;
|
||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||
g_autoptr(xmlXPathObject) obj = NULL;
|
||||
xmlChar *newxml = NULL;
|
||||
int size;
|
||||
xmlNodePtr node;
|
||||
|
||||
doc = virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt);
|
||||
if (!doc)
|
||||
if (!(doc = virXMLParseStringCtxt(origxml, _("(volume_definition)"), &ctxt)))
|
||||
return NULL;
|
||||
|
||||
obj = xmlXPathEval(BAD_CAST "/volume/name", ctxt);
|
||||
if (obj == NULL || obj->nodesetval == NULL ||
|
||||
obj->nodesetval->nodeTab == NULL)
|
||||
if (!(node = virXPathNode("/volume/name", ctxt)))
|
||||
return NULL;
|
||||
|
||||
xmlNodeSetContent(obj->nodesetval->nodeTab[0], (const xmlChar *)newname);
|
||||
xmlDocDumpMemory(doc, &newxml, &size);
|
||||
xmlNodeSetContent(node, (const xmlChar *)newname);
|
||||
|
||||
return newxml;
|
||||
return virXMLNodeToString(doc, doc->children);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -574,7 +568,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
|
||||
g_autoptr(virshStorageVol) newvol = NULL;
|
||||
const char *name = NULL;
|
||||
g_autofree char *origxml = NULL;
|
||||
g_autofree xmlChar *newxml = NULL;
|
||||
g_autofree char *newxml = NULL;
|
||||
unsigned int flags = 0;
|
||||
|
||||
if (!(origvol = virshCommandOptVol(ctl, cmd, "vol", "pool", NULL)))
|
||||
@ -608,8 +602,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml,
|
||||
origvol, flags))) {
|
||||
if (!(newvol = virStorageVolCreateXMLFrom(origpool, newxml, origvol, flags))) {
|
||||
vshError(ctl, _("Failed to clone vol from %s"),
|
||||
virStorageVolGetName(origvol));
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user