libvirt/0003-vbox_snapshot_conf-Keep-indent-in-snapshot-XML.patch
Richard W.M. Jones f8539fae13 Backport upstream cfcbba4c2b8a
commit cfcbba4c2b8a2062dec36072a34209229b6c3277
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Wed Nov 22 14:58:49 2023 +0100

    lib: Replace qsort() with g_qsort_with_data()
2023-11-30 10:40:30 +00:00

77 lines
2.5 KiB
Diff

From ee3f790a24ec16308e016f9e7dc1cc5e29a6a525 Mon Sep 17 00:00:00 2001
From: Michal Privoznik <mprivozn@redhat.com>
Date: Tue, 21 Nov 2023 10:40:36 +0100
Subject: [PATCH 3/8] vbox_snapshot_conf: Keep indent in snapshot XML
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit d1f58b10f687050dd097c5a60becf62c35deee68)
---
src/vbox/vbox_snapshot_conf.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c
index 467255f77f..89cd685954 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,11 @@ 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;
uuid = g_strdup_printf("{%s}", snapshot->uuid);
@@ -940,12 +940,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 +1129,8 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMachine *machine,
ret = 0;
cleanup:
+ xmlIndentTreeOutput = oldIndentTreeOutput;
+
VIR_FREE(currentSnapshot);
VIR_FREE(timeStamp);
--
2.43.0