]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virXMLFormatMetadata: Don't modify deprecated 'xmlIndentTreeOutput'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 10 Nov 2025 15:52:45 +0000 (16:52 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 11 Nov 2025 20:30:06 +0000 (21:30 +0100)
'libxml2' deprecated the 'xmlIndentTreeOutput' thread-local variable as
well as the 'xmlThrDefIndentTreeOutput' function for setting the global
default, which we use in our code for formatting the metadata sub-XML.

'libxml2' also for now doesn't provide a way to set target indentation
level in 'xmlSaveCtxt' which would allow us to use the modern output
APIs, we can't replace our use of 'xmlDumpNode'. (See
https://gitlab.gnome.org/GNOME/libxml2/-/issues/989 )

Since the indentation is enabled by default in libxml2 and our most
commonly used code which calls xmlDumpNode lives in a standalone
process, where we don't override the setting, just removing the override
will result in identical behaviour.

For the use cases which do live in a process we don't fully control and
thus the default could have been overriden, the result would be that the
<metadata> element would be un-indented, but that is still valid XML.

Thus to fix the deprecated use just stop setting 'xmlIndentTreeOutput'.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/816
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/util/virxml.c

index 44f11accf3cf0f34d7c680670b52a1856d2f1b35..77c7b5a8f45c076f76716ef6dd9f9f057318adc6 100644 (file)
@@ -1920,23 +1920,14 @@ virXMLFormatMetadata(virBuffer *buf,
 {
     g_autoptr(xmlBuffer) xmlbuf = NULL;
     const char *xmlbufContent = NULL;
-    int oldIndentTreeOutput = xmlIndentTreeOutput;
 
     if (!metadata)
         return 0;
 
-    /* Indentation on output requires that we previously set
-     * xmlKeepBlanksDefault to 0 when parsing; also, libxml does 2
-     * spaces per level of indentation of intermediate elements,
-     * but no leading indentation before the starting element.
-     * Thankfully, libxml maps what looks like globals into
-     * thread-local uses, so we are thread-safe.  */
-    xmlIndentTreeOutput = 1;
     xmlbuf = virXMLBufferCreate();
 
     if (xmlNodeDump(xmlbuf, metadata->doc, metadata,
                     virBufferGetIndent(buf) / 2, 1) < 0) {
-        xmlIndentTreeOutput = oldIndentTreeOutput;
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Unable to format metadata element"));
         return -1;
@@ -1948,7 +1939,6 @@ virXMLFormatMetadata(virBuffer *buf,
     virSkipSpaces(&xmlbufContent);
 
     virBufferAsprintf(buf, "%s\n", xmlbufContent);
-    xmlIndentTreeOutput = oldIndentTreeOutput;
 
     return 0;
 }