mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
Use a separate buffer for <input> subelements
Instead of figuring out upfront whether <input> will be a single or a pair element, format the subelements into a separate buffer and close <input/> early if this buffer is empty.
This commit is contained in:
parent
a94d431dc4
commit
51219e11b8
@ -23036,6 +23036,7 @@ virDomainInputDefFormat(virBufferPtr buf,
|
|||||||
{
|
{
|
||||||
const char *type = virDomainInputTypeToString(def->type);
|
const char *type = virDomainInputTypeToString(def->type);
|
||||||
const char *bus = virDomainInputBusTypeToString(def->bus);
|
const char *bus = virDomainInputBusTypeToString(def->bus);
|
||||||
|
virBuffer childbuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
/* don't format keyboard into migratable XML for backward compatibility */
|
/* don't format keyboard into migratable XML for backward compatibility */
|
||||||
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
|
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
|
||||||
@ -23058,17 +23059,17 @@ virDomainInputDefFormat(virBufferPtr buf,
|
|||||||
virBufferAsprintf(buf, "<input type='%s' bus='%s'",
|
virBufferAsprintf(buf, "<input type='%s' bus='%s'",
|
||||||
type, bus);
|
type, bus);
|
||||||
|
|
||||||
if (virDomainDeviceInfoNeedsFormat(&def->info, flags) ||
|
virBufferAdjustIndent(&childbuf, virBufferGetIndent(buf, false) + 2);
|
||||||
def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
|
virBufferEscapeString(&childbuf, "<source evdev='%s'/>\n", def->source.evdev);
|
||||||
virBufferAddLit(buf, ">\n");
|
if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0)
|
||||||
virBufferAdjustIndent(buf, 2);
|
|
||||||
virBufferEscapeString(buf, "<source evdev='%s'/>\n", def->source.evdev);
|
|
||||||
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
virBufferAdjustIndent(buf, -2);
|
|
||||||
virBufferAddLit(buf, "</input>\n");
|
if (!virBufferUse(&childbuf)) {
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddLit(buf, "/>\n");
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAddBuffer(buf, &childbuf);
|
||||||
|
virBufferAddLit(buf, "</input>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user