Hi,
I make a patch which reports error for a existing file to prevent
overwriting before the file.
# ./virsh dump 1 a.dump
error: file a.dump exists already
# echo $?
1
# ./virsh save 1 a.save
error: file a.save exists already
# echo $?
1
As you know, we need to add this message item to libvirt/po.
Signed-off-by: Kazuki Mizushima <mizushima.kazuk(a)jp.fujitsu.com>
Thanks,
Kazuki Mizushima
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.58
diff -u -p -r1.58 virsh.c
--- src/virsh.c 2 Mar 2007 14:22:33 -0000 1.58
+++ src/virsh.c 5 Mar 2007 06:49:28 -0000
@@ -25,6 +25,7 @@
#include <getopt.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <ctype.h>
#include <fcntl.h>
#include <locale.h>
@@ -860,6 +861,7 @@ cmdSave(vshControl * ctl, vshCmd * cmd)
virDomainPtr dom;
char *name;
char *to;
+ struct stat st;
int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -871,6 +873,11 @@ cmdSave(vshControl * ctl, vshCmd * cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
return FALSE;
+ if (stat(to, &st) == 0){
+ vshError(ctl, FALSE, _("file %s exists already"), to);
+ return FALSE;
+ }
+
if (virDomainSave(dom, to) == 0) {
vshPrint(ctl, _("Domain %s saved to %s\n"), name, to);
} else {
@@ -942,6 +949,7 @@ cmdDump(vshControl * ctl, vshCmd * cmd)
virDomainPtr dom;
char *name;
char *to;
+ struct stat st;
int ret = TRUE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -953,6 +961,11 @@ cmdDump(vshControl * ctl, vshCmd * cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, "domain", &name)))
return FALSE;
+ if (stat(to, &st) == 0){
+ vshError(ctl, FALSE, _("file %s exists already"), to);
+ return FALSE;
+ }
+
if (virDomainCoreDump(dom, to, 0) == 0) {
vshPrint(ctl, _("Domain %s dumpd to %s\n"), name, to);
} else {