[Libguestfs] [PATCH v3 1/6] mllib: compute checksum of file inside tar

Richard W.M. Jones rjones at redhat.com
Fri Dec 9 12:47:12 UTC 2016


On Wed, Dec 07, 2016 at 05:13:05PM +0100, Tomáš Golembiovský wrote:
> Signed-off-by: Tomáš Golembiovský <tgolembi at redhat.com>
> ---
>  mllib/checksums.ml  | 11 +++++++++--
>  mllib/checksums.mli |  7 +++++--
>  2 files changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/mllib/checksums.ml b/mllib/checksums.ml
> index dfa8c3a..a6c995b 100644
> --- a/mllib/checksums.ml
> +++ b/mllib/checksums.ml
> @@ -45,7 +45,7 @@ let of_string csum_type csum_value =
>    | "sha512" -> SHA512 csum_value
>    | _ -> invalid_arg csum_type
>  
> -let verify_checksum csum filename =
> +let verify_checksum csum ?tar filename =
>    let prog, csum_ref =
>      match csum with
>      | SHA1 c -> "sha1sum", c
> @@ -53,7 +53,14 @@ let verify_checksum csum filename =
>      | SHA512 c -> "sha512sum", c
>    in
>  
> -  let cmd = sprintf "%s %s" prog (Filename.quote filename) in
> +  let cmd =
> +    match tar with
> +    | None ->
> +      sprintf "%s %s" prog (Filename.quote filename)
> +    | Some tar ->
> +      sprintf "tar xOf %s %s | %s"
> +        (Filename.quote tar) (Filename.quote filename) prog
> +  in
>    let lines = external_command cmd in
>    match lines with
>    | [] ->
> diff --git a/mllib/checksums.mli b/mllib/checksums.mli
> index 0074837..9f7041b 100644
> --- a/mllib/checksums.mli
> +++ b/mllib/checksums.mli
> @@ -29,8 +29,11 @@ val of_string : string -> string -> csum_t
>  
>      Raise [Invalid_argument] if the checksum type is not known. *)
>  
> -val verify_checksum : csum_t -> string -> unit
> -(** Verify the checksum of the file. *)
> +val verify_checksum : csum_t -> ?tar:string -> string -> unit
> +(** [verify_checksum type filename] Verify the checksum of the file.
> +
> +    When optional [tar] is used it is path to uncompressed tar archive
> +    and the [filename] is a path in the tar archive. *)
>  
>  val verify_checksums : csum_t list -> string -> unit
>  (** Verify all the checksums of the file. *)

This one looks fine to me.

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