[Libguestfs] [PATCH v11 3/8] builder: change arch type to (string, string option) maybe.
Richard W.M. Jones
rjones at redhat.com
Tue Nov 7 12:35:36 UTC 2017
On Fri, Oct 27, 2017 at 04:08:17PM +0200, Cédric Bosdonnat wrote:
> In a future commit, the index parser will allow arch not to be set
> for some cases. In such cases, it will be guessed by inspecting the
> image, but we need to distinguish between a set value and a guessed
> one. Using the '(string, string option) maybe' type will help it:
>
> match arch with
> | Either s -> (* This is a set value *)
> | Or Some s -> (* This is a guessed value *)
> | Or None -> (* No value and no guess *)
I know I suggested something like this on IRC, but in retrospect
that wasn't a good idea.
First of all I don't think you need the "Or None" case at all.
Secondly it would be better to use descriptive cases instead of
the Either/Or type.
Here's a better idea (on top of your patch). I didn't change the
rest of the code but it should be obvious how to change it.
Rich.
----------------------------------------------------------------------
diff --git a/builder/index.ml b/builder/index.ml
index 18e653534..566f3e22a 100644
--- a/builder/index.ml
+++ b/builder/index.ml
@@ -26,11 +26,6 @@ open Printf
open Unix
-(* Either string -> value set
- Or Some string -> value guessed
- Or None -> value neither set nor guessed
- *)
-type arch = (string, string option) Std_utils.maybe
type index = (string * entry) list (* string = "os-version" *)
and entry = {
printable_name : string option; (* the name= field *)
@@ -52,6 +47,9 @@ and entry = {
sigchecker : Sigchecker.t;
proxy : Curl.proxy;
}
+and arch =
+ | Arch of string
+ | ArchGuessed of string
let print_entry chan (name, { printable_name; file_uri; arch; osinfo;
signature_uri; checksums; revision; format;
diff --git a/builder/index.mli b/builder/index.mli
index 43d5485fb..eb83a469c 100644
--- a/builder/index.mli
+++ b/builder/index.mli
@@ -16,11 +16,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-(* Either string -> value set
- Or Some string -> value guessed
- Or None -> value neither set nor guessed
- *)
-type arch = (string, string option) Std_utils.maybe
type index = (string * entry) list (* string = "os-version" *)
and entry = {
printable_name : string option; (* the name= field *)
@@ -42,5 +37,9 @@ and entry = {
sigchecker : Sigchecker.t;
proxy : Curl.proxy;
}
+and arch =
+ | Arch of string (** value chosen by user or config file *)
+ | ArchGuessed of string (** architecture was guessed from
+ inspection data *)
val print_entry : out_channel -> (string * entry) -> unit
--
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