Fix virtual package handling
authorMichael Spang <mspang@csclub.uwaterloo.ca>
Mon, 21 Dec 2009 02:48:12 +0000 (21:48 -0500)
committerMichael Spang <mspang@csclub.uwaterloo.ca>
Tue, 22 Dec 2009 03:20:00 +0000 (22:20 -0500)
If a virtual package has no provides we should not let a valid
pkgIterator slip through.

Signed-off-by: Michael Spang <mspang@csclub.uwaterloo.ca>
inapt.cc

index 65e119b..f3aa890 100644 (file)
--- a/inapt.cc
+++ b/inapt.cc
@@ -114,35 +114,35 @@ static bool test_macro(const char *macro, std::set<std::string> *defines) {
 static pkgCache::PkgIterator eval_pkg(inapt_package *package, pkgCacheFile &cache) {
     pkgCache::PkgIterator pkg;
 
-    if (!pkg.end()) fatal("omg"); /* TODO */
-
     for (std::vector<std::string>::iterator i = package->alternates.begin(); i != package->alternates.end(); i++) {
-        pkg = cache->FindPkg(*i);
+        pkgCache::PkgIterator tmp = cache->FindPkg(*i);
 
         /* no such package */
-        if (pkg.end())
+        if (tmp.end())
             continue;
 
         /* real package */
-        if (cache[pkg].CandidateVer)
+        if (cache[tmp].CandidateVer) {
+            pkg = tmp;
             break;
+        }
 
         /* virtual package */
-        if (pkg->ProvidesList) {
-            if (!pkg.ProvidesList()->NextProvides) {
-                pkgCache::PkgIterator tmp = pkg.ProvidesList().OwnerPkg();
+        if (tmp->ProvidesList) {
+            if (!tmp.ProvidesList()->NextProvides) {
+                pkgCache::PkgIterator provide = tmp.ProvidesList().OwnerPkg();
                 if (package->action == inapt_action::INSTALL) {
-                    debug("selecting %s instead of %s", tmp.Name(), pkg.Name());
-                    pkg = tmp;
+                    debug("selecting %s instead of %s", provide.Name(), tmp.Name());
+                    pkg = provide;
                     break;
                 } else {
-                    debug("will not remove %s instead of virtual package %s", tmp.Name(), pkg.Name());
+                    debug("will not remove %s instead of virtual package %s", provide.Name(), tmp.Name());
                 }
             } else {
-                debug("%s is a virtual package", pkg.Name());
+                debug("%s is a virtual package", tmp.Name());
             }
         } else {
-            debug("%s is a virtual packages with no provides", pkg.Name());
+            debug("%s is a virtual packages with no provides", tmp.Name());
         }
     }