Richard W.M. Jones
2014-Aug-21 14:22 UTC
Re: [Libguestfs] [PATCH] v2v: adding input -i ova
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 inIn 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)) inMight be easier to use: let cmd = sprintf "sha1sum %s | awk '{print $1}'" (quote (dir // file)) in> + let out = external_command ~prog cmd inand 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
Richard W.M. Jones
2014-Aug-21 14:26 UTC
Re: [Libguestfs] [PATCH] v2v: adding input -i ova
On Thu, Aug 21, 2014 at 03:22:27PM +0100, Richard W.M. Jones wrote:> Might be easier to use:Or even easier and not using awk ... let cmd = sprintf "sha1sum %s" (quote (dir // file)) in ...> (match out with > | [] -> error (f_"no output from sha1sum command, see previous errors") > | [line] ->let hash, _ = string_split " " line in if hash <> sha1 then (etc) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
On 21.08.14 15:26, Richard W.M. Jones wrote:> On Thu, Aug 21, 2014 at 03:22:27PM +0100, Richard W.M. Jones wrote: > > Might be easier to use: > > Or even easier and not using awk ... > > let cmd = sprintf "sha1sum %s" (quote (dir // file)) in > > ... > > (match out with > > | [] -> error (f_"no output from sha1sum command, see previous errors") > > | [line] -> > > let hash, _ = string_split " " line in > if hash <> sha1 then > (etc) > > Rich. > > -- > Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones > Read my programming and virtualization blog: http://rwmj.wordpress.com > virt-p2v converts physical machines to virtual machines. Boot with a > live CD or over the network (PXE) and turn machines into KVM guests. > http://libguestfs.org/virt-v2vAfter applying the patch I have a logical error at the check: if hash <> sha1 then its looks like the sha1 is not a string but a unit let sha1 = Str.matched_group 2 line in (sha1 : string); Do you have an idea why? (attached the new patch) Shahar.