get_index now gets a new template parameter. Setting it to true will
make the index parsing less picky about missing important data. This
can be used to parse a partial index file.
---
 builder/builder.ml       |  2 +-
 builder/index_parser.ml  | 26 ++++++++++++++++++--------
 builder/index_parser.mli |  4 +++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/builder/builder.ml b/builder/builder.ml
index b0a48ea89..99cd488b2 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -207,7 +207,7 @@ let main () =
                               ~tmpdir in
           match source.Sources.format with
           | Sources.FormatNative ->
-            Index_parser.get_index ~downloader ~sigchecker source
+            Index_parser.get_index ~downloader ~sigchecker ~template:false 
source
           | Sources.FormatSimpleStreams ->
             Simplestreams_parser.get_index ~downloader ~sigchecker source
       ) sources
diff --git a/builder/index_parser.ml b/builder/index_parser.ml
index 468805cf8..c70909e44 100644
--- a/builder/index_parser.ml
+++ b/builder/index_parser.ml
@@ -24,7 +24,7 @@ open Utils
 open Printf
 open Unix
 
-let get_index ~downloader ~sigchecker
+let get_index ~downloader ~sigchecker ~template
   { Sources.uri = uri; proxy = 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.") uri
@@ -99,8 +99,10 @@ let get_index ~downloader ~sigchecker
           let arch =
             try List.assoc ("arch", None) fields
             with Not_found ->
-              eprintf (f_"%s: no ‘arch’ entry for ‘%s’\n") prog n;
-            corrupt_file () in
+              if template then "" else (
+                eprintf (f_"%s: no ‘arch’ entry for ‘%s’\n") prog n;
+                corrupt_file ()
+              ) in
           let signature_uri =
             try Some (make_absolute_uri (List.assoc ("sig", None) fields))
             with Not_found -> None in
@@ -112,7 +114,7 @@ let get_index ~downloader ~sigchecker
           let revision =
             try Rev_int (int_of_string (List.assoc ("revision", None) fields))
             with
-            | Not_found -> Rev_int 1
+            | Not_found -> if template then Rev_int 0 else Rev_int 1
             | Failure _ ->
               eprintf (f_"%s: cannot parse ‘revision’ field for ‘%s’\n") prog 
n;
               corrupt_file () in
@@ -122,11 +124,19 @@ let get_index ~downloader ~sigchecker
             try Int64.of_string (List.assoc ("size", None) fields)
             with
             | Not_found ->
-              eprintf (f_"%s: no ‘size’ field for ‘%s’\n") prog n;
-              corrupt_file ()
+              if template then
+                Int64.zero
+              else (
+                eprintf (f_"%s: no ‘size’ field for ‘%s’\n") prog n;
+                corrupt_file ()
+              )
             | Failure _ ->
-              eprintf (f_"%s: cannot parse ‘size’ field for ‘%s’\n") prog n;
-              corrupt_file () in
+              if template then
+                Int64.zero
+              else (
+                eprintf (f_"%s: cannot parse ‘size’ field for ‘%s’\n") prog n;
+                corrupt_file ()
+              ) in
           let compressed_size =
             try Some (Int64.of_string (List.assoc ("compressed_size", None) 
fields))
             with
diff --git a/builder/index_parser.mli b/builder/index_parser.mli
index b8d8ddf3d..aa5f84730 100644
--- a/builder/index_parser.mli
+++ b/builder/index_parser.mli
@@ -16,4 +16,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-val get_index : downloader:Downloader.t -> sigchecker:Sigchecker.t -> 
Sources.source -> Index.index
+val get_index : downloader:Downloader.t -> sigchecker:Sigchecker.t -> 
template:bool -> Sources.source -> Index.index
+(** [get_index download sigchecker source] will parse the source index file
+     into an index entry list. *)
-- 
2.12.2

_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to