[Libguestfs] [PATCH] builder: proper consider subkeys in index files
Richard W.M. Jones
rjones at redhat.com
Tue Jan 21 16:43:04 UTC 2014
On Tue, Jan 21, 2014 at 05:18:27PM +0100, Pino Toscano wrote:
> let entries =
> List.map (
> fun (n, fields) ->
> + let find_elem key subkey fields =
> + match List.filter (
> + fun (iterkey, itersubkey, itervalue) ->
> + iterkey = key && itersubkey = subkey
> + ) fields with
> + | [] -> raise Not_found
> + | (_, _, value) :: _ -> value in
>
> let printable_name =
> - try Some (List.assoc "name" fields) with Not_found -> None in
> + try Some (find_elem "name" "" fields) with Not_found -> None in
What you could do here, which is a bit nicer, is (earlier on):
let fields = List.map (fun (k,sk,v) -> (k,sk),v) fields in
Delete the find_elem function and use instead:
- try Some (List.assoc "name" fields) with Not_found -> None in
+ try Some (List.assoc ("name",None) fields) with Not_found -> None in
etc. since List.assoc works for any key type, not just strings.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
More information about the Libguestfs
mailing list