psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone
Blob Blame History Raw
From 47a44bec0a20a32ec470fdc9da92be04b4253286 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 25 Oct 2013 13:35:51 +0100
Subject: [PATCH] builder: Add --mkdir option to create directories.

(cherry picked from commit 99840550d5508b228ee4b2533ad94da517873f76)
---
 builder/builder.ml           | 13 ++++++++++---
 builder/cmdline.ml           | 12 +++++++++---
 builder/test-virt-builder.sh |  1 +
 builder/virt-builder.pod     | 12 ++++++++++++
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/builder/builder.ml b/builder/builder.ml
index ed83554..0c8f3b1 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -36,9 +36,9 @@ let main () =
   (* Command line argument parsing - see cmdline.ml. *)
   let mode, arg,
     attach, cache, check_signature, curl, debug, delete, edit, fingerprint,
-    firstboot, run, format, gpg, hostname, install, list_long, network, output,
-    password_crypto, quiet, root_password, scrub, scrub_logfile, size, source,
-    sync, upload =
+    firstboot, run, format, gpg, hostname, install, list_long, mkdirs,
+    network, output, password_crypto, quiet, root_password, scrub,
+    scrub_logfile, size, source, sync, upload =
     parse_cmdline () in
 
   (* Timestamped messages in ordinary, non-debug non-quiet mode. *)
@@ -575,6 +575,13 @@ exec >>%s 2>&1
     do_run ~display:cmd cmd
   );
 
+  (* Make directories. *)
+  List.iter (
+    fun dir ->
+      msg (f_"Making directory: %s") dir;
+      g#mkdir_p dir
+  ) mkdirs;
+
   (* Upload files. *)
   List.iter (
     fun (file, dest) ->
diff --git a/builder/cmdline.ml b/builder/cmdline.ml
index 43909cc..36c63a2 100644
--- a/builder/cmdline.ml
+++ b/builder/cmdline.ml
@@ -119,6 +119,10 @@ let parse_cmdline () =
   in
 
   let list_long = ref false in
+
+  let mkdirs = ref [] in
+  let add_mkdir arg = mkdirs := arg :: !mkdirs in
+
   let network = ref true in
   let output = ref "" in
 
@@ -217,6 +221,7 @@ let parse_cmdline () =
     "--long",    Arg.Set list_long,         ditto;
     "--no-logfile", Arg.Set scrub_logfile,  " " ^ s_"Scrub build log file";
     "--long-options", Arg.Unit display_long_options, " " ^ s_"List long options";
+    "--mkdir",   Arg.String add_mkdir,      "dir" ^ " " ^ s_"Create directory";
     "--network", Arg.Set network,           " " ^ s_"Enable appliance network (default)";
     "--no-network", Arg.Clear network,      " " ^ s_"Disable appliance network";
     "--notes",   Arg.Unit notes_mode,       " " ^ s_"Display installation notes";
@@ -281,6 +286,7 @@ read the man page virt-builder(1).
   let hostname = !hostname in
   let install = !install in
   let list_long = !list_long in
+  let mkdirs = List.rev !mkdirs in
   let network = !network in
   let output = match !output with "" -> None | s -> Some s in
   let password_crypto = !password_crypto in
@@ -345,6 +351,6 @@ read the man page virt-builder(1).
 
   mode, arg,
   attach, cache, check_signature, curl, debug, delete, edit, fingerprint,
-  firstboot, run, format, gpg, hostname, install, list_long, network, output,
-  password_crypto, quiet, root_password, scrub, scrub_logfile, size, source,
-  sync, upload
+  firstboot, run, format, gpg, hostname, install, list_long, mkdirs,
+  network, output, password_crypto, quiet, root_password, scrub,
+  scrub_logfile, size, source, sync, upload
diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh
index cec76fa..93fed4e 100755
--- a/builder/test-virt-builder.sh
+++ b/builder/test-virt-builder.sh
@@ -54,6 +54,7 @@ $VG ./virt-builder phony-fedora \
     -o $output --size 2G --format $format \
     --hostname test.example.com \
     --root-password password:123456 \
+    --mkdir /etc/foo/bar/baz \
     --upload Makefile:/Makefile \
     --upload Makefile:/etc \
     --delete /Makefile \
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index aa543bb..55dba90 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -18,6 +18,7 @@ virt-builder - Build virtual machine images quickly
     [--root-password SELECTOR]
     [--hostname HOSTNAME]
     [--install PKG,[PKG...]]
+    [--mkdir DIR]
     [--upload FILE:DEST]
     [--edit FILE:EXPR]
     [--delete FILE] [--scrub FILE]
@@ -364,6 +365,13 @@ the image was built, use this option.
 
 See also: L</LOG FILE>.
 
+=item B<--mkdir> DIR
+
+Create a directory in the guest.
+
+This uses S<C<mkdir -p>> so any intermediate directories are created,
+and it also works if the directory already exists.
+
 =item B<--network>
 
 =item B<--no-network>
@@ -756,6 +764,10 @@ Packages are installed (I<--install>).
 
 =item *
 
+Directories are created (I<--mkdir>).
+
+=item *
+
 Files are uploaded (I<--upload>).
 
 =item *
-- 
1.8.3.1