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 | 36 ++++++++++++++++++++----------------
v2v/test-v2v-i-ova-gz.ovf | 2 +-
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index b283629..db884d9 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -275,25 +275,29 @@ 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 comprression in OVF: %s") s
in
+
+ let filename = if compressed then (
+ let new_filename = tmpdir // String.random8 () ^ ".vmdk" in
+ let cmd =
+ sprintf "zcat %s > %s" (quote ovf_folder // filename) (quote
new_filename) in
+ if shell_command cmd <> 0 then
+ error (f_"error uncompressing %s, see earlier error messages")
+ filename;
+ new_filename
+ )
+ else
+ ovf_folder // filename
+ in
+
(* Does the file exist and is it readable? *)
- let filename = ovf_folder // filename in
Unix.access filename [Unix.R_OK];
- (* 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 disk = {
s_disk_id = i;
s_qemu_uri = filename;
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.1