[Libguestfs] [PATCH supermin 2/5] Add function to get file source from file struct, and use it instead of file_exists.

Richard W.M. Jones rjones at redhat.com
Fri Mar 28 15:17:56 UTC 2014


---
 src/chroot.ml           | 8 ++------
 src/ext2.ml             | 9 ++++-----
 src/package_handler.ml  | 9 +++++++++
 src/package_handler.mli | 3 +++
 4 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/chroot.ml b/src/chroot.ml
index 9e522d9..63a5a79 100644
--- a/src/chroot.ml
+++ b/src/chroot.ml
@@ -26,9 +26,7 @@ let build_chroot debug files outputdir =
   List.iter (
     fun file ->
       try
-        let path = if file_exists file.ft_source_path
-          then file.ft_source_path
-          else file.ft_path in
+        let path = file_source file in
         let st = lstat path in
         let opath = outputdir // file.ft_path in
         match st.st_kind with
@@ -70,9 +68,7 @@ let build_chroot debug files outputdir =
   (* Second pass: fix up directory permissions in reverse. *)
   let dirs = filter_map (
     fun file ->
-      let path =
-        if file_exists file.ft_source_path then file.ft_source_path
-        else file.ft_path in
+      let path = file_source file in
       let st = lstat path in
       if st.st_kind = S_DIR then Some (file.ft_path, st) else None
   ) files in
diff --git a/src/ext2.ml b/src/ext2.ml
index ccaa81f..c9c8933 100644
--- a/src/ext2.ml
+++ b/src/ext2.ml
@@ -67,11 +67,10 @@ let build_ext2 debug basedir files modpath kernel_version appliance =
     printf "supermin: ext2: copying files from host filesystem\n%!";
 
   (* Copy files from host filesystem. *)
-  List.iter (fun file ->
-    if file_exists file.ft_source_path then
-      ext2fs_copy_file_from_host fs file.ft_source_path file.ft_path
-    else
-      ext2fs_copy_file_from_host fs file.ft_path file.ft_path
+  List.iter (
+    fun file ->
+      let src = file_source file in
+      ext2fs_copy_file_from_host fs src file.ft_path
   ) files;
 
   if debug >= 1 then
diff --git a/src/package_handler.ml b/src/package_handler.ml
index 5aa27ba..b1dffc0 100644
--- a/src/package_handler.ml
+++ b/src/package_handler.ml
@@ -16,6 +16,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *)
 
+open Unix
 open Printf
 
 open Utils
@@ -47,6 +48,14 @@ type file = {
   ft_config : bool;
 }
 
+let file_source file =
+  try
+    if (lstat file.ft_source_path).st_kind = S_REG then
+      file.ft_source_path
+    else
+      file.ft_path
+  with Unix_error _ -> file.ft_path
+
 type package_handler = {
   ph_detect : unit -> bool;
   ph_init : settings -> unit;
diff --git a/src/package_handler.mli b/src/package_handler.mli
index fa7b396..7e17981 100644
--- a/src/package_handler.mli
+++ b/src/package_handler.mli
@@ -84,6 +84,9 @@ type file = {
       (dpkg) we guess it based on the filename. *)
 }
 
+val file_source : file -> string
+(** Get the source path, taking into account diversions. *)
+
 (** Package handlers are modules that implement this structure and
     call {!register_package_handler}. *)
 type package_handler = {
-- 
1.8.5.3




More information about the Libguestfs mailing list