[Libguestfs] [PATCH 3/3] OCaml: use the new behaviour of Std_utils.which

Pino Toscano ptoscano at redhat.com
Fri Jan 11 16:04:15 UTC 2019


Since Std_utils.which can handle relative/absolute paths, remove the
manual checks, and use Std_utils.which directly.
---
 common/mltools/tools_utils.ml |  4 +---
 dib/cmdline.ml                | 12 +-----------
 2 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
index 3c7e1b846..24641369e 100644
--- a/common/mltools/tools_utils.ml
+++ b/common/mltools/tools_utils.ml
@@ -408,9 +408,7 @@ and do_run ?(echo_cmd = true) ?stdout_fd ?stderr_fd args =
       fd
   in
   try
-    let app =
-      if Filename.is_relative app then which app
-      else (Unix.access app [Unix.X_OK]; app) in
+    let app = which app in
     let outfd = get_fd Unix.stdout stdout_fd in
     let errfd = get_fd Unix.stderr stderr_fd in
     if echo_cmd then
diff --git a/dib/cmdline.ml b/dib/cmdline.ml
index 220350d9d..11ff57341 100644
--- a/dib/cmdline.ml
+++ b/dib/cmdline.ml
@@ -251,17 +251,7 @@ read the man page virt-dib(1).
   if elements = [] then
     error (f_"at least one distribution root element must be specified");
 
-  let python =
-    match python with
-    | Some exe ->
-      let p =
-        if String.find exe Filename.dir_sep <> -1 then (
-          Unix.access exe [Unix.X_OK];
-          exe
-        ) else
-          get_required_tool exe in
-      Some p
-    | None -> None in
+  let python = Option.map get_required_tool python in
 
   { debug = debug; basepath = basepath; elements = elements;
     excluded_elements = excluded_elements; element_paths = element_paths;
-- 
2.17.2




More information about the Libguestfs mailing list