From 45bb7c8bcbb92c47b85538e00ff6bdaa316b92a8 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 15 Oct 2015 16:24:25 +0200 Subject: [PATCH] mllib: move is_regular_file there Move the is_regular_file function, implemented in virt-dib and virt-v2v, to Common_utils. --- dib/elements.ml | 3 --- mllib/common_utils.ml | 4 ++++ mllib/common_utils.mli | 3 +++ v2v/utils.ml | 4 ---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dib/elements.ml b/dib/elements.ml index d1b0abb56..95acca4c7 100644 --- a/dib/elements.ml +++ b/dib/elements.ml @@ -147,9 +147,6 @@ let copy_element element destdir blacklist = let dirs, nondirs = List.partition is_directory entries in let dirs = List.map (fun x -> (x, element.directory // x, destdir // x)) dirs in let nondirs = List.map (fun x -> element.directory // x) nondirs in - let is_regular_file file = - try (Unix.stat file).Unix.st_kind = Unix.S_REG - with Unix.Unix_error _ -> false in List.iter ( fun (e, path, destpath) -> do_mkdir destpath; diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml index 27bba5c9a..4d07f3a52 100644 --- a/mllib/common_utils.ml +++ b/mllib/common_utils.ml @@ -806,3 +806,7 @@ let read_first_line_from_file filename = let line = input_line chan in close_in chan; line + +let is_regular_file path = (* NB: follows symlinks. *) + try (Unix.stat path).Unix.st_kind = Unix.S_REG + with Unix.Unix_error _ -> false diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli index 0b005ef50..473efb972 100644 --- a/mllib/common_utils.mli +++ b/mllib/common_utils.mli @@ -248,3 +248,6 @@ val last_part_of : string -> char -> string option val read_first_line_from_file : string -> string (** Read only the first line (i.e. until the first newline character) of a file. *) + +val is_regular_file : string -> bool +(** Checks whether the file is a regular file. *) diff --git a/v2v/utils.ml b/v2v/utils.ml index 46cf04c29..2a668ec34 100644 --- a/v2v/utils.ml +++ b/v2v/utils.ml @@ -159,10 +159,6 @@ let find_uefi_firmware guest_arch = in loop files -let is_regular_file path = (* NB: follows symlinks. *) - try (Unix.stat path).Unix.st_kind = Unix.S_REG - with Unix.Unix_error _ -> false - (* Given a path of a file relative to the root of the directory tree * with virtio-win drivers, figure out if it's suitable for the specific Windows flavor of the current guest.