The following commit has been merged in the master branch:
commit 94a1d64a0ab0feeafac6426a5596bc65e9b14187
Author: Guillem Jover <guil...@debian.org>
Date:   Sat Mar 17 23:49:51 2012 +0100

    libdpkg: Change pkg_db_get_singleton() to return a better candidate
    
    When there's no installed instances, try to get a betted candidate,
    mostly for selection purposes.

diff --git a/lib/dpkg/pkg-db.c b/lib/dpkg/pkg-db.c
index bdd7c51..69a8c00 100644
--- a/lib/dpkg/pkg-db.c
+++ b/lib/dpkg/pkg-db.c
@@ -108,8 +108,9 @@ pkg_db_find_set(const char *inname)
 /**
  * Return the singleton package instance from a package set.
  *
- * This means, either the first instance if none are installed, the single
- * installed instance, or NULL if more than one instance is installed.
+ * This means, if none are installed either an instance with native or
+ * all arch or the first if none found, the single installed instance,
+ * or NULL if more than one instance is installed.
  *
  * @param set The package set to use.
  *
@@ -120,15 +121,26 @@ pkg_db_get_singleton(struct pkgset *set)
 {
   struct pkginfo *pkg;
 
-  if (pkgset_installed_instances(set) > 1)
+  switch (pkgset_installed_instances(set)) {
+  case 0:
+    /* Pick an available candidate. */
+    for (pkg = &set->pkg; pkg; pkg = pkg->arch_next) {
+      const struct dpkg_arch *arch = pkg->available.arch;
+
+      if (arch->type == arch_native || arch->type == arch_all)
+        return pkg;
+    }
+    /* Or falling that the first entry. */
+    return &set->pkg;
+  case 1:
+    for (pkg = &set->pkg; pkg; pkg = pkg->arch_next) {
+      if (pkg->status > stat_notinstalled)
+        return pkg;
+    }
+    internerr("pkgset %s should have one installed instance", set->name);
+  default:
     return NULL;
-
-  for (pkg = &set->pkg; pkg; pkg = pkg->arch_next) {
-    if (pkg->status > stat_notinstalled)
-      return pkg;
   }
-
-  return &set->pkg;
 }
 
 /**

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to