mllib: Create a common utility function is_directory.

This is a wrapper around Sys.is_directory which doesn't throw
exceptions.
This commit is contained in:
Richard W.M. Jones
2014-06-13 13:34:01 +01:00
parent 9b5cdc8747
commit 893bfe2e36
3 changed files with 10 additions and 10 deletions

View File

@@ -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;

View File

@@ -451,3 +451,10 @@ 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

View File

@@ -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