Pino Toscano
2014-Apr-14  12:29 UTC
[Libguestfs] [PATCH] sysprep: remove also hidden files/dirs in temporary dirs
List manually and remove the content left (hidden files/directories) in
temporary directories after the glob listing & removal.
---
 sysprep/sysprep_operation_tmp_files.ml | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/sysprep/sysprep_operation_tmp_files.ml
b/sysprep/sysprep_operation_tmp_files.ml
index dc0247e..d5a52f3 100644
--- a/sysprep/sysprep_operation_tmp_files.ml
+++ b/sysprep/sysprep_operation_tmp_files.ml
@@ -24,15 +24,22 @@ module G = Guestfs
 let tmp_files_perform ~debug ~quiet g root side_effects    let typ =
g#inspect_get_type root in
   if typ <> "windows" then (
-    let paths = [ "/tmp/*";
-                  "/var/tmp/*"; ] in
+    let paths = [ "/tmp";
+                  "/var/tmp"; ] in
     List.iter (
       fun path ->
-        let files = g#glob_expand path in
+        let files = g#glob_expand (path ^ "/*") in
         Array.iter (
           fun file ->
             g#rm_rf file;
         ) files;
+        (try
+          let files = g#ls path in
+          Array.iter (
+            fun file ->
+              g#rm_rf (path ^ "/" ^ file);
+          ) files
+        with G.Error _ -> ());
     ) paths
   )
 
-- 
1.9.0
Richard W.M. Jones
2014-Apr-14  13:03 UTC
Re: [Libguestfs] [PATCH] sysprep: remove also hidden files/dirs in temporary dirs
On Mon, Apr 14, 2014 at 02:29:15PM +0200, Pino Toscano wrote:> List manually and remove the content left (hidden files/directories) in > temporary directories after the glob listing & removal. > --- > sysprep/sysprep_operation_tmp_files.ml | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/sysprep/sysprep_operation_tmp_files.ml b/sysprep/sysprep_operation_tmp_files.ml > index dc0247e..d5a52f3 100644 > --- a/sysprep/sysprep_operation_tmp_files.ml > +++ b/sysprep/sysprep_operation_tmp_files.ml > @@ -24,15 +24,22 @@ module G = Guestfs > let tmp_files_perform ~debug ~quiet g root side_effects > let typ = g#inspect_get_type root in > if typ <> "windows" then ( > - let paths = [ "/tmp/*"; > - "/var/tmp/*"; ] in > + let paths = [ "/tmp"; > + "/var/tmp"; ] in > List.iter ( > fun path -> > - let files = g#glob_expand path in > + let files = g#glob_expand (path ^ "/*") in > Array.iter ( > fun file -> > g#rm_rf file; > ) files; > + (try > + let files = g#ls path in > + Array.iter ( > + fun file -> > + g#rm_rf (path ^ "/" ^ file); > + ) files > + with G.Error _ -> ()); > ) paths > )ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html