Simple code motion.
---
 v2v/input_libvirt_vddk.ml | 10 +---------
 v2v/utils.ml              |  9 +++++++++
 v2v/utils.mli             |  4 ++++
 3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/v2v/input_libvirt_vddk.ml b/v2v/input_libvirt_vddk.ml
index 36efdb260..1e1f5b6bd 100644
--- a/v2v/input_libvirt_vddk.ml
+++ b/v2v/input_libvirt_vddk.ml
@@ -334,15 +334,7 @@ object
          (* Wait for the pidfile to appear so we know that nbdkit
           * is listening for requests.
           *)
-         let rec loop i =
-           if i = 0 then false
-           else if Sys.file_exists pidfile then true
-           else (
-             sleep 1;
-             loop (i-1)
-           )
-         in
-         if not (loop 30) then (
+         if not (wait_for_file pidfile 30) then (
            if verbose () then
              error (f_"nbdkit did not start up.  See previous debugging 
messages for problems.")
            else
diff --git a/v2v/utils.ml b/v2v/utils.ml
index 1ceba94cd..58331207f 100644
--- a/v2v/utils.ml
+++ b/v2v/utils.ml
@@ -196,3 +196,12 @@ let find_file_in_tar tar filename =
     )
   in
   loop lines
+
+(* Wait for a file to appear until a timeout. *)
+let rec wait_for_file filename timeout =
+  if Sys.file_exists filename then true
+  else if timeout = 0 then false
+  else (
+    Unix.sleep 1;
+    wait_for_file filename (timeout-1)
+  )
diff --git a/v2v/utils.mli b/v2v/utils.mli
index 34402e28f..4a444aaa0 100644
--- a/v2v/utils.mli
+++ b/v2v/utils.mli
@@ -61,3 +61,7 @@ val find_file_in_tar : string -> string -> int64 * int64
 
     Function raises [Not_found] if there is no such file inside [tar] and
     [Failure] if there is any error parsing the tar output. *)
+
+val wait_for_file : string -> int -> bool
+(** [wait_for_file filename timeout] waits up to [timeout] seconds for
+    [filename] to appear.  It returns [true] if the file appeared. *)
-- 
2.13.2

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to