[Pkg-libvirt-commits] [libguestfs] 04/61: v2v: Handle *.vmdk.gz compressed files (RHBZ#1152998).

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 31 19:09:34 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.28.2-1
in repository libguestfs.

commit 3e3c97961580b83f060f26006bf9ee65ba2501ec
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Sat Oct 18 18:54:12 2014 +0100

    v2v: Handle *.vmdk.gz compressed files (RHBZ#1152998).
    
    The OVA spec allows the disk images to be gzipped within the OVA
    container.
    
    (cherry picked from commit ede39a7591122abe29fc6de29aaa717ee9f8bb55)
---
 v2v/input_ova.ml | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index 4ad38a0..001a579 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -181,14 +181,36 @@ object
         let file_id = xpath_to_string "rasd:HostResource/text()" "" in
         let rex = Str.regexp "^ovf:/disk/\\(.*\\)" in
         if Str.string_match rex file_id 0 then (
+          (* Chase the references through to the actual file name. *)
           let file_id = Str.matched_group 1 file_id in
           let expr = sprintf "/ovf:Envelope/ovf:DiskSection/ovf:Disk[@ovf:diskId='%s']/@ovf:fileRef" file_id in
           let file_ref = xpath_to_string expr "" in
           if file_ref == "" then error (f_"error parsing disk fileRef");
           let expr = sprintf "/ovf:Envelope/ovf:References/ovf:File[@ovf:id='%s']/@ovf:href" file_ref in
-          let file_name = xpath_to_string expr "" in
+          let filename = xpath_to_string expr "" in
+
+          (* Does the file exist and is it readable? *)
+          let filename = exploded // 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 verbose then printf "%s\n%!" cmd;
+              if Sys.command cmd <> 0 then
+                error (f_"error uncompressing %s, see earlier error messages")
+                  filename;
+              new_filename
+            )
+            else filename in
+
           let disk = {
-            s_qemu_uri= exploded // file_name;
+            s_qemu_uri = filename;
             s_format = Some "vmdk";
             s_target_dev = Some target_dev;
           } in

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list