[Libguestfs] [PATCH] builder: pass Sources.source objects directly

Pino Toscano ptoscano at redhat.com
Fri Oct 31 15:30:17 UTC 2014


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




More information about the Libguestfs mailing list