[Libguestfs] [PATCH v2 1/3] daemon: make sgdisk_info_extract_uuid_field more generic

Richard W.M. Jones rjones at redhat.com
Tue Jan 16 08:41:41 UTC 2018


On Mon, Jan 15, 2018 at 03:13:59PM +0100, Cédric Bosdonnat wrote:
> Rename the sgdisk_info_extract_uuid_field to
> sgdisk_info_extract_field in order to reuse it for other field types.
> Just like its C ancestor, it now needs an extractor function to be
> passed as parameter.
> ---
>  daemon/parted.ml | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/daemon/parted.ml b/daemon/parted.ml
> index d6638867a..6fe803613 100644
> --- a/daemon/parted.ml
> +++ b/daemon/parted.ml
> @@ -124,12 +124,11 @@ let part_get_parttype device =
>    | _ ->
>       failwithf "%s: cannot parse the output of parted" device
>  
> -let rec part_get_gpt_type device partnum =
> -  sgdisk_info_extract_uuid_field device partnum "Partition GUID code"
> -and part_get_gpt_guid device partnum =
> -  sgdisk_info_extract_uuid_field device partnum "Partition unique GUID"
> +let extract_guid value =
> +  (* The value contains only valid GUID characters. *)
> +  String.sub value 0 (String.span value "-0123456789ABCDEF")
>  
> -and sgdisk_info_extract_uuid_field device partnum field =
> +let sgdisk_info_extract_field device partnum field extractor =
>    if partnum <= 0 then failwith "partition number must be >= 1";
>  
>    udev_settle ();
> @@ -167,13 +166,16 @@ and sgdisk_info_extract_uuid_field device partnum field =
>         (* Skip any whitespace after the colon. *)
>         let value = String.triml value in
>  
> -       (* Extract the UUID. *)
> -       extract_uuid value
> +       (* Extract the value. *)
> +       extractor value
>  
>      | _ :: lines -> loop lines
>    in
>    loop lines
>  
> -and extract_uuid value =
> -  (* The value contains only valid GUID characters. *)
> -  String.sub value 0 (String.span value "-0123456789ABCDEF")
> +let rec part_get_gpt_type device partnum =
> +  sgdisk_info_extract_field device partnum "Partition GUID code"
> +                            extract_guid
> +and part_get_gpt_guid device partnum =
> +  sgdisk_info_extract_field device partnum "Partition unique GUID"
> +                            extract_guid
> -- 
> 2.15.1

Simple refactoring, ACK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html




More information about the Libguestfs mailing list