The information whether the disk is gzip compressed or not is stored
in the OVF. There is no reason to do the detection.
Signed-off-by: Tomáš Golembiovský <tgolembi(a)redhat.com>
---
v2v/input_ova.ml | 28 +++++++++++++++++-----------
v2v/test-v2v-i-ova-gz.ovf | 2 +-
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index b283629..61930f0 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -275,6 +275,13 @@ object
| None -> error (f_"no href in ovf:File (id=%s)") file_ref
| Some s -> s in
+ let expr = sprintf
"/ovf:Envelope/ovf:References/ovf:File[@ovf:id='%s']/@ovf:compression"
file_ref in
+ let compressed =
+ match xpath_string expr with
+ | None | Some "identity" -> false
+ | Some "gzip" -> true
+ | Some s -> error (f_"unsupported compression in OVF: %s") s in
+
(* Does the file exist and is it readable? *)
let filename = ovf_folder // filename in
Unix.access filename [Unix.R_OK];
@@ -282,17 +289,16 @@ object
(* The spec allows the file to be gzip-compressed, in which case
* we must uncompress it into the tmpdir.
*)
- let filename =
- if detect_file_type filename = `GZip then (
- let new_filename = tmpdir // String.random8 () ^ ".vmdk" in
- let cmd =
- sprintf "zcat %s > %s" (quote filename) (quote new_filename)
in
- if shell_command cmd <> 0 then
- error (f_"error uncompressing %s, see earlier error messages")
- filename;
- new_filename
- )
- else filename in
+ let filename = if compressed then (
+ let new_filename = tmpdir // String.random8 () ^ ".vmdk" in
+ let cmd =
+ sprintf "zcat %s > %s" (quote filename) (quote new_filename)
in
+ if shell_command cmd <> 0 then
+ error (f_"error uncompressing %s, see earlier error messages")
+ filename;
+ new_filename
+ )
+ else filename in
let disk = {
s_disk_id = i;
diff --git a/v2v/test-v2v-i-ova-gz.ovf b/v2v/test-v2v-i-ova-gz.ovf
index e10ad2b..4a03e85 100644
--- a/v2v/test-v2v-i-ova-gz.ovf
+++ b/v2v/test-v2v-i-ova-gz.ovf
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Envelope vmw:buildId="build-1750787"
xmlns="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:cim="http://schemas.dmtf.org/wbem/wscim/1/common"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Re...
xmlns:vmw="http://www.vmware.com/schema/ovf"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_Vi...
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<References>
- <File ovf:href="disk1.vmdk.gz" ovf:id="file1"
ovf:size="7804077568"/>
+ <File ovf:href="disk1.vmdk.gz" ovf:id="file1"
ovf:size="7804077568" ovf:compression="gzip"/>
</References>
<DiskSection>
<Info>Virtual disk information</Info>
--
2.10.2