Rename the sgdisk_info_extract_uuid_field to sgdisk_info_extract_field in order to reuse it for other field types. To avoid possible confusion, the list of valid characters used to extract the value is added to the function parameters. --- daemon/parted.ml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/daemon/parted.ml b/daemon/parted.ml index d6638867a..cf1a54a08 100644 --- a/daemon/parted.ml +++ b/daemon/parted.ml @@ -124,12 +124,16 @@ let part_get_parttype device = | _ -> failwithf "%s: cannot parse the output of parted" device +let hex_chars = "0123456789ABCDEF" + let rec part_get_gpt_type device partnum = - sgdisk_info_extract_uuid_field device partnum "Partition GUID code" + sgdisk_info_extract_field device partnum "Partition GUID code" + ("-" ^ hex_chars) and part_get_gpt_guid device partnum = - sgdisk_info_extract_uuid_field device partnum "Partition unique GUID" + sgdisk_info_extract_field device partnum "Partition unique GUID" + ("-" ^ hex_chars) -and sgdisk_info_extract_uuid_field device partnum field = +and sgdisk_info_extract_field device partnum field chars = if partnum <= 0 then failwith "partition number must be >= 1"; udev_settle (); @@ -167,13 +171,13 @@ 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. *) + extract_string chars value | _ :: lines -> loop lines in loop lines -and extract_uuid value = +and extract_string chars value = (* The value contains only valid GUID characters. *) - String.sub value 0 (String.span value "-0123456789ABCDEF") + String.sub value 0 (String.span value chars) -- 2.15.1 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs