Pino Toscano
2014-Oct-31 15:30 UTC
[Libguestfs] [PATCH] builder: move the gpgkey_type type from Sigchecker to Utils
No functional change, just code motion.
---
builder/builder.ml | 6 +++---
builder/list_entries.ml | 12 ++++++------
builder/list_entries.mli | 2 +-
builder/sigchecker.ml | 5 -----
builder/sigchecker.mli | 7 +------
builder/utils.ml | 5 +++++
6 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/builder/builder.ml b/builder/builder.ml
index d7d8fb2..9a77a23 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -154,13 +154,13 @@ let main () fun { Sources.uri = uri; Sources.gpgkey =
gpgkey; Sources.proxy = proxy } ->
let gpgkey match gpgkey with
- | None -> Sigchecker.No_Key
- | Some key -> Sigchecker.KeyFile key in
+ | None -> Utils.No_Key
+ | Some key -> Utils.KeyFile key in
uri, gpgkey, proxy
) repos in
let sources = List.map (
fun (source, fingerprint) ->
- source, Sigchecker.Fingerprint fingerprint, Downloader.SystemProxy
+ source, Utils.Fingerprint fingerprint, Downloader.SystemProxy
) sources in
let sources = List.append repos sources in
let index : Index_parser.index diff --git a/builder/list_entries.ml
b/builder/list_entries.ml
index 2727c9f..2f8107f 100644
--- a/builder/list_entries.ml
+++ b/builder/list_entries.ml
@@ -50,10 +50,10 @@ and list_entries_long ~sources index fun (source, key,
proxy) ->
printf (f_"Source URI: %s\n") source;
(match key with
- | Sigchecker.No_Key -> ()
- | Sigchecker.Fingerprint fp ->
+ | Utils.No_Key -> ()
+ | Utils.Fingerprint fp ->
printf (f_"Fingerprint: %s\n") fp;
- | Sigchecker.KeyFile kf ->
+ | Utils.KeyFile kf ->
printf (f_"Key: %s\n") kf;
);
printf "\n"
@@ -103,10 +103,10 @@ and list_entries_json ~sources index let item = [
"uri", JSON.String source ] in
let item match key with
- | Sigchecker.No_Key -> item
- | Sigchecker.Fingerprint fp ->
+ | Utils.No_Key -> item
+ | Utils.Fingerprint fp ->
("fingerprint", JSON.String fp) :: item
- | Sigchecker.KeyFile kf ->
+ | Utils.KeyFile kf ->
("key", JSON.String kf) :: item in
JSON.Dict item
) sources in
diff --git a/builder/list_entries.mli b/builder/list_entries.mli
index ce012c4..520eb33 100644
--- a/builder/list_entries.mli
+++ b/builder/list_entries.mli
@@ -16,4 +16,4 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-val list_entries : list_format:([ `Short | `Long | `Json ]) ->
sources:(string * Sigchecker.gpgkey_type * Downloader.proxy_mode) list ->
Index_parser.index -> unit
+val list_entries : list_format:([ `Short | `Long | `Json ]) ->
sources:(string * Utils.gpgkey_type * Downloader.proxy_mode) list ->
Index_parser.index -> unit
diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml
index 489da28..0c292fb 100644
--- a/builder/sigchecker.ml
+++ b/builder/sigchecker.ml
@@ -24,11 +24,6 @@ open Utils
open Printf
open Unix
-type gpgkey_type - | No_Key
- | Fingerprint of string
- | KeyFile of string
-
type t = {
verbose : bool;
gpg : string;
diff --git a/builder/sigchecker.mli b/builder/sigchecker.mli
index 5b1885b..4eb7a88 100644
--- a/builder/sigchecker.mli
+++ b/builder/sigchecker.mli
@@ -18,12 +18,7 @@
type t
-type gpgkey_type - | No_Key
- | Fingerprint of string
- | KeyFile of string
-
-val create : verbose:bool -> gpg:string -> gpgkey:gpgkey_type ->
check_signature:bool -> t
+val create : verbose:bool -> gpg:string -> gpgkey:Utils.gpgkey_type ->
check_signature:bool -> t
val verify : t -> string -> unit
(** Verify the file is signed (if check_signature is true). *)
diff --git a/builder/utils.ml b/builder/utils.ml
index f4f290d..8962636 100644
--- a/builder/utils.ml
+++ b/builder/utils.ml
@@ -22,6 +22,11 @@ open Printf
open Common_utils
+type gpgkey_type + | No_Key
+ | Fingerprint of string
+ | KeyFile of string
+
let prog = Filename.basename Sys.executable_name
let error ?exit_code fs = error ~prog ?exit_code fs
let warning fs = warning ~prog fs
--
1.9.3
Pino Toscano
2014-Oct-31 15:30 UTC
[Libguestfs] [PATCH] builder: use gpgkey_type for the gpgkey field in sources
---
builder/builder.ml | 4 ----
builder/sources.ml | 8 ++++----
builder/sources.mli | 2 +-
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/builder/builder.ml b/builder/builder.ml
index 9a77a23..af61538 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -152,10 +152,6 @@ let main () let repos = Sources.read_sources ~prog
~verbose in
let repos = List.map (
fun { Sources.uri = uri; Sources.gpgkey = gpgkey; Sources.proxy = proxy }
->
- let gpgkey - match gpgkey with
- | None -> Utils.No_Key
- | Some key -> Utils.KeyFile key in
uri, gpgkey, proxy
) repos in
let sources = List.map (
diff --git a/builder/sources.ml b/builder/sources.ml
index 9b81a3a..990a2ac 100644
--- a/builder/sources.ml
+++ b/builder/sources.ml
@@ -25,7 +25,7 @@ open Unix
type source = {
name : string;
uri : string;
- gpgkey : string option;
+ gpgkey : Utils.gpgkey_type;
proxy : Downloader.proxy_mode;
}
@@ -56,15 +56,15 @@ let parse_conf ~prog ~verbose file );
raise ex in
match k with
- | None -> None
+ | None -> Utils.No_Key
| Some uri ->
(match uri.URI.protocol with
- | "file" -> Some uri.URI.path
+ | "file" -> Utils.KeyFile uri.URI.path
| _ ->
if verbose then (
printf (f_"%s: '%s' has non-local gpgkey
URI\n") prog n;
);
- None
+ Utils.No_Key
) in
let proxy try
diff --git a/builder/sources.mli b/builder/sources.mli
index 3e31d35..f7bc016 100644
--- a/builder/sources.mli
+++ b/builder/sources.mli
@@ -19,7 +19,7 @@
type source = {
name : string;
uri : string;
- gpgkey : string option;
+ gpgkey : Utils.gpgkey_type;
proxy : Downloader.proxy_mode;
}
--
1.9.3
Pino Toscano
2014-Oct-31 15:30 UTC
[Libguestfs] [PATCH] builder: pass Sources.source objects directly
Instead of passing the (uri, key, proxy) tuple around, pass the whole
Sources.source record; this requires creating proper Sources.source also
for uri+fingerprint passed via command line.
No functional changes.
---
builder/Makefile.am | 2 +-
builder/builder.ml | 17 +++++++++--------
builder/index_parser.ml | 14 +++++++-------
builder/index_parser.mli | 2 +-
builder/list_entries.ml | 12 ++++++------
builder/list_entries.mli | 2 +-
6 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/builder/Makefile.am b/builder/Makefile.am
index 5702d75..414279f 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -132,11 +132,11 @@ deps = \
languages.cmx \
get_kernel.cmx \
cache.cmx \
+ sources.cmx \
downloader.cmx \
sigchecker.cmx \
index_parser.cmx \
list_entries.cmx \
- sources.cmx \
cmdline.cmx \
builder.cmx
diff --git a/builder/builder.ml b/builder/builder.ml
index af61538..c7f1dae 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -150,22 +150,23 @@ let main () (* Download the sources. *)
let downloader = Downloader.create ~verbose ~curl ~cache in
let repos = Sources.read_sources ~prog ~verbose in
- let repos = List.map (
- fun { Sources.uri = uri; Sources.gpgkey = gpgkey; Sources.proxy = proxy }
->
- uri, gpgkey, proxy
- ) repos in
let sources = List.map (
fun (source, fingerprint) ->
- source, Utils.Fingerprint fingerprint, Downloader.SystemProxy
+ {
+ Sources.name = source; uri = source;
+ gpgkey = Utils.Fingerprint fingerprint;
+ proxy = Downloader.SystemProxy;
+ }
) sources in
let sources = List.append repos sources in
let index : Index_parser.index List.concat (
List.map (
- fun (source, key, proxy) ->
+ fun source ->
let sigchecker - Sigchecker.create ~verbose ~gpg
~check_signature ~gpgkey:key in
- Index_parser.get_index ~prog ~verbose ~downloader ~sigchecker ~proxy
source
+ Sigchecker.create ~verbose ~gpg ~check_signature
+ ~gpgkey:source.Sources.gpgkey in
+ Index_parser.get_index ~prog ~verbose ~downloader ~sigchecker source
) sources
) in
let index = remove_duplicates index in
diff --git a/builder/index_parser.ml b/builder/index_parser.ml
index 00b0e49..e2d48d7 100644
--- a/builder/index_parser.ml
+++ b/builder/index_parser.ml
@@ -111,14 +111,14 @@ let print_entry chan (name, { printable_name =
printable_name;
);
if hidden then fp "hidden=true\n"
-let get_index ~prog ~verbose ~downloader ~sigchecker ~proxy source +let
get_index ~prog ~verbose ~downloader ~sigchecker { 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.") source
+ 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
let rec get_index () (* Get the index page. *)
- let tmpfile, delete_tmpfile = Downloader.download ~prog downloader ~proxy
source in
+ let tmpfile, delete_tmpfile = Downloader.download ~prog downloader ~proxy
uri in
(* Check index file signature (also verifies it was fully
* downloaded and not corrupted in transit).
@@ -278,7 +278,7 @@ let get_index ~prog ~verbose ~downloader ~sigchecker ~proxy
source ) sections in
if verbose then (
- printf "index file (%s) after parsing (C parser):\n" source;
+ printf "index file (%s) after parsing (C parser):\n" uri;
List.iter (print_entry Pervasives.stdout) entries
);
@@ -301,10 +301,10 @@ let get_index ~prog ~verbose ~downloader ~sigchecker
~proxy source else (
(* Construct the URI. *)
try
- let i = String.rindex source '/' in
- String.sub source 0 (i+1) ^ path
+ let i = String.rindex uri '/' in
+ String.sub uri 0 (i+1) ^ path
with
- Not_found -> source // path
+ Not_found -> uri // path
)
in
diff --git a/builder/index_parser.mli b/builder/index_parser.mli
index e25fcc7..c7f244d 100644
--- a/builder/index_parser.mli
+++ b/builder/index_parser.mli
@@ -38,4 +38,4 @@ and entry = {
proxy : Downloader.proxy_mode;
}
-val get_index : prog:string -> verbose:bool -> downloader:Downloader.t
-> sigchecker:Sigchecker.t -> proxy:Downloader.proxy_mode -> string
-> index
+val get_index : prog:string -> verbose:bool -> downloader:Downloader.t
-> sigchecker:Sigchecker.t -> Sources.source -> index
diff --git a/builder/list_entries.ml b/builder/list_entries.ml
index 2f8107f..d78ddf8 100644
--- a/builder/list_entries.ml
+++ b/builder/list_entries.ml
@@ -47,9 +47,9 @@ and list_entries_long ~sources index let langs =
Languages.languages () in
List.iter (
- fun (source, key, proxy) ->
- printf (f_"Source URI: %s\n") source;
- (match key with
+ fun { Sources.uri; gpgkey } ->
+ printf (f_"Source URI: %s\n") uri;
+ (match gpgkey with
| Utils.No_Key -> ()
| Utils.Fingerprint fp ->
printf (f_"Fingerprint: %s\n") fp;
@@ -99,10 +99,10 @@ and list_entries_long ~sources index and list_entries_json
~sources index let json_sources List.map (
- fun (source, key, proxy) ->
- let item = [ "uri", JSON.String source ] in
+ fun { Sources.uri; gpgkey } ->
+ let item = [ "uri", JSON.String uri ] in
let item - match key with
+ match gpgkey with
| Utils.No_Key -> item
| Utils.Fingerprint fp ->
("fingerprint", JSON.String fp) :: item
diff --git a/builder/list_entries.mli b/builder/list_entries.mli
index 520eb33..4765f67 100644
--- a/builder/list_entries.mli
+++ b/builder/list_entries.mli
@@ -16,4 +16,4 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-val list_entries : list_format:([ `Short | `Long | `Json ]) ->
sources:(string * Utils.gpgkey_type * Downloader.proxy_mode) list ->
Index_parser.index -> unit
+val list_entries : list_format:([ `Short | `Long | `Json ]) ->
sources:Sources.source list -> Index_parser.index -> unit
--
1.9.3
Richard W.M. Jones
2014-Oct-31 16:19 UTC
Re: [Libguestfs] [PATCH] builder: move the gpgkey_type type from Sigchecker to Utils
On Fri, Oct 31, 2014 at 04:30:15PM +0100, Pino Toscano wrote:> No functional change, just code motion. > --- > builder/builder.ml | 6 +++--- > builder/list_entries.ml | 12 ++++++------ > builder/list_entries.mli | 2 +- > builder/sigchecker.ml | 5 ----- > builder/sigchecker.mli | 7 +------ > builder/utils.ml | 5 +++++ > 6 files changed, 16 insertions(+), 21 deletions(-) > > diff --git a/builder/builder.ml b/builder/builder.ml > index d7d8fb2..9a77a23 100644 > --- a/builder/builder.ml > +++ b/builder/builder.ml > @@ -154,13 +154,13 @@ let main () > fun { Sources.uri = uri; Sources.gpgkey = gpgkey; Sources.proxy = proxy } -> > let gpgkey > match gpgkey with > - | None -> Sigchecker.No_Key > - | Some key -> Sigchecker.KeyFile key in > + | None -> Utils.No_Key > + | Some key -> Utils.KeyFile key in > uri, gpgkey, proxy > ) repos in > let sources = List.map ( > fun (source, fingerprint) -> > - source, Sigchecker.Fingerprint fingerprint, Downloader.SystemProxy > + source, Utils.Fingerprint fingerprint, Downloader.SystemProxy > ) sources in > let sources = List.append repos sources in > let index : Index_parser.index > diff --git a/builder/list_entries.ml b/builder/list_entries.ml > index 2727c9f..2f8107f 100644 > --- a/builder/list_entries.ml > +++ b/builder/list_entries.ml > @@ -50,10 +50,10 @@ and list_entries_long ~sources index > fun (source, key, proxy) -> > printf (f_"Source URI: %s\n") source; > (match key with > - | Sigchecker.No_Key -> () > - | Sigchecker.Fingerprint fp -> > + | Utils.No_Key -> () > + | Utils.Fingerprint fp -> > printf (f_"Fingerprint: %s\n") fp; > - | Sigchecker.KeyFile kf -> > + | Utils.KeyFile kf -> > printf (f_"Key: %s\n") kf; > ); > printf "\n" > @@ -103,10 +103,10 @@ and list_entries_json ~sources index > let item = [ "uri", JSON.String source ] in > let item > match key with > - | Sigchecker.No_Key -> item > - | Sigchecker.Fingerprint fp -> > + | Utils.No_Key -> item > + | Utils.Fingerprint fp -> > ("fingerprint", JSON.String fp) :: item > - | Sigchecker.KeyFile kf -> > + | Utils.KeyFile kf -> > ("key", JSON.String kf) :: item in > JSON.Dict item > ) sources in > diff --git a/builder/list_entries.mli b/builder/list_entries.mli > index ce012c4..520eb33 100644 > --- a/builder/list_entries.mli > +++ b/builder/list_entries.mli > @@ -16,4 +16,4 @@ > * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. > *) > > -val list_entries : list_format:([ `Short | `Long | `Json ]) -> sources:(string * Sigchecker.gpgkey_type * Downloader.proxy_mode) list -> Index_parser.index -> unit > +val list_entries : list_format:([ `Short | `Long | `Json ]) -> sources:(string * Utils.gpgkey_type * Downloader.proxy_mode) list -> Index_parser.index -> unit > diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml > index 489da28..0c292fb 100644 > --- a/builder/sigchecker.ml > +++ b/builder/sigchecker.ml > @@ -24,11 +24,6 @@ open Utils > open Printf > open Unix > > -type gpgkey_type > - | No_Key > - | Fingerprint of string > - | KeyFile of string > - > type t = { > verbose : bool; > gpg : string; > diff --git a/builder/sigchecker.mli b/builder/sigchecker.mli > index 5b1885b..4eb7a88 100644 > --- a/builder/sigchecker.mli > +++ b/builder/sigchecker.mli > @@ -18,12 +18,7 @@ > > type t > > -type gpgkey_type > - | No_Key > - | Fingerprint of string > - | KeyFile of string > - > -val create : verbose:bool -> gpg:string -> gpgkey:gpgkey_type -> check_signature:bool -> t > +val create : verbose:bool -> gpg:string -> gpgkey:Utils.gpgkey_type -> check_signature:bool -> t > > val verify : t -> string -> unit > (** Verify the file is signed (if check_signature is true). *) > diff --git a/builder/utils.ml b/builder/utils.ml > index f4f290d..8962636 100644 > --- a/builder/utils.ml > +++ b/builder/utils.ml > @@ -22,6 +22,11 @@ open Printf > > open Common_utils > > +type gpgkey_type > + | No_Key > + | Fingerprint of string > + | KeyFile of string > + > let prog = Filename.basename Sys.executable_name > let error ?exit_code fs = error ~prog ?exit_code fs > let warning fs = warning ~prog fs > -- > 1.9.3ACK, just code motion. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Richard W.M. Jones
2014-Oct-31 16:23 UTC
Re: [Libguestfs] [PATCH] builder: pass Sources.source objects directly
On Fri, Oct 31, 2014 at 04:30:17PM +0100, Pino Toscano wrote:> -let get_index ~prog ~verbose ~downloader ~sigchecker ~proxy source > +let get_index ~prog ~verbose ~downloader ~sigchecker { Sources.uri; proxy; }I have a feeling that 'proxy;' is a OCaml 4-ism, so it probably wouldn't work on RHEL 6. You can use 'proxy = proxy' instead. Also the final semicolon is not needed. [...]> + fun { Sources.uri; gpgkey } ->Same sort of thing here. [...]> + fun { Sources.uri; gpgkey } ->And here. ACK to 2/3 and 3/3, with those changes. 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
Reasonably Related Threads
- [PATCH] builder: move the gpgkey_type type from Sigchecker to Utils
- [PATCH 3/3] builder: Use the new Curl module for passing parameters to curl.
- [PATCH 06/10] builder: split Index_parser.index in an own module
- [PATCH] builder: support aliases for images (RHBZ#1098718).
- [PATCH 2/2] builder: consolidate handling of temporary files/dirs