From b28ef8791a21751b1def9f84108fec14ea73ffa9 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 3 Jun 2014 14:37:41 +0200 Subject: [PATCH] builder: handle duplicated images (RHBZ#1092753). Filter the available images, removing the versions with an older revisions, and duplicates. --- builder/builder.ml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/builder/builder.ml b/builder/builder.ml index 2884cf61d..5c2f6bbe8 100644 --- a/builder/builder.ml +++ b/builder/builder.ml @@ -36,6 +36,41 @@ let prog = Filename.basename Sys.executable_name let () = Random.self_init () +let remove_duplicates index = + (* Fill an hash with the higher revision of the available + * (name, arch) tuples, so it possible to ignore duplicates, + * and versions with a lower revision. + *) + let nseen = Hashtbl.create 13 in + List.iter ( + fun (name, { Index_parser.arch = arch; revision = revision }) -> + let id = name, arch in + try + let rev = Hashtbl.find nseen id in + if revision > rev then + Hashtbl.replace nseen id revision + with Not_found -> + Hashtbl.add nseen id revision + ) index; + List.filter ( + fun (name, { Index_parser.arch = arch; revision = revision }) -> + let id = name, arch in + try + let rev = Hashtbl.find nseen (name, arch) in + (* Take the first occurrency with the higher revision, + * removing it from the hash so the other occurrencies + * are ignored. + *) + if revision = rev then ( + Hashtbl.remove nseen id; + true + ) else + false + with Not_found -> + (* Already taken, so ignore. *) + false + ) index + let main () = (* Command line argument parsing - see cmdline.ml. *) let mode, arg, @@ -146,6 +181,7 @@ let main () = Index_parser.get_index ~prog ~debug ~downloader ~sigchecker ~proxy source ) sources ) in + let index = remove_duplicates index in (* Now handle the remaining modes. *) let mode =