[Libguestfs] [PATCH 1/2] mllib: Create a common utility function is_directory.
Pino Toscano
ptoscano at redhat.com
Fri Jun 13 15:41:51 UTC 2014
On Friday 13 June 2014 13:49:35 Richard W.M. Jones wrote:
> This is a wrapper around Sys.is_directory which doesn't throw
> exceptions.
> ---
> builder/cache.ml | 9 ++-------
> mllib/common_utils.ml | 5 +++++
> v2v/cmdline.ml | 4 +---
> 3 files changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/builder/cache.ml b/builder/cache.ml
> index 581b2cf..683cd35 100644
> --- a/builder/cache.ml
> +++ b/builder/cache.ml
> @@ -34,13 +34,8 @@ type t = {
> }
>
> let create ~debug ~directory =
> - (* Annoyingly Sys.is_directory throws an exception on failure
> - * (RHBZ#1022431).
> - *)
> - let is_dir = try Sys.is_directory directory with Sys_error _ -> false in - if is_dir = false then (
> - mkdir directory 0o755
> - );
> + if not (is_directory directory) then
> + mkdir directory 0o755;
> {
> debug = debug;
> directory = directory;
> diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
> index 3b15868..3726eec 100644
> --- a/mllib/common_utils.ml
> +++ b/mllib/common_utils.ml
> @@ -451,3 +451,8 @@ let is_block_device file =
> let is_char_device file =
> try (Unix.stat file).Unix.st_kind = Unix.S_CHR
> with Unix.Unix_error _ -> false
> +
> +(* Annoyingly Sys.is_directory throws an exception on failure
> + * (RHBZ#1022431).
> + *)
> +let is_directory path = try Sys.is_directory path with Sys_error _ -> false
I'd just reindent it like the other is_* functions right above this
one, mostly for readability.
In any case, LGTM.
> diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
> index 966fe42..52a4959 100644
> --- a/v2v/cmdline.ml
> +++ b/v2v/cmdline.ml
> @@ -181,9 +181,7 @@ read the man page virt-v2v(1).
>
> | `Local ->
>
> if output_storage = "" then
> error (f_"-o local: output directory was not specified, use '-os /dir'");
> - let dir_exists =
> - try Sys.is_directory output_storage with Sys_error _ -> false in
> - if not dir_exists then
> + if not (is_directory output_storage) then
> error (f_"-os %s: output directory does not exist or is not a directory") output_storage;
> OutputLocal output_storage
--
Pino Toscano
More information about the Libguestfs
mailing list