mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
util: improve the sysinfo element XML format
If the <sysinfo type='smbios'...> ends up not formatting any sub-elements, then rather than formatting as: <sysinfo type='smbios'> </sysinfo> Just format it more cleanly as: <sysinfo type='smbios'/> Signed-off-by: Luyao Huang <lhuang@redhat.com>
This commit is contained in:
parent
733950c21c
commit
e14cdeb44f
@ -1040,31 +1040,42 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||
int
|
||||
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||
{
|
||||
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
|
||||
const char *type = virSysinfoTypeToString(def->type);
|
||||
int indent = virBufferGetIndent(buf, false);
|
||||
int ret = -1;
|
||||
|
||||
if (!type) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected sysinfo type model %d"),
|
||||
def->type);
|
||||
virBufferFreeAndReset(buf);
|
||||
return -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
virBufferAdjustIndent(&childrenBuf, indent + 2);
|
||||
|
||||
virSysinfoBIOSFormat(buf, def);
|
||||
virSysinfoSystemFormat(buf, def);
|
||||
virSysinfoProcessorFormat(buf, def);
|
||||
virSysinfoMemoryFormat(buf, def);
|
||||
virSysinfoBIOSFormat(&childrenBuf, def);
|
||||
virSysinfoSystemFormat(&childrenBuf, def);
|
||||
virSysinfoProcessorFormat(&childrenBuf, def);
|
||||
virSysinfoMemoryFormat(&childrenBuf, def);
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</sysinfo>\n");
|
||||
virBufferAsprintf(buf, "<sysinfo type='%s'", type);
|
||||
if (virBufferUse(&childrenBuf)) {
|
||||
virBufferAddLit(buf, ">\n");
|
||||
virBufferAddBuffer(buf, &childrenBuf);
|
||||
virBufferAddLit(buf, "</sysinfo>\n");
|
||||
} else {
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
|
||||
if (virBufferCheckError(buf) < 0)
|
||||
return -1;
|
||||
goto cleanup;
|
||||
|
||||
return 0;
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virBufferFreeAndReset(&childrenBuf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool virSysinfoIsEqual(virSysinfoDefPtr src,
|
||||
|
Loading…
x
Reference in New Issue
Block a user