[Libguestfs] [PATCH 4/4] v2v: -i ova: use Checksums
Richard W.M. Jones
rjones at redhat.com
Mon Oct 3 08:40:51 UTC 2016
On Fri, Sep 30, 2016 at 11:31:02AM +0200, Pino Toscano wrote:
> Make use of the Checksums module to ease the verification of the SHA1
> checksums in manifests.
> ---
> v2v/input_ova.ml | 17 +++++------------
> 1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
> index 4f848e2..5731a45 100644
> --- a/v2v/input_ova.ml
> +++ b/v2v/input_ova.ml
> @@ -143,18 +143,11 @@ object
> if Str.string_match rex line 0 then (
> let disk = Str.matched_group 1 line in
> let expected = Str.matched_group 2 line in
> - let cmd = sprintf "sha1sum %s" (quote (mf_folder // disk)) in
> - let out = external_command cmd in
> - match out with
> - | [] ->
> - error (f_"no output from sha1sum command, see previous errors")
> - | [line] ->
> - let actual, _ = String.split " " line in
> - if actual <> expected then
> - error (f_"checksum of disk %s does not match manifest %s (actual sha1(%s) = %s, expected sha1 (%s) = %s)")
> - disk mf disk actual disk expected;
> - debug "sha1 of %s matches expected checksum %s" disk expected
> - | _::_ -> error (f_"cannot parse output of sha1sum command")
> + let csum = Checksums.SHA1 expected in
> + try Checksums.verify_checksum csum (mf_folder // disk)
> + with Checksums.Mismatched_checksum (_, actual) ->
> + error (f_"checksum of disk %s does not match manifest %s (actual sha1(%s) = %s, expected sha1 (%s) = %s)")
> + disk mf disk actual disk expected;
> )
> in
> (try loop () with End_of_file -> ());
ACK series.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
More information about the Libguestfs
mailing list