[Pkg-libvirt-commits] [libguestfs] 301/384: mllib: add helper mkdir_p

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 16:58:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit d54132f94d92e09b4cf936db23803ac26ef37648
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Mon Feb 23 14:04:00 2015 +0100

    mllib: add helper mkdir_p
    
    Small function to create in OCaml-based code a directory and its
    parents, much like `mkdir -p`.
---
 mllib/common_utils.ml  | 11 +++++++++++
 mllib/common_utils.mli |  3 +++
 2 files changed, 14 insertions(+)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 898be17..76d8b79 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -673,3 +673,14 @@ let qemu_input_filename filename =
     "./" ^ filename
   else
     filename
+
+let rec mkdir_p path permissions =
+  try Unix.mkdir path permissions
+  with
+  | Unix.Unix_error (Unix.EEXIST, _, _) -> ()
+  | Unix.Unix_error (Unix.ENOENT, _, _) ->
+    (* A component in the path does not exist, so first try
+     * creating the parent directory, and then again the requested
+     * directory. *)
+    mkdir_p (Filename.dirname path) permissions;
+    Unix.mkdir path permissions
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index 5d3149a..28ba648 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -147,3 +147,6 @@ val qemu_input_filename : string -> string
     try to interpret that as "foo" in the file:/// protocol.  To
     avoid that, if the path is relative prefix it with "./" since
     qemu-img won't try to interpret such a path. *)
+
+val mkdir_p : string -> int -> unit
+(** Creates a directory, and its parents if missing. *)

-- 
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