Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 0/5] CentOS 6.4: Supermin fails to detect distro.
See: https://bugzilla.redhat.com/show_bug.cgi?id=1082044
Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 1/5] dpkg: Don't use OCaml 4-ism when creating a struct.
Prevents us compiling on OCaml 3.11.2 in RHEL 6. --- src/dpkg.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dpkg.ml b/src/dpkg.ml index 8f92f7f..f96105f 100644 --- a/src/dpkg.ml +++ b/src/dpkg.ml @@ -64,7 +64,8 @@ let dpkg_package_of_string str fun line -> match string_split " " line with | [ name; version; arch; _; _; "installed" ] -> - Hashtbl.add dpkg_packages name { name; version; arch } + let dpkg = { name = name; version = version; arch = arch } in + Hashtbl.add dpkg_packages name dpkg | _ -> (); ) lines ); -- 1.8.5.3
Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 2/5] Add function to get file source from file struct, and use it instead of file_exists.
--- 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
Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 3/5] kernel: Refactor code to use single function to check if modules.dep exists.
And don't use file_exists. --- src/kernel.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kernel.ml b/src/kernel.ml index 0287983..ed5aea3 100644 --- a/src/kernel.ml +++ b/src/kernel.ml @@ -195,17 +195,21 @@ and find_modpath debug kernel_version and has_modpath kernel_name try let kv = get_kernel_version kernel_name in - file_exists ("/lib/modules/" ^ kv ^ "/modules.dep") + modules_dep_exists kv with | Not_found -> false and get_kernel_version kernel_name if string_prefix "vmlinuz-" kernel_name then ( let kv = String.sub kernel_name 8 (String.length kernel_name - 8) in - if file_exists ("/lib/modules/" ^ kv ^ "/modules.dep") then kv + if modules_dep_exists kv then kv else get_kernel_version_from_name kernel_name ) else get_kernel_version_from_name kernel_name +and modules_dep_exists kv + try (lstat ("/lib/modules/" ^ kv ^ "/modules.dep")).st_kind = S_REG + with Unix_error _ -> false + and get_kernel_version_from_name kernel_name get_kernel_version_from_file ("/boot" // kernel_name) -- 1.8.5.3
Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 4/5] package handlers: Remove use of file_exists function (RHBZ#1082044).
Use equivalent code using stat. On CentOS this should detect /etc/redhat-release symlink. --- src/dpkg.ml | 2 +- src/pacman.ml | 2 +- src/rpm.ml | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dpkg.ml b/src/dpkg.ml index f96105f..1bb3f7f 100644 --- a/src/dpkg.ml +++ b/src/dpkg.ml @@ -28,7 +28,7 @@ let dpkg_detect () Config.dpkg_query <> "no" && Config.dpkg_divert <> "no" && Config.apt_get <> "no" && - file_exists "/etc/debian_version" + try (stat "/etc/debian_version").st_kind = S_REG with Unix_error _ -> false let dpkg_primary_arch = ref "" let settings = ref no_settings diff --git a/src/pacman.ml b/src/pacman.ml index 6393cfa..e411816 100644 --- a/src/pacman.ml +++ b/src/pacman.ml @@ -24,7 +24,7 @@ open Package_handler let pacman_detect () Config.pacman <> "no" && Config.fakeroot <> "no" && - file_exists "/etc/arch-release" && + (stat "/etc/arch-release").st_kind = S_REG && Config.pacman_g2 = "no" (* not Frugalware with pacman-g2 *) let settings = ref no_settings diff --git a/src/rpm.ml b/src/rpm.ml index 80c38d6..b08c60c 100644 --- a/src/rpm.ml +++ b/src/rpm.ml @@ -25,18 +25,21 @@ open Package_handler let fedora_detect () Config.rpm <> "no" && Config.rpm2cpio <> "no" && Config.yumdownloader <> "no" && - (file_exists "/etc/redhat-release" || file_exists "/etc/fedora-release") + try + (stat "/etc/redhat-release").st_kind = S_REG || + (stat "/etc/fedora-release").st_kind = S_REG + with Unix_error _ -> false let opensuse_detect () Config.rpm <> "no" && Config.rpm2cpio <> "no" && Config.zypper <> "no" && - file_exists "/etc/SuSE-release" + try (stat "/etc/SuSE-release").st_kind = S_REG with Unix_error _ -> false let mageia_detect () Config.rpm <> "no" && Config.rpm2cpio <> "no" && Config.urpmi <> "no" && Config.fakeroot <> "no" && - file_exists "/etc/mageia-release" + try (stat "/etc/mageia-release").st_kind = S_REG with Unix_error _ -> false let settings = ref no_settings let rpm_major, rpm_minor = ref 0, ref 0 -- 1.8.5.3
Richard W.M. Jones
2014-Mar-28 15:17 UTC
[Libguestfs] [PATCH supermin 5/5] Remove generic 'file_exists' function from utils.ml.
--- src/utils.ml | 4 ---- src/utils.mli | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/utils.ml b/src/utils.ml index 55f6754..5f0d24c 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -28,10 +28,6 @@ let (//) = Filename.concat let quote = Filename.quote let quoted_list names = String.concat " " (List.map quote names) -let file_exists name - try access name [F_OK]; true - with Unix_error _ -> false - let dir_exists name try (stat name).st_kind = S_DIR with Unix_error _ -> false diff --git a/src/utils.mli b/src/utils.mli index 38bf9a0..5de940d 100644 --- a/src/utils.mli +++ b/src/utils.mli @@ -24,9 +24,6 @@ val ( *^ ) : int64 -> int64 -> int64 val (/^) : int64 -> int64 -> int64 (** Int64 operators. *) -val file_exists : string -> bool - (** Return [true] iff file exists. *) - val dir_exists : string -> bool (** Return [true] iff dir exists. *) -- 1.8.5.3