# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1217613773 25200
# Node ID a9e3b40692cef1635f1c377f896fc2d5be0b3c16
# Parent d7406e2f4670208cfe61ef9c0065164292ab3942
When saving out the infostore, clear any previous data.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r d7406e2f4670 -r a9e3b40692ce libxkutil/infostore.c
--- a/libxkutil/infostore.c Tue Jul 29 12:34:38 2008 -0700
+++ b/libxkutil/infostore.c Fri Aug 01 11:02:53 2008 -0700
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <inttypes.h>
#include <sys/file.h>
+#include <string.h>
#include <libvirt/libvirt.h>
#include <libxml/parser.h>
@@ -42,6 +43,7 @@
xmlNodePtr root;
xmlXPathContextPtr xpathctx;
int fd;
+ char *filename;
};
static void infostore_cleanup_ctx(struct infostore_ctx *ctx)
@@ -49,6 +51,7 @@
xmlXPathFreeContext(ctx->xpathctx);
xmlFreeDoc(ctx->doc);
close(ctx->fd);
+ free(ctx->filename);
free(ctx);
}
@@ -148,7 +151,12 @@
xmlSaveCtxtPtr save = NULL;
long size = 0;
- lseek(ctx->fd, 0, SEEK_SET);
+ close(ctx->fd);
+ ctx->fd = open(ctx->filename, O_RDWR|O_TRUNC, 0600);
+ if (ctx->fd < 0) {
+ CU_DEBUG("Unable to open `%s': %m", ctx->filename);
+ goto out;
+ }
save = xmlSaveToFd(ctx->fd, NULL, 0);
if (save == NULL) {
@@ -179,6 +187,8 @@
filename = make_filename(dom);
if (filename == NULL)
goto err;
+
+ isc->filename = strdup(filename);
isc->fd = open(filename, O_RDWR|O_CREAT, 0600);
if (isc->fd < 0) {
@@ -310,6 +320,7 @@
}
xmlNodeSetContent(node, BAD_CAST val);
+
out:
xmlXPathFreeObject(result);