[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH v11 5/8] builder: add a template parameter to get_index



On Fri, Oct 27, 2017 at 04:08:19PM +0200, Cédric Bosdonnat wrote:
> get_index now gets a new template parameter. Setting it to true will
> make the index parsing less picky about missing important data. This
> can be used to parse a partial index file.
> ---
>  builder/index_parser.ml  | 46 ++++++++++++++++++++++++++++++++++++++--------
>  builder/index_parser.mli |  5 ++++-
>  2 files changed, 42 insertions(+), 9 deletions(-)
> 
> diff --git a/builder/index_parser.ml b/builder/index_parser.ml
> index c715ccac7..7f64d0d98 100644
> --- a/builder/index_parser.ml
> +++ b/builder/index_parser.ml
> @@ -25,7 +25,7 @@ open Utils
>  open Printf
>  open Unix
>  
> -let get_index ~downloader ~sigchecker { Sources.uri; proxy } =
> +let get_index ~downloader ~sigchecker ?(template = false) { Sources.uri; proxy } =
>    let corrupt_file () =
>      error (f_"The index file downloaded from ‘%s’ is corrupt.\nYou need to ask the supplier of this file to fix it and upload a fixed version.") uri
>    in
> @@ -99,8 +99,25 @@ let get_index ~downloader ~sigchecker { Sources.uri; proxy } =
>            let arch =
>              try Either (List.assoc ("arch", None) fields)
>              with Not_found ->
> -              eprintf (f_"%s: no ‘arch’ entry for ‘%s’\n") prog n;
> -            corrupt_file () in
> +              if template then
> +                try
> +                  let g = new Guestfs.guestfs () in
> +                  g#add_drive_ro file_uri;
> +                  g#launch ();
> +                  let roots = g#inspect_os () in
> +                  let nroots = Array.length roots in
> +                  if nroots <> 1 then (
> +                    eprintf (f_"%s: no ‘arch’ entry for %s and failed to guess it\n") prog n;
> +                    corrupt_file ()
> +                  );
> +                  let inspected_arch = g#inspect_get_arch (Array.get roots 0) in
> +                  g#close();
> +                  Or (Some inspected_arch)
> +                with exn -> Or None

So we're throwing away the exception here ...

Are we expecting an exception to be thrown?  I'm guessing not, in
which case don't catch the exception and you don't need the "Or None"
case at all.

(See also another comment which I'm about to send ...)

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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]