Maros Zatko
2015-Mar-05 12:58 UTC
[Libguestfs] [PATCH] customize: add --truncate-recursive option
Allows user to recursively truncate all files in a directory. Related to RHBZ#119673 Maros Zatko (1): customize: add --truncate-recursive option builder/cmdline.ml | 3 ++- customize/customize_run.ml | 6 ++++++ generator/customize.ml | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) -- 1.9.3
Maros Zatko
2015-Mar-05 12:58 UTC
[Libguestfs] [PATCH] customize: add --truncate-recursive option
Allows user to recursively truncate files in PATH. e.g.: virt-builder --truncate-recursive /var/log Relates to RHBZ#119673 --- builder/cmdline.ml | 3 ++- customize/customize_run.ml | 6 ++++++ generator/customize.ml | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/builder/cmdline.ml b/builder/cmdline.ml index b7e7e07..debc789 100644 --- a/builder/cmdline.ml +++ b/builder/cmdline.ml @@ -313,7 +313,8 @@ read the man page virt-builder(1). | `Delete _ | `Edit _ | `FirstbootCommand _ | `FirstbootPackages _ | `FirstbootScript _ | `Hostname _ | `Link _ | `Mkdir _ | `Password _ | `RootPassword _ | `Scrub _ | `SSHInject _ - | `Truncate _ | `Timezone _ | `Upload _ | `Write _ | `Chmod _ + | `Timezone _ | `Truncate _ | `TruncateRecursive _ + | `Upload _ | `Write _ | `Chmod _ | `CommandsFromFile _ | `CopyIn _ -> false ) ops.ops in if requires_execute_on_guest then diff --git a/customize/customize_run.ml b/customize/customize_run.ml index 921bc7e..0f61f81 100644 --- a/customize/customize_run.ml +++ b/customize/customize_run.ml @@ -251,6 +251,12 @@ exec >>%s 2>&1 msg (f_"Truncating: %s") path; g#truncate path + | `TruncateRecursive path -> + msg (f_"Recursively truncating: %s") path; + let maybefiles = Array.to_list (g#find path) in + let files = List.filter (fun f -> g#is_file (path ^ f)) maybefiles in + List.iter (fun f -> g#truncate (path ^ f)) files; + | `Timezone tz -> msg (f_"Setting the timezone: %s") tz; if not (Timezone.set_timezone g root tz) then diff --git a/generator/customize.ml b/generator/customize.ml index f7ec3f2..bfb37f7 100644 --- a/generator/customize.ml +++ b/generator/customize.ml @@ -326,6 +326,14 @@ This command truncates \"path\" to a zero-length file. The file must exist already."; }; + { op_name = "truncate-recursive"; + op_type = String "PATH"; + op_discrim = "`TruncateRecursive"; + op_shortdesc = "Recursively truncate all files in directory"; + op_pod_longdesc = "\ +This command recursively truncates all files under \"path\" to zero-length."; + }; + { op_name = "timezone"; op_type = String "TIMEZONE"; op_discrim = "`Timezone"; -- 1.9.3
Richard W.M. Jones
2015-Mar-05 13:01 UTC
Re: [Libguestfs] [PATCH] customize: add --truncate-recursive option
On Thu, Mar 05, 2015 at 01:58:21PM +0100, Maros Zatko wrote:> + let files = List.filter (fun f -> g#is_file (path ^ f)) maybefiles inI'm surprised that path ^ f works ... Suggest using the library function `rm_rf_only_files' instead. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v