[Libguestfs] [PATCH] v2v: adding input -i ova

Richard W.M. Jones rjones at redhat.com
Thu Aug 21 14:22:27 UTC 2014


On Thu, Aug 21, 2014 at 05:09:13PM +0300, Shahar Havivi wrote:
[...]

You'll also need to update documentation (v2v/virt-v2v.pod) and maybe
add a test if it is possible to test this without carrying around
huge/proprietary files.

> +    (* verify sha1 from manifest file *)
> +    let mf = dir // !mf in
> +    let rex = Str.regexp "SHA1(\\(.*\\))= *\\(.*?\\).*$" in
> +    let lines = read_whole_file mf in

In here, add:

   let lines = string_nsplit "\n" lines in

and replace the (Str.split ... lines) with just lines (after List.iter).
   
> +    List.iter (
> +      fun line ->
> +        if Str.string_match rex line 0 then
> +          let file = Str.matched_group 1 line in
> +          let sha1 = Str.matched_group 2 line in
> +
> +          let cmd = sprintf "sha1sum %s" (quote(dir // file)) in

Might be easier to use:


       let cmd = sprintf "sha1sum %s | awk '{print $1}'"
                   (quote (dir // file)) in

> +          let out = external_command ~prog cmd in

and then:

   (match out with
   | [] -> error (f_"no output from sha1sum command, see previous errors")
   | [line] ->
      let len = String.length sha1 in
      let line =
        if len > 0 && sha1.[len-1] = '\n' then
          String.sub sha1 0 (len-1)
        else line in
      if line <> sha1 then
        error (f_"Checksum of %s does not match manifest sha1 %s") file sha1;
   | _::_ -> error (f_"cannot parse output of sha1sum command")
   );

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list