[Pkg-libvirt-commits] [libguestfs] 27/72: mllib: add helper mkdir_p

Hilko Bengen bengen at moszumanska.debian.org
Sun Apr 5 15:19:48 UTC 2015


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

bengen pushed a commit to branch master
in repository libguestfs.

commit e85417cda5ef83d8bca4a91029f8197072590d80
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`.
    
    (cherry picked from commit d54132f94d92e09b4cf936db23803ac26ef37648)
---
 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 6faab93..05d53af 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -611,3 +611,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 e41b157..356c486 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -141,3 +141,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