[Pkg-libvirt-commits] [libguestfs] 36/156: builder: handle duplicated images (RHBZ#1092753).

Hilko Bengen bengen at moszumanska.debian.org
Sat Aug 30 08:25:48 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit d5deb00f3b9b659987111708ed4d5de11b4e3dd0
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Jun 3 14:37:41 2014 +0200

    builder: handle duplicated images (RHBZ#1092753).
    
    Filter the available images, removing the versions with an older
    revisions, and duplicates.
    
    (cherry picked from commit b28ef8791a21751b1def9f84108fec14ea73ffa9)
---
 builder/builder.ml | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/builder/builder.ml b/builder/builder.ml
index b28e484..4a4b196 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,
@@ -157,6 +192,7 @@ let main () =
           Index_parser.get_index ~prog ~debug ~downloader ~sigchecker source
       ) sources
     ) in
+  let index = remove_duplicates index in
 
   (* Now handle the remaining modes. *)
   let mode =

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list