pool.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007-2009, Novell Inc.
00003  *
00004  * This program is licensed under the BSD license, read LICENSE.BSD
00005  * for further information
00006  */
00007 
00008 /*
00009  * pool.c
00010  * 
00011  * The pool contains information about solvables
00012  * stored optimized for memory consumption and fast retrieval.
00013  */
00014 
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <stdarg.h>
00018 #include <unistd.h>
00019 #include <string.h>
00020 
00021 #include "pool.h"
00022 #include "repo.h"
00023 #include "poolid.h"
00024 #include "poolid_private.h"
00025 #include "poolarch.h"
00026 #include "util.h"
00027 #include "bitmap.h"
00028 #include "evr.h"
00029 
00030 #define SOLVABLE_BLOCK  255
00031 
00032 #define KNOWNID_INITIALIZE
00033 #include "knownid.h"
00034 #undef KNOWNID_INITIALIZE
00035 
00036 /* create pool */
00037 Pool *
00038 pool_create(void)
00039 {
00040   Pool *pool;
00041   Solvable *s;
00042 
00043   pool = (Pool *)sat_calloc(1, sizeof(*pool));
00044 
00045   stringpool_init (&pool->ss, initpool_data);
00046 
00047   /* alloc space for RelDep 0 */
00048   pool->rels = sat_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
00049   pool->nrels = 1;
00050   memset(pool->rels, 0, sizeof(Reldep));
00051 
00052   /* alloc space for Solvable 0 and system solvable */
00053   pool->solvables = sat_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
00054   pool->nsolvables = 2;
00055   memset(pool->solvables, 0, 2 * sizeof(Solvable));
00056   s = pool->solvables + SYSTEMSOLVABLE;
00057   s->name = SYSTEM_SYSTEM;
00058   s->arch = ARCH_NOARCH;
00059   s->evr = ID_EMPTY;
00060 
00061   queue_init(&pool->vendormap);
00062 
00063   pool->debugmask = SAT_DEBUG_RESULT;   /* FIXME */
00064 #ifdef FEDORA
00065   pool->obsoleteusescolors = 1;
00066 #endif
00067 #ifdef DEBIAN 
00068   pool->allowselfconflicts = 1;
00069 # ifdef MULTI_SEMANTICS
00070   pool->disttype = DISTTYPE_DEB;
00071 # endif
00072 #endif
00073 #ifdef RPM5
00074   pool->obsoleteusesprovides = 1;
00075   pool->implicitobsoleteusesprovides = 1;
00076 #endif
00077   return pool;
00078 }
00079 
00080 
00081 /* free all the resources of our pool */
00082 void
00083 pool_free(Pool *pool)
00084 {
00085   int i;
00086 
00087   pool_freewhatprovides(pool);
00088   pool_freeidhashes(pool);
00089   repo_freeallrepos(pool, 1);
00090   sat_free(pool->id2arch);
00091   sat_free(pool->solvables);
00092   stringpool_free(&pool->ss);
00093   sat_free(pool->rels);
00094   pool_setvendorclasses(pool, 0);
00095   queue_free(&pool->vendormap);
00096   for (i = 0; i < POOL_TMPSPACEBUF; i++)
00097     sat_free(pool->tmpspace.buf[i]);
00098   for (i = 0; i < pool->nlanguages; i++)
00099     free((char *)pool->languages[i]);
00100   sat_free(pool->languages);
00101   sat_free(pool->languagecache);
00102   sat_free(pool);
00103 }
00104 
00105 #ifdef MULTI_SEMANTICS
00106 void
00107 pool_setdisttype(Pool *pool, int disttype)
00108 {
00109   pool->disttype = disttype;
00110 }
00111 #endif
00112 
00113 Id
00114 pool_add_solvable(Pool *pool)
00115 {
00116   pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
00117   memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
00118   return pool->nsolvables++;
00119 }
00120 
00121 Id
00122 pool_add_solvable_block(Pool *pool, int count)
00123 {
00124   Id nsolvables = pool->nsolvables;
00125   if (!count)
00126     return nsolvables;
00127   pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
00128   memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
00129   pool->nsolvables += count;
00130   return nsolvables;
00131 }
00132 
00133 void
00134 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
00135 {
00136   if (!count)
00137     return;
00138   if (reuseids && start + count == pool->nsolvables)
00139     {
00140       /* might want to shrink solvable array */
00141       pool->nsolvables = start;
00142       return;
00143     }
00144   memset(pool->solvables + start, 0, sizeof(Solvable) * count);
00145 }
00146 
00147 
00148 void
00149 pool_set_installed(Pool *pool, Repo *installed)
00150 {
00151   if (pool->installed == installed)
00152     return;
00153   pool->installed = installed;
00154   pool_freewhatprovides(pool);
00155 }
00156 
00157 static int
00158 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
00159 {
00160   int r;
00161   Pool *pool = dp;
00162   Id oa, ob, *da, *db;
00163   oa = pool->whatprovides[*(Id *)ap];
00164   ob = pool->whatprovides[*(Id *)bp];
00165   if (oa == ob)
00166     return *(Id *)ap - *(Id *)bp;
00167   if (!oa)
00168     return -1;
00169   if (!ob)
00170     return 1;
00171   da = pool->whatprovidesdata + oa;
00172   db = pool->whatprovidesdata + ob;
00173   while (*db)
00174     if ((r = (*da++ - *db++)) != 0)
00175       return r;
00176   if (*da)
00177     return *da;
00178   return *(Id *)ap - *(Id *)bp;
00179 }
00180 
00181 /*
00182  * pool_shrink_whatprovides  - unify whatprovides data
00183  *
00184  * whatprovides_rel must be empty for this to work!
00185  *
00186  */
00187 static void
00188 pool_shrink_whatprovides(Pool *pool)
00189 {
00190   Id i, id;
00191   Id *sorted;
00192   Id lastid, *last, *dp, *lp;
00193   Offset o;
00194   int r;
00195 
00196   if (pool->ss.nstrings < 3)
00197     return;
00198   sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
00199   for (id = 0; id < pool->ss.nstrings; id++)
00200     sorted[id] = id;
00201   sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
00202   last = 0;
00203   lastid = 0;
00204   for (i = 1; i < pool->ss.nstrings; i++)
00205     {
00206       id = sorted[i];
00207       o = pool->whatprovides[id];
00208       if (o == 0 || o == 1)
00209         continue;
00210       dp = pool->whatprovidesdata + o;
00211       if (last)
00212         {
00213           lp = last;
00214           while (*dp)   
00215             if (*dp++ != *lp++)
00216               {
00217                 last = 0;
00218                 break;
00219               }
00220           if (last && *lp)
00221             last = 0;
00222           if (last)
00223             {
00224               pool->whatprovides[id] = -lastid;
00225               continue;
00226             }
00227         }
00228       last = pool->whatprovidesdata + o;
00229       lastid = id;
00230     }
00231   sat_free(sorted);
00232   dp = pool->whatprovidesdata + 2;
00233   for (id = 1; id < pool->ss.nstrings; id++)
00234     {
00235       o = pool->whatprovides[id];
00236       if (o == 0 || o == 1)
00237         continue;
00238       if ((Id)o < 0)
00239         {
00240           i = -(Id)o;
00241           if (i >= id)
00242             abort();
00243           pool->whatprovides[id] = pool->whatprovides[i];
00244           continue;
00245         }
00246       lp = pool->whatprovidesdata + o;
00247       if (lp < dp)
00248         abort();
00249       pool->whatprovides[id] = dp - pool->whatprovidesdata;
00250       while ((*dp++ = *lp++) != 0)
00251         ;
00252     }
00253   o = dp - pool->whatprovidesdata;
00254   POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
00255   if (pool->whatprovidesdataoff == o)
00256     return;
00257   r = pool->whatprovidesdataoff - o;
00258   pool->whatprovidesdataoff = o;
00259   pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
00260   if (r > pool->whatprovidesdataleft)
00261     r = pool->whatprovidesdataleft;
00262   memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
00263 }
00264 
00265 
00266 /*
00267  * pool_createwhatprovides()
00268  * 
00269  * create hashes over pool of solvables to ease provide lookups
00270  * 
00271  */
00272 void
00273 pool_createwhatprovides(Pool *pool)
00274 {
00275   int i, num, np, extra;
00276   Offset off;
00277   Solvable *s;
00278   Id id;
00279   Offset *idp, n;
00280   Offset *whatprovides;
00281   Id *whatprovidesdata, *d;
00282   Repo *installed = pool->installed;
00283   unsigned int now;
00284 
00285   now = sat_timems(0);
00286   POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
00287   POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
00288 
00289   pool_freeidhashes(pool);      /* XXX: should not be here! */
00290   pool_freewhatprovides(pool);
00291   num = pool->ss.nstrings;
00292   pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
00293   pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
00294 
00295   /* count providers for each name */
00296   for (i = pool->nsolvables - 1; i > 0; i--)
00297     {
00298       Id *pp;
00299       s = pool->solvables + i;
00300       if (!s->provides || !s->repo || s->repo->disabled)
00301         continue;
00302       /* we always need the installed solvable in the whatprovides data,
00303          otherwise obsoletes/conflicts on them won't work */
00304       if (s->repo != installed && !pool_installable(pool, s))
00305         continue;
00306       pp = s->repo->idarraydata + s->provides;
00307       while ((id = *pp++) != 0)
00308         {
00309           while (ISRELDEP(id))
00310             {
00311               Reldep *rd = GETRELDEP(pool, id);
00312               id = rd->name;
00313             }
00314           whatprovides[id]++;          /* inc count of providers */
00315         }
00316     }
00317 
00318   off = 2;      /* first entry is undef, second is empty list */
00319   np = 0;                              /* number of names provided */
00320   for (i = 0, idp = whatprovides; i < num; i++, idp++)
00321     {
00322       n = *idp;
00323       if (!n)                          /* no providers */
00324         continue;
00325       off += n;                        /* make space for all providers */
00326       *idp = off++;                    /* now idp points to terminating zero */
00327       np++;                            /* inc # of provider 'slots' for stats */
00328     }
00329 
00330   POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
00331 
00332   /* reserve some space for relation data */
00333   extra = 2 * pool->nrels;
00334   if (extra < 256)
00335     extra = 256;
00336 
00337   POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
00338 
00339   /* alloc space for all providers + extra */
00340   whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
00341 
00342   /* now fill data for all provides */
00343   for (i = pool->nsolvables - 1; i > 0; i--)
00344     {
00345       Id *pp;
00346       s = pool->solvables + i;
00347       if (!s->provides || !s->repo || s->repo->disabled)
00348         continue;
00349       if (s->repo != installed && !pool_installable(pool, s))
00350         continue;
00351 
00352       /* for all provides of this solvable */
00353       pp = s->repo->idarraydata + s->provides;
00354       while ((id = *pp++) != 0)
00355         {
00356           while (ISRELDEP(id))
00357             {
00358               Reldep *rd = GETRELDEP(pool, id);
00359               id = rd->name;
00360             }
00361           d = whatprovidesdata + whatprovides[id];   /* offset into whatprovidesdata */
00362           if (*d != i)          /* don't add same solvable twice */
00363             {
00364               d[-1] = i;
00365               whatprovides[id]--;
00366             }
00367         }
00368     }
00369   pool->whatprovidesdata = whatprovidesdata;
00370   pool->whatprovidesdataoff = off;
00371   pool->whatprovidesdataleft = extra;
00372   pool_shrink_whatprovides(pool);
00373   POOL_DEBUG(SAT_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (int)(1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (int)(1024/sizeof(Id)));
00374   POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
00375 }
00376 
00377 /*
00378  * free all of our whatprovides data
00379  * be careful, everything internalized with pool_queuetowhatprovides is
00380  * gone, too
00381  */
00382 void
00383 pool_freewhatprovides(Pool *pool)
00384 {
00385   pool->whatprovides = sat_free(pool->whatprovides);
00386   pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
00387   pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
00388   pool->whatprovidesdataoff = 0;
00389   pool->whatprovidesdataleft = 0;
00390 }
00391 
00392 
00393 /******************************************************************************/
00394 
00395 /*
00396  * pool_queuetowhatprovides  - add queue contents to whatprovidesdata
00397  * 
00398  * on-demand filling of provider information
00399  * move queue data into whatprovidesdata
00400  * q: queue of Ids
00401  * returns: Offset into whatprovides
00402  *
00403  */
00404 Id
00405 pool_queuetowhatprovides(Pool *pool, Queue *q)
00406 {
00407   Offset off;
00408   int count = q->count;
00409 
00410   if (count == 0)                      /* queue empty -> 1 */
00411     return 1;
00412 
00413   /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
00414   if (pool->whatprovidesdataleft < count + 1)
00415     {
00416       POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
00417       pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
00418       pool->whatprovidesdataleft = count + 4096;
00419     }
00420 
00421   /* copy queue to next free slot */
00422   off = pool->whatprovidesdataoff;
00423   memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
00424 
00425   /* adapt count and ID_NULL-terminate */
00426   pool->whatprovidesdataoff += count;
00427   pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
00428   pool->whatprovidesdataleft -= count + 1;
00429 
00430   return (Id)off;
00431 }
00432 
00433 
00434 /*************************************************************************/
00435 
00436 #if defined(MULTI_SEMANTICS)
00437 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
00438 #elif defined(DEBIAN_SEMANTICS)
00439 # define EVRCMP_DEPCMP EVRCMP_COMPARE
00440 #else
00441 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
00442 #endif
00443 
00444 /* check if a package's nevr matches a dependency */
00445 
00446 int
00447 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
00448 {
00449   Reldep *rd = GETRELDEP(pool, d);
00450   Id name = rd->name;
00451   Id evr = rd->evr;
00452   int flags = rd->flags;
00453 
00454   if (flags > 7)
00455     {
00456       switch (flags)
00457         {
00458         case REL_ARCH:
00459           if (s->arch != evr)
00460             return 0;
00461           return pool_match_nevr(pool, s, name);
00462         case REL_OR:
00463           if (pool_match_nevr(pool, s, name))
00464             return 1;
00465           return pool_match_nevr(pool, s, evr);
00466         case REL_AND:
00467         case REL_WITH:
00468           if (!pool_match_nevr(pool, s, name))
00469             return 0;
00470           return pool_match_nevr(pool, s, evr);
00471         default:
00472           return 0;
00473         }
00474     }
00475   if (!pool_match_nevr(pool, s, name))
00476     return 0;
00477   if (evr == s->evr)
00478     return flags & 2 ? 1 : 0;
00479   if (!flags)
00480     return 0;
00481   if (flags == 7)
00482     return 1;
00483   if (flags != 2 && flags != 5)
00484     flags ^= 5;
00485   if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
00486     return 1;
00487   return 0;
00488 }
00489 
00490 /* match (flags, evr) against provider (pflags, pevr) */
00491 static inline int
00492 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
00493 {
00494   if (!pflags || !flags || pflags >= 8 || flags >= 8)
00495     return 0;
00496   if (flags == 7 || pflags == 7)
00497     return 1;           /* rel provides every version */
00498   if ((pflags & flags & 5) != 0)
00499     return 1;           /* both rels show in the same direction */
00500   if (pevr == evr)
00501     {
00502       if ((pflags & flags & 2) != 0)
00503         return 1;       /* both have '=', match */
00504     }
00505   else
00506     {
00507       int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
00508       if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
00509         return 1;
00510     }
00511   return 0;
00512 }
00513 
00514 /* match two dependencies (d1 = provider) */
00515 
00516 int
00517 pool_match_dep(Pool *pool, Id d1, Id d2)
00518 {
00519   Reldep *rd1, *rd2;
00520 
00521   if (d1 == d2)
00522     return 1;
00523   if (!ISRELDEP(d1))
00524     {
00525       if (!ISRELDEP(d2))
00526         return 0;
00527       rd2 = GETRELDEP(pool, d2);
00528       return pool_match_dep(pool, d1, rd2->name);
00529     }
00530   rd1 = GETRELDEP(pool, d1);
00531   if (!ISRELDEP(d2))
00532     {
00533       return pool_match_dep(pool, rd1->name, d2);
00534     }
00535   rd2 = GETRELDEP(pool, d2);
00536   /* first match name */
00537   if (!pool_match_dep(pool, rd1->name, rd2->name))
00538     return 0;
00539   /* name matches, check flags and evr */
00540   return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
00541 }
00542 
00543 /*
00544  * addrelproviders
00545  * 
00546  * add packages fulfilling the relation to whatprovides array
00547  * no exact providers, do range match
00548  * 
00549  */
00550 
00551 Id
00552 pool_addrelproviders(Pool *pool, Id d)
00553 {
00554   Reldep *rd = GETRELDEP(pool, d);
00555   Reldep *prd;
00556   Queue plist;
00557   Id buf[16];
00558   Id name = rd->name;
00559   Id evr = rd->evr;
00560   int flags = rd->flags;
00561   Id pid, *pidp;
00562   Id p, *pp;
00563 
00564   d = GETRELID(d);
00565   queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
00566 
00567   if (flags >= 8)
00568     {
00569       /* special relation */
00570       Id wp = 0;
00571       Id *pp2, *pp3;
00572 
00573       switch (flags)
00574         {
00575         case REL_AND:
00576         case REL_WITH:
00577           wp = pool_whatprovides(pool, name);
00578           pp2 = pool_whatprovides_ptr(pool, evr);
00579           pp = pool->whatprovidesdata + wp;
00580           while ((p = *pp++) != 0)
00581             {
00582               for (pp3 = pp2; *pp3; pp3++)
00583                 if (*pp3 == p)
00584                   break;
00585               if (*pp3)
00586                 queue_push(&plist, p);  /* found it */
00587               else
00588                 wp = 0;
00589             }
00590           break;
00591         case REL_OR:
00592           wp = pool_whatprovides(pool, name);
00593           pp = pool->whatprovidesdata + wp;
00594           if (!*pp)
00595             wp = pool_whatprovides(pool, evr);
00596           else
00597             {
00598               int cnt;
00599               while ((p = *pp++) != 0)
00600                 queue_push(&plist, p);
00601               cnt = plist.count;
00602               pp = pool_whatprovides_ptr(pool, evr);
00603               while ((p = *pp++) != 0)
00604                 queue_pushunique(&plist, p);
00605               if (plist.count != cnt)
00606                 wp = 0;
00607             }
00608           break;
00609         case REL_NAMESPACE:
00610           if (name == NAMESPACE_OTHERPROVIDERS)
00611             {
00612               wp = pool_whatprovides(pool, evr);
00613               break;
00614             }
00615           if (pool->nscallback)
00616             {
00617               /* ask callback which packages provide the dependency
00618                * 0:  none
00619                * 1:  the system (aka SYSTEMSOLVABLE)
00620                * >1: set of packages, stored as offset on whatprovidesdata
00621                */
00622               p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
00623               if (p > 1)
00624                 wp = p;
00625               if (p == 1)
00626                 queue_push(&plist, SYSTEMSOLVABLE);
00627             }
00628           break;
00629         case REL_ARCH:
00630           /* small hack: make it possible to match <pkg>.src
00631            * we have to iterate over the solvables as src packages do not
00632            * provide anything, thus they are not indexed in our
00633            * whatprovides hash */
00634           if (evr == ARCH_SRC)
00635             {
00636               Solvable *s;
00637               for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
00638                 {
00639                   if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
00640                     continue;
00641                   if (pool_match_nevr(pool, s, name))
00642                     queue_push(&plist, p);
00643                 }
00644               break;
00645             }
00646           wp = pool_whatprovides(pool, name);
00647           pp = pool->whatprovidesdata + wp;
00648           while ((p = *pp++) != 0)
00649             {
00650               Solvable *s = pool->solvables + p;
00651               if (s->arch == evr)
00652                 queue_push(&plist, p);
00653               else
00654                 wp = 0;
00655             }
00656           break;
00657         case REL_FILECONFLICT:
00658           pp = pool_whatprovides_ptr(pool, name);
00659           while ((p = *pp++) != 0)
00660             {
00661               Id origd = MAKERELDEP(d);
00662               Solvable *s = pool->solvables + p;
00663               if (!s->provides)
00664                 continue;
00665               pidp = s->repo->idarraydata + s->provides;
00666               while ((pid = *pidp++) != 0)
00667                 if (pid == origd)
00668                   break;
00669               if (pid)
00670                 queue_push(&plist, p);
00671             }
00672           break;
00673         default:
00674           break;
00675         }
00676       if (wp)
00677         {
00678           /* we can reuse an existing entry */
00679           queue_free(&plist);
00680           pool->whatprovides_rel[d] = wp;
00681           return wp;
00682         }
00683     }
00684   else if (flags)
00685     {
00686       /* simple version comparison relation */
00687 #if 0
00688       POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
00689 #endif
00690       pp = pool_whatprovides_ptr(pool, name);
00691       while (ISRELDEP(name))
00692         {
00693           rd = GETRELDEP(pool, name);
00694           name = rd->name;
00695         }
00696       while ((p = *pp++) != 0)
00697         {
00698           Solvable *s = pool->solvables + p;
00699           if (!s->provides)
00700             {
00701               /* no provides - check nevr */
00702               if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
00703                 queue_push(&plist, p);
00704               continue;
00705             }
00706           /* solvable p provides name in some rels */
00707           pidp = s->repo->idarraydata + s->provides;
00708           while ((pid = *pidp++) != 0)
00709             {
00710               if (pid == name)
00711                 {
00712 #if defined(MULTI_SEMANTICS)
00713                   if (pool->disttype == DISTTYPE_DEB)
00714                     continue;
00715                   else
00716                     break;
00717 #elif defined(DEBIAN_SEMANTICS)
00718                   continue;             /* unversioned provides can
00719                                          * never match versioned deps */
00720 #else
00721                   break;                /* yes, provides all versions */
00722 #endif
00723                 }
00724               if (!ISRELDEP(pid))
00725                 continue;               /* wrong provides name */
00726               prd = GETRELDEP(pool, pid);
00727               if (prd->name != name)
00728                 continue;               /* wrong provides name */
00729               /* right package, both deps are rels. check flags/evr */
00730               if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
00731                 break;  /* matches */
00732             }
00733           if (!pid)
00734             continue;   /* none of the providers matched */
00735           queue_push(&plist, p);
00736         }
00737       /* make our system solvable provide all unknown rpmlib() stuff */
00738       if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
00739         queue_push(&plist, SYSTEMSOLVABLE);
00740     }
00741   /* add providers to whatprovides */
00742 #if 0
00743   POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
00744 #endif
00745   pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
00746   queue_free(&plist);
00747 
00748   return pool->whatprovides_rel[d];
00749 }
00750 
00751 /*************************************************************************/
00752 
00753 void
00754 pool_debug(Pool *pool, int type, const char *format, ...)
00755 {
00756   va_list args;
00757   char buf[1024];
00758 
00759   if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
00760     {
00761       if ((pool->debugmask & type) == 0)
00762         return;
00763     }
00764   va_start(args, format);
00765   if (!pool->debugcallback)
00766     {
00767       if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
00768         vprintf(format, args);
00769       else
00770         vfprintf(stderr, format, args);
00771       return;
00772     }
00773   vsnprintf(buf, sizeof(buf), format, args);
00774   pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
00775 }
00776 
00777 void
00778 pool_setdebuglevel(Pool *pool, int level)
00779 {
00780   int mask = SAT_DEBUG_RESULT;
00781   if (level > 0)
00782     mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
00783   if (level > 1)
00784     mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
00785   if (level > 2)
00786     mask |= SAT_DEBUG_PROPAGATE;
00787   if (level > 3)
00788     mask |= SAT_DEBUG_RULE_CREATION;
00789   if (level > 4)
00790     mask |= SAT_DEBUG_SCHUBI;
00791   mask |= pool->debugmask & SAT_DEBUG_TO_STDERR;        /* keep bit */
00792   pool->debugmask = mask;
00793 }
00794 
00795 /*************************************************************************/
00796 
00797 struct searchfiles {
00798   Id *ids;
00799   char **dirs;
00800   char **names;
00801   int nfiles;
00802   Map seen;
00803 };
00804 
00805 #define SEARCHFILES_BLOCK 127
00806 
00807 static void
00808 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
00809 {
00810   Id dep, sid;
00811   const char *s, *sr;
00812   struct searchfiles *csf;
00813 
00814   while ((dep = *ida++) != 0)
00815     {
00816       csf = sf;
00817       while (ISRELDEP(dep))
00818         {
00819           Reldep *rd;
00820           sid = pool->ss.nstrings + GETRELID(dep);
00821           if (MAPTST(&csf->seen, sid))
00822             {
00823               dep = 0;
00824               break;
00825             }
00826           MAPSET(&csf->seen, sid);
00827           rd = GETRELDEP(pool, dep);
00828           if (rd->flags < 8)
00829             dep = rd->name;
00830           else if (rd->flags == REL_NAMESPACE)
00831             {
00832               if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
00833                 {
00834                   csf = isf;
00835                   if (!csf || MAPTST(&csf->seen, sid))
00836                     {
00837                       dep = 0;
00838                       break;
00839                     }
00840                   MAPSET(&csf->seen, sid);
00841                 }
00842               dep = rd->evr;
00843             }
00844           else if (rd->flags == REL_FILECONFLICT)
00845             {
00846               dep = 0;
00847               break;
00848             }
00849           else
00850             {
00851               Id ids[2];
00852               ids[0] = rd->name;
00853               ids[1] = 0;
00854               pool_addfileprovides_dep(pool, ids, csf, isf);
00855               dep = rd->evr;
00856             }
00857         }
00858       if (!dep)
00859         continue;
00860       if (MAPTST(&csf->seen, dep))
00861         continue;
00862       MAPSET(&csf->seen, dep);
00863       s = id2str(pool, dep);
00864       if (*s != '/')
00865         continue;
00866       csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
00867       csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
00868       csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
00869       csf->ids[csf->nfiles] = dep;
00870       sr = strrchr(s, '/');
00871       csf->names[csf->nfiles] = strdup(sr + 1);
00872       csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
00873       if (sr != s)
00874         strncpy(csf->dirs[csf->nfiles], s, sr - s);
00875       csf->dirs[csf->nfiles][sr - s] = 0;
00876       csf->nfiles++;
00877     }
00878 }
00879 
00880 struct addfileprovides_cbdata {
00881   int nfiles;
00882   Id *ids;
00883   char **dirs;
00884   char **names;
00885 
00886   Id *dids;
00887 
00888   Map providedids;
00889 
00890   Map useddirs;
00891 };
00892 
00893 static int
00894 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
00895 {
00896   struct addfileprovides_cbdata *cbd = cbdata;
00897   int i;
00898 
00899   if (!cbd->useddirs.size)
00900     {
00901       map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
00902       for (i = 0; i < cbd->nfiles; i++)
00903         {
00904           Id did;
00905           if (MAPTST(&cbd->providedids, cbd->ids[i]))
00906             {
00907               cbd->dids[i] = 0;
00908               continue;
00909             }
00910           did = repodata_str2dir(data, cbd->dirs[i], 0);
00911           cbd->dids[i] = did;
00912           if (did)
00913             MAPSET(&cbd->useddirs, did);
00914         }
00915     }
00916   if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
00917     return 0;
00918   for (i = 0; i < cbd->nfiles; i++)
00919     {
00920       if (cbd->dids[i] != value->id)
00921         continue;
00922       if (!strcmp(cbd->names[i], value->str))
00923         break;
00924     }
00925   if (i == cbd->nfiles)
00926     return 0;
00927   s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
00928   return 0;
00929 }
00930 
00931 static void
00932 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
00933 {
00934   Id p;
00935   Repodata *data;
00936   Repo *repo;
00937   Queue fileprovidesq;
00938   int i, j, repoid, repodataid;
00939   int provstart, provend;
00940   Map donemap;
00941   int ndone, incomplete;
00942 
00943   if (!pool->nrepos)
00944     return;
00945 
00946   cbd->nfiles = sf->nfiles;
00947   cbd->ids = sf->ids;
00948   cbd->dirs = sf->dirs;
00949   cbd->names = sf->names;
00950   cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
00951   map_init(&cbd->providedids, pool->ss.nstrings);
00952 
00953   repoid = 0;
00954   repo = repoonly ? repoonly : pool->repos[0];
00955   map_init(&donemap, pool->nsolvables);
00956   queue_init(&fileprovidesq);
00957   provstart = provend = 0;
00958   for (;;)
00959     {
00960       if (repo->disabled)
00961         {
00962           if (repoonly || ++repoid == pool->nrepos)
00963             break;
00964           repo = pool->repos[repoid];
00965           continue;
00966         }
00967       ndone = 0;
00968       for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
00969         {
00970           if (ndone >= repo->nsolvables)
00971             break;
00972 
00973           if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
00974             {
00975               map_empty(&cbd->providedids);
00976               for (i = 0; i < fileprovidesq.count; i++)
00977                 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
00978               provstart = data->start;
00979               provend = data->end;
00980               for (i = 0; i < cbd->nfiles; i++)
00981                 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
00982                   break;
00983               if (i == cbd->nfiles)
00984                 {
00985                   /* great! no need to search files */
00986                   for (p = data->start; p < data->end; p++)
00987                     if (pool->solvables[p].repo == repo)
00988                       {
00989                         if (MAPTST(&donemap, p))
00990                           continue;
00991                         MAPSET(&donemap, p);
00992                         ndone++;
00993                       }
00994                   continue;
00995                 }
00996             }
00997 
00998           if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
00999             continue;
01000 
01001           if (data->start < provstart || data->end > provend)
01002             {
01003               map_empty(&cbd->providedids);
01004               provstart = provend = 0;
01005             }
01006 
01007           /* check if the data is incomplete */
01008           incomplete = 0;
01009           if (data->state == REPODATA_AVAILABLE)
01010             {
01011               for (j = 1; j < data->nkeys; j++)
01012                 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
01013                   break;
01014               if (j < data->nkeys)
01015                 {
01016 #if 0
01017                   for (i = 0; i < cbd->nfiles; i++)
01018                     if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
01019                       printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
01020 #endif
01021                   for (i = 0; i < cbd->nfiles; i++)
01022                     if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
01023                       break;
01024                   if (i < cbd->nfiles)
01025                     incomplete = 1;
01026                 }
01027             }
01028 
01029           /* do the search */
01030           map_init(&cbd->useddirs, 0);
01031           for (p = data->start; p < data->end; p++)
01032             if (pool->solvables[p].repo == repo)
01033               {
01034                 if (MAPTST(&donemap, p))
01035                   continue;
01036                 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
01037                 if (!incomplete)
01038                   {
01039                     MAPSET(&donemap, p);
01040                     ndone++;
01041                   }
01042               }
01043           map_free(&cbd->useddirs);
01044         }
01045 
01046       if (repoonly || ++repoid == pool->nrepos)
01047         break;
01048       repo = pool->repos[repoid];
01049     }
01050   map_free(&donemap);
01051   queue_free(&fileprovidesq);
01052   map_free(&cbd->providedids);
01053 }
01054 
01055 void
01056 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
01057 {
01058   Solvable *s;
01059   Repo *repo;
01060   struct searchfiles sf, isf, *isfp;
01061   struct addfileprovides_cbdata cbd;
01062   int i;
01063   unsigned int now;
01064 
01065   now = sat_timems(0);
01066   memset(&sf, 0, sizeof(sf));
01067   map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
01068   memset(&isf, 0, sizeof(isf));
01069   map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
01070 
01071   isfp = installed ? &isf : 0;
01072   for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
01073     {
01074       repo = s->repo;
01075       if (!repo)
01076         continue;
01077       if (s->obsoletes)
01078         pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
01079       if (s->conflicts)
01080         pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
01081       if (s->requires)
01082         pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
01083       if (s->recommends)
01084         pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
01085       if (s->suggests)
01086         pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
01087       if (s->supplements)
01088         pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
01089       if (s->enhances)
01090         pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
01091     }
01092   map_free(&sf.seen);
01093   map_free(&isf.seen);
01094   POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
01095   cbd.dids = 0;
01096   if (idp)
01097     *idp = 0;
01098   if (sf.nfiles)
01099     {
01100 #if 0
01101       for (i = 0; i < sf.nfiles; i++)
01102         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
01103 #endif
01104       pool_addfileprovides_search(pool, &cbd, &sf, 0);
01105       if (idp)
01106         {
01107           sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
01108           sf.ids[sf.nfiles] = 0;
01109           *idp = sf.ids;
01110           sf.ids = 0;
01111         }
01112       sat_free(sf.ids);
01113       for (i = 0; i < sf.nfiles; i++)
01114         {
01115           sat_free(sf.dirs[i]);
01116           sat_free(sf.names[i]);
01117         }
01118       sat_free(sf.dirs);
01119       sat_free(sf.names);
01120     }
01121   if (isf.nfiles)
01122     {
01123 #if 0
01124       for (i = 0; i < isf.nfiles; i++)
01125         POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
01126 #endif
01127       if (installed)
01128         pool_addfileprovides_search(pool, &cbd, &isf, installed);
01129       sat_free(isf.ids);
01130       for (i = 0; i < isf.nfiles; i++)
01131         {
01132           sat_free(isf.dirs[i]);
01133           sat_free(isf.names[i]);
01134         }
01135       sat_free(isf.dirs);
01136       sat_free(isf.names);
01137     }
01138   sat_free(cbd.dids);
01139   pool_freewhatprovides(pool);  /* as we have added provides */
01140   POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
01141 }
01142 
01143 void
01144 pool_addfileprovides(Pool *pool)
01145 {
01146   pool_addfileprovides_ids(pool, pool->installed, 0);
01147 }
01148 
01149 void
01150 pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct _Repodata *data, struct _Repokey *key, struct _KeyValue *kv), void *cbdata)
01151 {
01152   if (p)
01153     {
01154       if (pool->solvables[p].repo)
01155         repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
01156       return;
01157     }
01158   /* FIXME: obey callback return value! */
01159   for (p = 1; p < pool->nsolvables; p++)
01160     if (pool->solvables[p].repo)
01161       repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
01162 }
01163 
01164 void
01165 pool_clear_pos(Pool *pool)
01166 {
01167   memset(&pool->pos, 0, sizeof(pool->pos));
01168 }
01169 
01170 
01171 void
01172 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
01173 {
01174   int i;
01175 
01176   pool->languagecache = sat_free(pool->languagecache);
01177   pool->languagecacheother = 0;
01178   if (pool->nlanguages)
01179     {
01180       for (i = 0; i < pool->nlanguages; i++)
01181         free((char *)pool->languages[i]);
01182       free(pool->languages);
01183     }
01184   pool->nlanguages = nlanguages;
01185   if (!nlanguages)
01186     return;
01187   pool->languages = sat_calloc(nlanguages, sizeof(const char **));
01188   for (i = 0; i < pool->nlanguages; i++)
01189     pool->languages[i] = strdup(languages[i]);
01190 }
01191 
01192 Id
01193 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
01194 {
01195   const char *n;
01196   char buf[256], *p;
01197   int l;
01198 
01199   if (!lang)
01200     return id;
01201   n = id2str(pool, id);
01202   l = strlen(n) + strlen(lang) + 2;
01203   if (l > sizeof(buf))
01204     p = sat_malloc(strlen(n) + strlen(lang) + 2);
01205   else
01206     p = buf;
01207   sprintf(p, "%s:%s", n, lang);
01208   id = str2id(pool, p, create);
01209   if (p != buf)
01210     free(p);
01211   return id;
01212 }
01213 
01214 char *
01215 pool_alloctmpspace(Pool *pool, int len)
01216 {
01217   int n = pool->tmpspace.n;
01218   if (!len)
01219     return 0;
01220   if (len > pool->tmpspace.len[n])
01221     {
01222       pool->tmpspace.buf[n] = sat_realloc(pool->tmpspace.buf[n], len + 32);
01223       pool->tmpspace.len[n] = len + 32;
01224     }
01225   pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
01226   return pool->tmpspace.buf[n];
01227 }
01228 
01229 static char *
01230 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
01231 {
01232   if (space)
01233     {
01234       int n, oldn;
01235       n = oldn = pool->tmpspace.n;
01236       for (;;)
01237         {
01238           if (!n--)
01239             n = POOL_TMPSPACEBUF - 1;
01240           if (n == oldn)
01241             break;
01242           if (pool->tmpspace.buf[n] != space)
01243             continue;
01244           if (len > pool->tmpspace.len[n])
01245             {
01246               pool->tmpspace.buf[n] = sat_realloc(pool->tmpspace.buf[n], len + 32);
01247               pool->tmpspace.len[n] = len + 32;
01248             }
01249           return pool->tmpspace.buf[n];
01250         }
01251     }
01252   return 0;
01253 }
01254 
01255 void
01256 pool_freetmpspace(Pool *pool, const char *space)
01257 {
01258   int n = pool->tmpspace.n;
01259   if (!space)
01260     return;
01261   n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
01262   if (pool->tmpspace.buf[n] == space)
01263     pool->tmpspace.n = n;
01264 }
01265 
01266 char *
01267 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
01268 {
01269   int l1, l2, l3;
01270   char *s, *str;
01271   l1 = str1 ? strlen(str1) : 0;
01272   l2 = str2 ? strlen(str2) : 0;
01273   l3 = str3 ? strlen(str3) : 0;
01274   s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
01275   if (l1)
01276     {
01277       strcpy(s, str1);
01278       s += l1;
01279     }
01280   if (l2)
01281     {
01282       strcpy(s, str2);
01283       s += l2;
01284     }
01285   if (l3)
01286     {
01287       strcpy(s, str3);
01288       s += l3;
01289     }
01290   *s = 0;
01291   return str;
01292 }
01293 
01294 char *
01295 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
01296 {
01297   int l1, l2, l3;
01298   char *s, *str;
01299 
01300   l1 = str1 ? strlen(str1) : 0;
01301   l2 = str2 ? strlen(str2) : 0;
01302   l3 = str3 ? strlen(str3) : 0;
01303   str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
01304   if (str)
01305     str1 = str;
01306   else
01307     str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
01308   s = str;
01309   if (l1)
01310     {
01311       if (s != str1)
01312         strcpy(s, str1);
01313       s += l1;
01314     }
01315   if (l2)
01316     {
01317       strcpy(s, str2);
01318       s += l2;
01319     }
01320   if (l3)
01321     {
01322       strcpy(s, str3);
01323       s += l3;
01324     }
01325   *s = 0;
01326   return str;
01327 }
01328 
01329 const char *
01330 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
01331 {
01332   char *s;
01333   if (!len)
01334     return "";
01335   s = pool_alloctmpspace(pool, 2 * len + 1);
01336   sat_bin2hex(buf, len, s);
01337   return s;
01338 }
01339 
01340 /*******************************************************************/
01341 
01342 struct mptree {
01343   Id sibling;
01344   Id child;
01345   const char *comp;
01346   int compl;
01347   Id mountpoint;
01348 };
01349 
01350 struct ducbdata {
01351   DUChanges *mps;
01352   struct mptree *mptree;
01353   int addsub;
01354   int hasdu;
01355 
01356   Id *dirmap;
01357   int nmap;
01358   Repodata *olddata;
01359 };
01360 
01361 
01362 static int
01363 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
01364 {
01365   struct ducbdata *cbd = cbdata;
01366   Id mp;
01367 
01368   if (data != cbd->olddata)
01369     {
01370       Id dn, mp, comp, *dirmap, *dirs;
01371       int i, compl;
01372       const char *compstr;
01373       struct mptree *mptree;
01374 
01375       /* create map from dir to mptree */
01376       cbd->dirmap = sat_free(cbd->dirmap);
01377       cbd->nmap = 0;
01378       dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
01379       mptree = cbd->mptree;
01380       mp = 0;
01381       for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
01382         {
01383           comp = *dirs++;
01384           if (comp <= 0)
01385             {
01386               mp = dirmap[-comp];
01387               continue;
01388             }
01389           if (mp < 0)
01390             {
01391               /* unconnected */
01392               dirmap[dn] = mp;
01393               continue;
01394             }
01395           if (!mptree[mp].child)
01396             {
01397               dirmap[dn] = -mp;
01398               continue;
01399             }
01400           if (data->localpool)
01401             compstr = stringpool_id2str(&data->spool, comp);
01402           else
01403             compstr = id2str(data->repo->pool, comp);
01404           compl = strlen(compstr);
01405           for (i = mptree[mp].child; i; i = mptree[i].sibling)
01406             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
01407               break;
01408           dirmap[dn] = i ? i : -mp;
01409         }
01410       /* change dirmap to point to mountpoint instead of mptree */
01411       for (dn = 0; dn < data->dirpool.ndirs; dn++)
01412         {
01413           mp = dirmap[dn];
01414           dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
01415         }
01416       cbd->dirmap = dirmap;
01417       cbd->nmap = data->dirpool.ndirs;
01418       cbd->olddata = data;
01419     }
01420   cbd->hasdu = 1;
01421   if (value->id < 0 || value->id >= cbd->nmap)
01422     return 0;
01423   mp = cbd->dirmap[value->id];
01424   if (mp < 0)
01425     return 0;
01426   if (cbd->addsub > 0)
01427     {
01428       cbd->mps[mp].kbytes += value->num;
01429       cbd->mps[mp].files += value->num2;
01430     }
01431   else
01432     {
01433       cbd->mps[mp].kbytes -= value->num;
01434       cbd->mps[mp].files -= value->num2;
01435     }
01436   return 0;
01437 }
01438 
01439 static void
01440 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
01441 {
01442   int i;
01443   if (mptree[pos].mountpoint == -1)
01444     mptree[pos].mountpoint = mountpoint;
01445   else
01446     mountpoint = mptree[pos].mountpoint;
01447   for (i = mptree[pos].child; i; i = mptree[i].sibling)
01448     propagate_mountpoints(mptree, i, mountpoint);
01449 }
01450 
01451 #define MPTREE_BLOCK 15
01452 
01453 void
01454 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
01455 {
01456   char *p;
01457   const char *path, *compstr;
01458   struct mptree *mptree;
01459   int i, nmptree;
01460   int pos, compl;
01461   int mp;
01462   struct ducbdata cbd;
01463   Solvable *s;
01464   Id sp;
01465   Map ignoredu;
01466   Repo *oldinstalled = pool->installed;
01467 
01468   memset(&ignoredu, 0, sizeof(ignoredu));
01469   cbd.mps = mps;
01470   cbd.addsub = 0;
01471   cbd.dirmap = 0;
01472   cbd.nmap = 0;
01473   cbd.olddata = 0;
01474 
01475   mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
01476 
01477   /* our root node */
01478   mptree[0].sibling = 0;
01479   mptree[0].child = 0;
01480   mptree[0].comp = 0;
01481   mptree[0].compl = 0;
01482   mptree[0].mountpoint = -1;
01483   nmptree = 1;
01484   
01485   /* create component tree */
01486   for (mp = 0; mp < nmps; mp++)
01487     {
01488       mps[mp].kbytes = 0;
01489       mps[mp].files = 0;
01490       pos = 0;
01491       path = mps[mp].path;
01492       while(*path == '/')
01493         path++;
01494       while (*path)
01495         {
01496           if ((p = strchr(path, '/')) == 0)
01497             {
01498               compstr = path;
01499               compl = strlen(compstr);
01500               path += compl;
01501             }
01502           else
01503             {
01504               compstr = path;
01505               compl = p - path;
01506               path = p + 1;
01507               while(*path == '/')
01508                 path++;
01509             }
01510           for (i = mptree[pos].child; i; i = mptree[i].sibling)
01511             if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
01512               break;
01513           if (!i)
01514             {
01515               /* create new node */
01516               mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
01517               i = nmptree++;
01518               mptree[i].sibling = mptree[pos].child;
01519               mptree[i].child = 0;
01520               mptree[i].comp = compstr;
01521               mptree[i].compl = compl;
01522               mptree[i].mountpoint = -1;
01523               mptree[pos].child = i;
01524             }
01525           pos = i;
01526         }
01527       mptree[pos].mountpoint = mp;
01528     }
01529 
01530   propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
01531 
01532 #if 0
01533   for (i = 0; i < nmptree; i++)
01534     {
01535       printf("#%d sibling: %d\n", i, mptree[i].sibling);
01536       printf("#%d child: %d\n", i, mptree[i].child);
01537       printf("#%d comp: %s\n", i, mptree[i].comp);
01538       printf("#%d compl: %d\n", i, mptree[i].compl);
01539       printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
01540     }
01541 #endif
01542 
01543   cbd.mptree = mptree;
01544   cbd.addsub = 1;
01545   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
01546     {
01547       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
01548         continue;
01549       if (!MAPTST(installedmap, sp))
01550         continue;
01551       cbd.hasdu = 0;
01552       repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
01553       if (!cbd.hasdu && oldinstalled)
01554         {
01555           Id op, opp;
01556           /* no du data available, ignore data of all installed solvables we obsolete */
01557           if (!ignoredu.map)
01558             map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
01559           if (s->obsoletes)
01560             {
01561               Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
01562               while ((obs = *obsp++) != 0)
01563                 FOR_PROVIDES(op, opp, obs)
01564                   if (op >= oldinstalled->start && op < oldinstalled->end)
01565                     MAPSET(&ignoredu, op - oldinstalled->start);
01566             }
01567           FOR_PROVIDES(op, opp, s->name)
01568             if (pool->solvables[op].name == s->name)
01569               if (op >= oldinstalled->start && op < oldinstalled->end)
01570                 MAPSET(&ignoredu, op - oldinstalled->start);
01571         }
01572     }
01573   cbd.addsub = -1;
01574   if (oldinstalled)
01575     {
01576       /* assumes we allways have du data for installed solvables */
01577       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
01578         {
01579           if (MAPTST(installedmap, sp))
01580             continue;
01581           if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
01582             continue;
01583           repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
01584         }
01585     }
01586   if (ignoredu.map)
01587     map_free(&ignoredu);
01588   sat_free(cbd.dirmap);
01589   sat_free(mptree);
01590 }
01591 
01592 int
01593 pool_calc_installsizechange(Pool *pool, Map *installedmap)
01594 {
01595   Id sp;
01596   Solvable *s;
01597   int change = 0;
01598   Repo *oldinstalled = pool->installed;
01599 
01600   for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
01601     {
01602       if (!s->repo || (oldinstalled && s->repo == oldinstalled))
01603         continue;
01604       if (!MAPTST(installedmap, sp))
01605         continue;
01606       change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
01607     }
01608   if (oldinstalled)
01609     {
01610       FOR_REPO_SOLVABLES(oldinstalled, sp, s)
01611         {
01612           if (MAPTST(installedmap, sp))
01613             continue;
01614           change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
01615         }
01616     }
01617   return change;
01618 }
01619 
01620 /* map:
01621  *  1: installed
01622  *  2: conflicts with installed
01623  *  8: interesting (only true if installed)
01624  * 16: undecided
01625  */
01626  
01627 static inline Id dep2name(Pool *pool, Id dep)
01628 {
01629   while (ISRELDEP(dep))
01630     {
01631       Reldep *rd = rd = GETRELDEP(pool, dep);
01632       dep = rd->name;
01633     }
01634   return dep;
01635 }
01636 
01637 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con) 
01638 {
01639   Id p, pp;
01640   Solvable *sn = pool->solvables + n; 
01641 
01642   FOR_PROVIDES(p, pp, sn->name)
01643     {    
01644       Solvable *s = pool->solvables + p; 
01645       if (s->name != sn->name || s->arch != sn->arch)
01646         continue;
01647       if ((map[p] & 9) != 9)
01648         continue;
01649       if (pool_match_nevr(pool, pool->solvables + p, con))
01650         continue;
01651       return 1;         /* found installed package that doesn't conflict */
01652     }
01653   return 0;
01654 }
01655 
01656 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
01657 {
01658   Id p, pp;
01659   int r = 0;
01660   FOR_PROVIDES(p, pp, dep)
01661     {
01662       if (p == SYSTEMSOLVABLE)
01663         return 1;       /* always boring, as never constraining */
01664       if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
01665         continue;
01666       if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
01667         if (providedbyinstalled_multiversion(pool, map, p, dep))
01668           continue;
01669       if ((map[p] & 9) == 9)
01670         return 9;
01671       r |= map[p] & 17;
01672     }
01673   return r;
01674 }
01675 
01676 /*
01677  * pool_trivial_installable - calculate if a set of solvables is
01678  * trivial installable without any other installs/deinstalls of
01679  * packages not belonging to the set.
01680  *
01681  * the state is returned in the result queue:
01682  * 1:  solvable is installable without any other package changes
01683  * 0:  solvable is not installable
01684  * -1: solvable is installable, but doesn't constrain any installed packages
01685  */
01686 
01687 void
01688 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
01689 {
01690   int i, r, m, did;
01691   Id p, *dp, con, *conp, req, *reqp;
01692   unsigned char *map;
01693   Solvable *s;
01694 
01695   map = sat_calloc(pool->nsolvables, 1);
01696   for (p = 1; p < pool->nsolvables; p++)
01697     {
01698       if (!MAPTST(installedmap, p))
01699         continue;
01700       map[p] |= 9;
01701       s = pool->solvables + p;
01702       if (!s->conflicts)
01703         continue;
01704       conp = s->repo->idarraydata + s->conflicts;
01705       while ((con = *conp++) != 0)
01706         {
01707           dp = pool_whatprovides_ptr(pool, con);
01708           for (; *dp; dp++)
01709             map[p] |= 2;        /* XXX: self conflict ? */
01710         }
01711     }
01712   for (i = 0; i < pkgs->count; i++)
01713     map[pkgs->elements[i]] = 16;
01714 
01715   for (i = 0, did = 0; did < pkgs->count; i++, did++)
01716     {
01717       if (i == pkgs->count)
01718         i = 0;
01719       p = pkgs->elements[i];
01720       if ((map[p] & 16) == 0)
01721         continue;
01722       if ((map[p] & 2) != 0)
01723         {
01724           map[p] = 2;
01725           continue;
01726         }
01727       s = pool->solvables + p;
01728       m = 1;
01729       if (s->requires)
01730         {
01731           reqp = s->repo->idarraydata + s->requires;
01732           while ((req = *reqp++) != 0)
01733             {
01734               if (req == SOLVABLE_PREREQMARKER)
01735                 continue;
01736               r = providedbyinstalled(pool, map, req, 0, 0);
01737               if (!r)
01738                 {
01739                   /* decided and miss */
01740                   map[p] = 2;
01741                   did = 0;
01742                   break;
01743                 }
01744               if (r == 16)
01745                 break;  /* undecided */
01746               m |= r;   /* 1 | 9 | 17 */
01747             }
01748           if (req)
01749             continue;
01750           if ((m & 9) == 9)
01751             m = 9;
01752         }
01753       if (s->conflicts)
01754         {
01755           int ispatch = 0;      /* see solver.c patch handling */
01756 
01757           if (!strncmp("patch:", id2str(pool, s->name), 6))
01758             ispatch = 1;
01759           conp = s->repo->idarraydata + s->conflicts;
01760           while ((con = *conp++) != 0)
01761             {
01762               if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
01763                 {
01764                   map[p] = 2;
01765                   did = 0;
01766                   break;
01767                 }
01768               if ((m == 1 || m == 17) && ISRELDEP(con))
01769                 {
01770                   con = dep2name(pool, con);
01771                   if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
01772                     m = 9;
01773                 }
01774             }
01775           if (con)
01776             continue;   /* found a conflict */
01777         }
01778 #if 0
01779       if (s->repo && s->repo != oldinstalled)
01780         {
01781           Id p2, obs, *obsp, *pp;
01782           Solvable *s2;
01783           if (s->obsoletes)
01784             {
01785               obsp = s->repo->idarraydata + s->obsoletes;
01786               while ((obs = *obsp++) != 0)
01787                 {
01788                   if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
01789                     {
01790                       map[p] = 2;
01791                       break;
01792                     }
01793                 }
01794               if (obs)
01795                 continue;
01796             }
01797           FOR_PROVIDES(p2, pp, s->name)
01798             {
01799               s2 = pool->solvables + p2;
01800               if (s2->name == s->name && (map[p2] & 1) != 0)
01801                 {
01802                   map[p] = 2;
01803                   break;
01804                 }
01805             }
01806           if (p2)
01807             continue;
01808         }
01809 #endif
01810       if (m != map[p])
01811         {
01812           map[p] = m;
01813           did = 0;
01814         }
01815     }
01816   queue_free(res);
01817   queue_init_clone(res, pkgs);
01818   for (i = 0; i < pkgs->count; i++)
01819     {
01820       m = map[pkgs->elements[i]];
01821       if ((m & 9) == 9)
01822         r = 1;
01823       else if (m & 1)
01824         r = -1;
01825       else
01826         r = 0;
01827       res->elements[i] = r;
01828     }
01829   free(map);
01830 }
01831 
01832 void
01833 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
01834 {
01835   pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
01836 }
01837 
01838 const char *
01839 pool_lookup_str(Pool *pool, Id entry, Id keyname)
01840 {
01841   if (entry == SOLVID_POS && pool->pos.repo)
01842     return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
01843   if (entry <= 0)
01844     return 0;
01845   return solvable_lookup_str(pool->solvables + entry, keyname);
01846 }
01847 
01848 Id
01849 pool_lookup_id(Pool *pool, Id entry, Id keyname)
01850 {
01851   if (entry == SOLVID_POS && pool->pos.repo)
01852     {
01853       Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
01854       Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
01855       return data->localpool ? repodata_globalize_id(data, id, 1) : id;
01856     }
01857   if (entry <= 0)
01858     return 0;
01859   return solvable_lookup_id(pool->solvables + entry, keyname);
01860 }
01861 
01862 unsigned int
01863 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
01864 {
01865   if (entry == SOLVID_POS && pool->pos.repo)
01866     {
01867       unsigned int value;
01868       if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
01869         return value;
01870       return notfound;
01871     }
01872   if (entry <= 0)
01873     return notfound;
01874   return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
01875 }
01876 
01877 int
01878 pool_lookup_void(Pool *pool, Id entry, Id keyname)
01879 {
01880   if (entry == SOLVID_POS && pool->pos.repo)
01881     return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
01882   if (entry <= 0)
01883     return 0;
01884   return solvable_lookup_void(pool->solvables + entry, keyname);
01885 }
01886 
01887 const unsigned char *
01888 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
01889 {
01890   if (entry == SOLVID_POS && pool->pos.repo)
01891     return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
01892   if (entry <= 0)
01893     return 0;
01894   return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
01895 }
01896 
01897 const char *
01898 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
01899 {
01900   if (entry == SOLVID_POS && pool->pos.repo)
01901     {
01902       const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
01903       return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
01904     }
01905   if (entry <= 0)
01906     return 0;
01907   return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
01908 }
01909 
01910 void
01911 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
01912 {
01913   int hadhashes = pool->relhashtbl ? 1 : 0;
01914   Solvable *s;
01915   Id fn, p, q, md5;
01916   Id id;
01917   int i;
01918 
01919   if (!conflicts->count)
01920     return;
01921   pool_freewhatprovides(pool);
01922   for (i = 0; i < conflicts->count; i += 5)
01923     {
01924       fn = conflicts->elements[i];
01925       p = conflicts->elements[i + 1];
01926       md5 = conflicts->elements[i + 2];
01927       q = conflicts->elements[i + 3];
01928       id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
01929       s = pool->solvables + p;
01930       if (!s->repo)
01931         continue;
01932       s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
01933       s = pool->solvables + q;
01934       if (!s->repo)
01935         continue;
01936       s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
01937     }
01938   if (!hadhashes)
01939     pool_freeidhashes(pool);
01940 }
01941 
01942 /* EOF */

Generated on Mon Dec 15 17:56:24 2014 for satsolver by  doxygen 1.5.6