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