Pino Toscano
2014-Jun-03 12:37 UTC
[Libguestfs] [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 2884cf6..5c2f6bb 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 --
1.9.3
Richard W.M. Jones
2014-Jun-10 10:15 UTC
Re: [Libguestfs] [PATCH] builder: handle duplicated images (RHBZ#1092753).
On Tue, Jun 03, 2014 at 02:37:41PM +0200, Pino Toscano wrote:> Filter the available images, removing the versions with an older > revisions, and duplicates.Tested it and it works for me, thanks. ACKed and pushed. 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