- fix bug in take_solution
authorMichael Schroeder <mls@suse.de>
Wed, 24 Jun 2009 14:16:29 +0000 (16:16 +0200)
committerMichael Schroeder <mls@suse.de>
Wed, 24 Jun 2009 14:16:29 +0000 (16:16 +0200)
- add buddy callback support

examples/solv.c
src/problems.c

index 96dd40bce7c2369e1192331cf1404df4780bb1e2..3b3c19b7c06108ed3bb13fcec6e8e614d7f53394 100644 (file)
@@ -487,6 +487,8 @@ fc_cb(Pool *pool, Id p, void *cbdata)
   if (i == fcstate->newpkgscnt)
     return 0;
   fp = fcstate->newpkgsfps[i];
+  if (!fp)
+    return 0;
   rewind(fp);
   return rpm_byfp(fp, solvable2str(pool, s), &fcstate->rpmdbstate);
 }
@@ -527,6 +529,33 @@ runrpm(const char *arg, const char *name, int dupfd3)
     }
 }
 
+static Id
+nscallback(Pool *pool, void *data, Id name, Id evr)
+{
+  if (name == NAMESPACE_PRODUCTBUDDY)
+    {    
+      /* SUSE specific hack: each product has an associated rpm */
+      Solvable *s = pool->solvables + evr; 
+      Id p, pp, cap; 
+      
+      cap = str2id(pool, pool_tmpjoin(pool, "product(", id2str(pool, s->name) + 8, ")"), 0);
+      if (!cap)
+        return 0;
+      cap = rel2id(pool, cap, s->evr, REL_EQ, 0);
+      if (!cap)
+        return 0;
+      FOR_PROVIDES(p, pp, cap) 
+        {
+          Solvable *ps = pool->solvables + p; 
+          if (ps->repo == s->repo && ps->arch == s->arch)
+            break;
+        }
+      return p;
+    }
+  return 0;
+}
+
+
 int
 main(int argc, char **argv)
 {
@@ -558,6 +587,7 @@ main(int argc, char **argv)
     }
 
   pool = pool_create();
+  pool->nscallback = nscallback;
   // pool_setdebuglevel(pool, 2);
   setarch(pool);
   repoinfos = read_repoinfos(pool, ZYPP_REPOINFO_PATH, &nrepoinfos);
@@ -703,6 +733,8 @@ rerunsolver:
              exit(1);
            }
          loc = solvable_get_location(s, &medianr);
+         if (!loc)
+            continue;
          if (cinfo->type == TYPE_SUSETAGS)
            {
              const char *datadir = repo_lookup_str(cinfo->repo, SOLVID_META, SUSETAGS_DATADIR);
@@ -710,7 +742,7 @@ rerunsolver:
            }
          if ((newpkgsfps[i] = curlfopen(cinfo->baseurl, loc, 0)) == 0)
            {
-             printf("%s: %s not found\n", s->repo->name, loc);
+             printf("%s: %s not found in repository\n", s->repo->name, loc);
              exit(1);
            }
        }
@@ -736,7 +768,8 @@ rerunsolver:
          if (yesno("Re-run solver (y/n/q)? "))
            {
              for (i = 0; i < newpkgs; i++)
-               fclose(newpkgsfps[i]);
+               if (newpkgsfps[i])
+                 fclose(newpkgsfps[i]);
              newpkgsfps = sat_free(newpkgsfps);
              solver_free(solv);
              pool_add_fileconflicts_deps(pool, &conflicts);
@@ -764,6 +797,8 @@ rerunsolver:
        {
        case SOLVER_TRANSACTION_ERASE:
          printf("erase %s\n", solvid2str(pool, p));
+         if (!s->repo->rpmdbid || !s->repo->rpmdbid[p - s->repo->start])
+           continue;
          if (strlen(solvid2str(pool, p)) > 255)
            continue;
          evr = evrp = id2str(pool, s->evr);
@@ -781,6 +816,8 @@ rerunsolver:
            if (checkq.elements[j] == p)
              break;
          fp = j < newpkgs ? newpkgsfps[j] : 0;
+         if (!fp)
+           continue;
          rewind(fp);
          lseek(fileno(fp), 0, SEEK_SET);
          runrpm(type == SOLVER_TRANSACTION_MULTIINSTALL ? "-i" : "-U", "/dev/fd/3", fileno(fp));
index ccdb54c42d08a97ff158747a2f35fcbff9f78198..d90dfb752c74cb5753f9e8487cd0df2cad807bfb 100644 (file)
@@ -707,7 +707,7 @@ solver_take_solutionelement(Solver *solv, Id p, Id rp, Queue *job)
       p = SOLVER_ERASE|SOLVER_SOLVABLE;
     }
   for (i = 0; i < job->count; i += 2)
-    if (job->elements[i] == p && job->elements[i + 2] == rp)
+    if (job->elements[i] == p && job->elements[i + 1] == rp)
       return;
   queue_push2(job, p, rp);
 }