[Pkg-libvirt-commits] [libguestfs] 08/29: mllib: add an optional filter for rm_rf_only_files
Hilko Bengen
bengen at moszumanska.debian.org
Sun Nov 1 17:15:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag upstream/1.29.49
in repository libguestfs.
commit 775e68c4613fabaa3b48ea3dc8d45ac74b93682b
Author: Pino Toscano <ptoscano at redhat.com>
Date: Tue Jun 30 20:59:31 2015 +0200
mllib: add an optional filter for rm_rf_only_files
This way it is possible to use rm_rf_only_files, but not removing
specific files.
---
mllib/common_utils.ml | 8 +++++++-
mllib/common_utils.mli | 5 ++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 516cff3..3737b4c 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -640,13 +640,19 @@ let rmdir_on_exit =
* without removing the actual directory structure. Also if 'dir' is
* not a directory or doesn't exist, ignore it.
*
+ * The optional filter is used to filter out files which will be
+ * removed: files returning true are not removed.
+ *
* XXX Could be faster with a specific API for doing this.
*)
-let rm_rf_only_files (g : Guestfs.guestfs) dir =
+let rm_rf_only_files (g : Guestfs.guestfs) ?filter dir =
if g#is_dir dir then (
let files = Array.map (Filename.concat dir) (g#find dir) in
let files = Array.to_list files in
let files = List.filter g#is_file files in
+ let files = match filter with
+ | None -> files
+ | Some f -> List.filter (fun x -> not (f x)) files in
List.iter g#rm files
)
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index bf0cba6..a5b0a68 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -140,12 +140,15 @@ val unlink_on_exit : string -> unit
val rmdir_on_exit : string -> unit
(** Remove a temporary directory on exit (using [rm -rf]). *)
-val rm_rf_only_files : Guestfs.guestfs -> string -> unit
+val rm_rf_only_files : Guestfs.guestfs -> ?filter:(string -> bool) -> string -> unit
(** Using the libguestfs API, recursively remove only files from the
given directory. Useful for cleaning [/var/cache] etc in sysprep
without removing the actual directory structure. Also if [dir] is
not a directory or doesn't exist, ignore it.
+ The optional [filter] is used to filter out files which will be
+ removed: files returning true are not removed.
+
XXX Could be faster with a specific API for doing this. *)
val truncate_recursive : Guestfs.guestfs -> string -> unit
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list