On a Tuesday in 2023, Michal Privoznik wrote:
As mentioned in previous commit, VirtualBox has its own snapshot
XML which we parse, change and then format back. During this, we
ought to keep the indentation to produce better looking result
(especially when we want to compare the output in tests later on,
like we do in vboxsnapshotxmltest).
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/vbox/vbox_snapshot_conf.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 467255f77f..9a10b08c3c 100644
--- a/src/vbox/vbox_snapshot_conf.c
+++ b/src/vbox/vbox_snapshot_conf.c
@@ -25,6 +25,7 @@
#include "virstring.h"
#include "virxml.h"
+#include <libxml/xmlsave.h>
#include <libxml/xpathInternals.h>
#define VIR_FROM_THIS VIR_FROM_VBOX
@@ -364,12 +365,14 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node,
xmlParserErrors parseError = XML_ERR_OK;
char *uuid = NULL;
char *timeStamp = NULL;
-
g_auto(GStrv) firstRegex = NULL;
int firstRegexResult = 0;
g_auto(GStrv) secondRegex = NULL;
int secondRegexResult = 0;
- const int parseFlags = XML_PARSE_NONET;
+ const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS;
+ int oldIndentTreeOutput = xmlIndentTreeOutput;
+
+ xmlIndentTreeOutput = 1;
uuid = g_strdup_printf("{%s}", snapshot->uuid);
@@ -440,6 +443,8 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node,
result = 0;
cleanup:
+ xmlIndentTreeOutput = oldIndentTreeOutput;
+
if (result < 0) {
xmlFreeNode(descriptionNode);
xmlUnlinkNode(snapshotsNode);
The changes to virVBoxSnapshotConfSerializeSnapshot seem unnecessary:
1) it only does parsing, not formatting
2) its only caller (other than itself) gets the IdentTreeOutput set
below:
@@ -940,12 +945,14 @@
virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine,
xmlParserErrors parseError = XML_ERR_OK;
char *currentSnapshot = NULL;
char *timeStamp = NULL;
-
g_auto(GStrv) firstRegex = NULL;
int firstRegexResult = 0;
g_auto(GStrv) secondRegex = NULL;
int secondRegexResult = 0;
- const int parseFlags = XML_PARSE_NONET;
+ const int parseFlags = XML_PARSE_NONET | XML_PARSE_NOBLANKS;
+ int oldIndentTreeOutput = xmlIndentTreeOutput;
+
+ xmlIndentTreeOutput = 1;
if (machine == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1127,6 +1134,8 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine
*machine,
ret = 0;
cleanup:
+ xmlIndentTreeOutput = oldIndentTreeOutput;
+
VIR_FREE(currentSnapshot);
VIR_FREE(timeStamp);
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
Jano