提交 e14cdeb4 编写于 作者: L Luyao Huang 提交者: John Ferlan

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: NLuyao Huang <lhuang@redhat.com>
上级 733950c2
...@@ -1040,31 +1040,42 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -1040,31 +1040,42 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
int int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{ {
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
const char *type = virSysinfoTypeToString(def->type); const char *type = virSysinfoTypeToString(def->type);
int indent = virBufferGetIndent(buf, false);
int ret = -1;
if (!type) { if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sysinfo type model %d"), _("unexpected sysinfo type model %d"),
def->type); def->type);
virBufferFreeAndReset(buf); virBufferFreeAndReset(buf);
return -1; goto cleanup;
} }
virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type); virBufferAdjustIndent(&childrenBuf, indent + 2);
virBufferAdjustIndent(buf, 2);
virSysinfoBIOSFormat(buf, def); virSysinfoBIOSFormat(&childrenBuf, def);
virSysinfoSystemFormat(buf, def); virSysinfoSystemFormat(&childrenBuf, def);
virSysinfoProcessorFormat(buf, def); virSysinfoProcessorFormat(&childrenBuf, def);
virSysinfoMemoryFormat(buf, def); virSysinfoMemoryFormat(&childrenBuf, def);
virBufferAdjustIndent(buf, -2); virBufferAsprintf(buf, "<sysinfo type='%s'", type);
virBufferAddLit(buf, "</sysinfo>\n"); if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childrenBuf);
virBufferAddLit(buf, "</sysinfo>\n");
} else {
virBufferAddLit(buf, "/>\n");
}
if (virBufferCheckError(buf) < 0) if (virBufferCheckError(buf) < 0)
return -1; goto cleanup;
return 0; ret = 0;
cleanup:
virBufferFreeAndReset(&childrenBuf);
return ret;
} }
bool virSysinfoIsEqual(virSysinfoDefPtr src, bool virSysinfoIsEqual(virSysinfoDefPtr src,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册