[Libguestfs] [PATCH] sysprep: add feature of removing specified paths

Richard W.M. Jones rjones at redhat.com
Tue Oct 29 12:57:54 UTC 2013


What do you think about this instead?

It uses the --delete option which is compatible with virt-builder.

It doesn't allow globs (whereas your version did).  Not sure if you
intended to allow globs.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
-------------- next part --------------
From 0f08b8c934551b9a970038d9ee90d534e1586295 Mon Sep 17 00:00:00 2001
From: Wanlong Gao <gaowanlong at cn.fujitsu.com>
Date: Tue, 22 Oct 2013 16:17:25 +0800
Subject: [PATCH] sysprep: add feature of deleting specified paths

Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
Signed-off-by: Richard W.M. Jones <rjones at redhat.com>
---
 po/POTFILES-ml                      |  1 +
 sysprep/Makefile.am                 |  1 +
 sysprep/sysprep_operation_delete.ml | 51 +++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 sysprep/sysprep_operation_delete.ml

diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 185f87b..98ee1cf 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -30,6 +30,7 @@ sysprep/sysprep_operation_blkid_tab.ml
 sysprep/sysprep_operation_ca_certificates.ml
 sysprep/sysprep_operation_crash_data.ml
 sysprep/sysprep_operation_cron_spool.ml
+sysprep/sysprep_operation_delete.ml
 sysprep/sysprep_operation_dhcp_client_state.ml
 sysprep/sysprep_operation_dhcp_server_state.ml
 sysprep/sysprep_operation_dovecot_data.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index a74d455..124cadf 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -36,6 +36,7 @@ operations = \
 	ca_certificates \
 	crash_data \
 	cron_spool \
+	delete \
 	dhcp_client_state \
 	dhcp_server_state \
 	dovecot_data \
diff --git a/sysprep/sysprep_operation_delete.ml b/sysprep/sysprep_operation_delete.ml
new file mode 100644
index 0000000..7cf1c39
--- /dev/null
+++ b/sysprep/sysprep_operation_delete.ml
@@ -0,0 +1,51 @@
+(* virt-sysprep
+ * Copyright (C) 2013 Fujitsu Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Common_utils
+open Sysprep_operation
+open Common_gettext.Gettext
+
+module G = Guestfs
+
+let paths = ref []
+let add_paths path = paths := path :: !paths
+
+let path_perform g root =
+  let paths = List.rev !paths in
+  List.iter g#rm_rf paths;
+  []
+
+let op = {
+  defaults with
+    name = "delete";
+    enabled_by_default = true;
+    heading = s_"Delete specified files or directories";
+    pod_description = Some (s_"\
+Delete specified files or directories.
+
+Use the I<--delete> option to specify a path to remove.");
+    extra_args = [
+      ("--delete", Arg.String add_paths, s_"path" ^ " " ^ s_"File or directory to be removed on guest"),
+      s_"\
+Delete (recursively) the specified C<path> on guest.";
+    ];
+
+    perform_on_filesystems = Some path_perform;
+}
+
+let () = register_operation op
-- 
1.8.3.1



More information about the Libguestfs mailing list