This helper function calls qemu-img info on an image file and
returns the output as a JSON Yajl tree.
This function will be used in future commits.
---
builder/Makefile.am | 2 +-
builder/utils.ml | 6 ++++++
builder/utils.mli | 4 ++++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/builder/Makefile.am b/builder/Makefile.am
index 4a2f639c3..88392d327 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -61,12 +61,12 @@ SOURCES_MLI = \
yajl.mli
SOURCES_ML = \
+ yajl.ml \
utils.ml \
pxzcat.ml \
setlocale.ml \
index.ml \
ini_reader.ml \
- yajl.ml \
paths.ml \
languages.ml \
cache.ml \
diff --git a/builder/utils.ml b/builder/utils.ml
index acb6c2f4b..9fceee282 100644
--- a/builder/utils.ml
+++ b/builder/utils.ml
@@ -33,3 +33,9 @@ and revision =
let string_of_revision = function
| Rev_int n -> string_of_int n
| Rev_string s -> s
+
+let get_image_infos filepath =
+ let qemuimg_cmd = "qemu-img info --output json " ^ (Std_utils.quote filepath)
in
+ let lines = external_command qemuimg_cmd in
+ let line = String.concat "\n" lines in
+ Yajl.yajl_tree_parse line
diff --git a/builder/utils.mli b/builder/utils.mli
index 45385f713..4acde9f36 100644
--- a/builder/utils.mli
+++ b/builder/utils.mli
@@ -28,3 +28,7 @@ and revision =
val string_of_revision : revision -> string
(** Convert a {!revision} into a string. *)
+
+val get_image_infos : string -> Yajl.yajl_val
+(** [get_image_infos path] Run qemu-img info on the image pointed at
+ path as YAJL tree. *)
--
2.13.2