2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * The pool contains information about solvables
12 * stored optimized for memory consumption and fast retrieval.
24 #include "poolid_private.h"
30 #define SOLVABLE_BLOCK 255
32 #define KNOWNID_INITIALIZE
34 #undef KNOWNID_INITIALIZE
43 pool = (Pool *)sat_calloc(1, sizeof(*pool));
45 stringpool_init (&pool->ss, initpool_data);
47 /* alloc space for RelDep 0 */
48 pool->rels = sat_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
50 memset(pool->rels, 0, sizeof(Reldep));
52 /* alloc space for Solvable 0 and system solvable */
53 pool->solvables = sat_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
55 memset(pool->solvables, 0, 2 * sizeof(Solvable));
56 s = pool->solvables + SYSTEMSOLVABLE;
57 s->name = SYSTEM_SYSTEM;
58 s->arch = ARCH_NOARCH;
61 queue_init(&pool->vendormap);
63 pool->debugmask = SAT_DEBUG_RESULT; /* FIXME */
68 /* free all the resources of our pool */
74 pool_freewhatprovides(pool);
75 pool_freeidhashes(pool);
76 repo_freeallrepos(pool, 1);
77 sat_free(pool->id2arch);
78 sat_free(pool->solvables);
79 stringpool_free(&pool->ss);
81 queue_free(&pool->vendormap);
82 for (i = 0; i < POOL_TMPSPACEBUF; i++)
83 sat_free(pool->tmpspacebuf[i]);
84 for (i = 0; i < pool->nlanguages; i++)
85 free((char *)pool->languages[i]);
86 sat_free(pool->languages);
87 sat_free(pool->languagecache);
92 pool_add_solvable(Pool *pool)
94 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
95 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
96 return pool->nsolvables++;
100 pool_add_solvable_block(Pool *pool, int count)
102 Id nsolvables = pool->nsolvables;
105 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
106 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
107 pool->nsolvables += count;
112 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
116 if (reuseids && start + count == pool->nsolvables)
118 /* might want to shrink solvable array */
119 pool->nsolvables = start;
122 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
127 pool_set_installed(Pool *pool, Repo *installed)
129 if (pool->installed == installed)
131 pool->installed = installed;
132 pool_freewhatprovides(pool);
135 static Pool *pool_shrink_whatprovides_sortcmp_data;
138 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
141 Pool *pool = pool_shrink_whatprovides_sortcmp_data;
143 oa = pool->whatprovides[*(Id *)ap];
144 ob = pool->whatprovides[*(Id *)bp];
146 return *(Id *)ap - *(Id *)bp;
151 da = pool->whatprovidesdata + oa;
152 db = pool->whatprovidesdata + ob;
154 if ((r = (*da++ - *db++)) != 0)
158 return *(Id *)ap - *(Id *)bp;
162 * pool_shrink_whatprovides - unify whatprovides data
164 * whatprovides_rel must be empty for this to work!
168 pool_shrink_whatprovides(Pool *pool)
172 Id lastid, *last, *dp, *lp;
176 if (pool->ss.nstrings < 3)
178 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
179 for (id = 0; id < pool->ss.nstrings; id++)
181 pool_shrink_whatprovides_sortcmp_data = pool;
182 qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
185 for (i = 1; i < pool->ss.nstrings; i++)
188 o = pool->whatprovides[id];
189 if (o == 0 || o == 1)
191 dp = pool->whatprovidesdata + o;
205 pool->whatprovides[id] = -lastid;
209 last = pool->whatprovidesdata + o;
213 dp = pool->whatprovidesdata + 2;
214 for (id = 1; id < pool->ss.nstrings; id++)
216 o = pool->whatprovides[id];
217 if (o == 0 || o == 1)
224 pool->whatprovides[id] = pool->whatprovides[i];
227 lp = pool->whatprovidesdata + o;
230 pool->whatprovides[id] = dp - pool->whatprovidesdata;
231 while ((*dp++ = *lp++) != 0)
234 o = dp - pool->whatprovidesdata;
235 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
236 if (pool->whatprovidesdataoff == o)
238 r = pool->whatprovidesdataoff - o;
239 pool->whatprovidesdataoff = o;
240 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
241 if (r > pool->whatprovidesdataleft)
242 r = pool->whatprovidesdataleft;
243 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
248 * pool_createwhatprovides()
250 * create hashes over pool of solvables to ease provide lookups
254 pool_createwhatprovides(Pool *pool)
256 int i, num, np, extra;
261 Offset *whatprovides;
262 Id *whatprovidesdata, *d;
263 Repo *installed = pool->installed;
267 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
268 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
270 pool_freeidhashes(pool); /* XXX: should not be here! */
271 pool_freewhatprovides(pool);
272 num = pool->ss.nstrings;
273 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
274 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
276 /* count providers for each name */
277 for (i = 1; i < pool->nsolvables; i++)
280 s = pool->solvables + i;
283 /* we always need the installed solvable in the whatprovides data,
284 otherwise obsoletes/conflicts on them won't work */
285 if (s->repo != installed && !pool_installable(pool, s))
287 pp = s->repo->idarraydata + s->provides;
288 while ((id = *pp++) != ID_NULL)
292 Reldep *rd = GETRELDEP(pool, id);
295 whatprovides[id]++; /* inc count of providers */
299 off = 2; /* first entry is undef, second is empty list */
301 np = 0; /* number of names provided */
302 for (i = 0; i < num; i++, idp++)
305 if (!n) /* no providers */
307 *idp = off; /* move from counts to offsets into whatprovidesdata */
308 off += n + 1; /* make space for all providers + terminating ID_NULL */
309 np++; /* inc # of provider 'slots' */
312 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
314 /* reserve some space for relation data */
315 extra = 2 * pool->nrels;
319 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
321 /* alloc space for all providers + extra */
322 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
324 /* now fill data for all provides */
325 for (i = 1; i < pool->nsolvables; i++)
328 s = pool->solvables + i;
331 if (s->repo != installed && !pool_installable(pool, s))
334 /* for all provides of this solvable */
335 pp = s->repo->idarraydata + s->provides;
336 while ((id = *pp++) != 0)
340 Reldep *rd = GETRELDEP(pool, id);
343 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
347 while (*d) /* find free slot */
349 if (d[-1] == i) /* solvable already tacked at end ? */
350 continue; /* Y: skip, on to next provides */
352 *d = i; /* put solvable Id into data */
355 pool->whatprovidesdata = whatprovidesdata;
356 pool->whatprovidesdataoff = off;
357 pool->whatprovidesdataleft = extra;
358 pool_shrink_whatprovides(pool);
359 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)));
360 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
364 * free all of our whatprovides data
365 * be careful, everything internalized with pool_queuetowhatprovides is gone, too
368 pool_freewhatprovides(Pool *pool)
370 pool->whatprovides = sat_free(pool->whatprovides);
371 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
372 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
373 pool->whatprovidesdataoff = 0;
374 pool->whatprovidesdataleft = 0;
378 /******************************************************************************/
381 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
383 * on-demand filling of provider information
384 * move queue data into whatprovidesdata
386 * returns: Offset into whatprovides
390 pool_queuetowhatprovides(Pool *pool, Queue *q)
393 int count = q->count;
395 if (count == 0) /* queue empty -> 1 */
398 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
399 if (pool->whatprovidesdataleft < count + 1)
401 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
402 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
403 pool->whatprovidesdataleft = count + 4096;
406 /* copy queue to next free slot */
407 off = pool->whatprovidesdataoff;
408 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
410 /* adapt count and ID_NULL-terminate */
411 pool->whatprovidesdataoff += count;
412 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
413 pool->whatprovidesdataleft -= count + 1;
419 /*************************************************************************/
421 /* check if a package's nevr matches a dependency */
424 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
426 Reldep *rd = GETRELDEP(pool, d);
429 int flags = rd->flags;
438 return pool_match_nevr(pool, s, name);
440 if (pool_match_nevr(pool, s, name))
442 return pool_match_nevr(pool, s, evr);
445 if (!pool_match_nevr(pool, s, name))
447 return pool_match_nevr(pool, s, evr);
452 if (!pool_match_nevr(pool, s, name))
455 return flags & 2 ? 1 : 0;
460 if (flags != 2 && flags != 5)
462 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
470 * add packages fulfilling the relation to whatprovides array
471 * no exact providers, do range match
476 pool_addrelproviders(Pool *pool, Id d)
478 Reldep *rd = GETRELDEP(pool, d);
484 int flags = rd->flags;
486 Id p, wp, *pp, *pp2, *pp3;
489 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
494 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
495 pp2 = pool->whatprovidesdata + pool_whatprovides(pool, evr);
496 while ((p = *pp++) != 0)
498 for (pp3 = pp2; *pp3;)
501 queue_push(&plist, p);
507 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
508 while ((p = *pp++) != 0)
509 queue_push(&plist, p);
510 pp = pool->whatprovidesdata + pool_whatprovides(pool, evr);
511 while ((p = *pp++) != 0)
512 queue_pushunique(&plist, p);
515 if (name == NAMESPACE_OTHERPROVIDERS)
517 wp = pool_whatprovides(pool, evr);
518 pool->whatprovides_rel[d] = wp;
521 if (pool->nscallback)
523 /* ask callback which packages provide the dependency
525 * 1: the system (aka SYSTEMSOLVABLE)
526 * >1: a set of packages, stored as offset on whatprovidesdata
528 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
532 pool->whatprovides_rel[d] = p;
536 queue_push(&plist, SYSTEMSOLVABLE);
540 /* small hack: make it possible to match <pkg>.src
541 * we have to iterate over the solvables as src packages do not
542 * provide anything, thus they are not indexed in our
543 * whatprovides hash */
547 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
549 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
551 if (pool_match_nevr(pool, s, name))
552 queue_push(&plist, p);
556 wp = pool_whatprovides(pool, name);
557 pp = pool->whatprovidesdata + wp;
558 while ((p = *pp++) != 0)
560 Solvable *s = pool->solvables + p;
562 queue_push(&plist, p);
568 pool->whatprovides_rel[d] = wp;
576 /* convert to whatprovides id */
578 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
580 if (flags && flags < 8)
582 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
583 while (ISRELDEP(name))
585 rd = GETRELDEP(pool, name);
588 while ((p = *pp++) != 0)
590 Solvable *s = pool->solvables + p;
592 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
596 /* no provides - check nevr */
597 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
598 queue_push(&plist, p);
601 /* solvable p provides name in some rels */
602 pidp = s->repo->idarraydata + s->provides;
603 while ((pid = *pidp++) != 0)
610 #ifdef DEBIAN_SEMANTICS
611 continue; /* unversioned provides can
612 * never match versioned deps */
614 break; /* yes, provides all versions */
618 continue; /* wrong provides name */
619 prd = GETRELDEP(pool, pid);
620 if (prd->name != name)
621 continue; /* wrong provides name */
622 /* right package, both deps are rels */
626 if (flags == 7 || pflags == 7)
627 break; /* included */
628 if ((pflags & flags & 5) != 0)
629 break; /* same direction, match */
633 if ((pflags & flags & 2) != 0)
634 break; /* both have =, match */
638 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
639 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
644 continue; /* no rel match */
645 queue_push(&plist, p);
647 /* make our system solvable provide all unknown rpmlib() stuff */
648 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
649 queue_push(&plist, SYSTEMSOLVABLE);
651 /* add providers to whatprovides */
653 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
655 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
658 return pool->whatprovides_rel[d];
661 /*************************************************************************/
664 pool_debug(Pool *pool, int type, const char *format, ...)
669 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
671 if ((pool->debugmask & type) == 0)
674 va_start(args, format);
675 if (!pool->debugcallback)
677 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
678 vprintf(format, args);
680 vfprintf(stderr, format, args);
683 vsnprintf(buf, sizeof(buf), format, args);
684 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
688 pool_setdebuglevel(Pool *pool, int level)
690 int mask = SAT_DEBUG_RESULT;
692 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
694 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
696 mask |= SAT_DEBUG_PROPAGATE;
698 mask |= SAT_DEBUG_RULE_CREATION;
700 mask |= SAT_DEBUG_SCHUBI;
701 pool->debugmask = mask;
704 /*************************************************************************/
714 #define SEARCHFILES_BLOCK 127
717 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
721 struct searchfiles *csf;
723 while ((dep = *ida++) != 0)
726 while (ISRELDEP(dep))
729 sid = pool->ss.nstrings + GETRELID(dep);
730 if (MAPTST(&csf->seen, sid))
735 MAPSET(&csf->seen, sid);
736 rd = GETRELDEP(pool, dep);
739 else if (rd->flags == REL_NAMESPACE)
741 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
744 if (!csf || MAPTST(&csf->seen, sid))
749 MAPSET(&csf->seen, sid);
758 pool_addfileprovides_dep(pool, ids, csf, isf);
764 if (MAPTST(&csf->seen, dep))
766 MAPSET(&csf->seen, dep);
767 s = id2str(pool, dep);
770 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
771 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
772 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
773 csf->ids[csf->nfiles] = dep;
774 sr = strrchr(s, '/');
775 csf->names[csf->nfiles] = strdup(sr + 1);
776 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
778 strncpy(csf->dirs[csf->nfiles], s, sr - s);
779 csf->dirs[csf->nfiles][sr - s] = 0;
784 struct addfileprovides_cbdata {
796 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
798 struct addfileprovides_cbdata *cbd = cbdata;
801 if (data != cbd->olddata)
803 map_free(&cbd->useddirs);
804 map_init(&cbd->useddirs, data->dirpool.ndirs);
805 for (i = 0; i < cbd->nfiles; i++)
807 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
810 MAPSET(&cbd->useddirs, did);
814 if (!MAPTST(&cbd->useddirs, value->id))
816 for (i = 0; i < cbd->nfiles; i++)
818 if (cbd->dids[i] != value->id)
820 if (!strcmp(cbd->names[i], value->str))
823 if (i == cbd->nfiles)
825 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
830 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
832 Map *provideids = cbdata;
833 if (key->type != REPOKEY_TYPE_IDARRAY)
835 MAPSET(provideids, kv->id);
836 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
841 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
845 Repodata *data = 0, *nextdata;
847 int dataincludes = 0;
851 cbd->nfiles = sf->nfiles;
853 cbd->dirs = sf->dirs;
854 cbd->names = sf->names;
856 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
859 start = repoonly->start;
864 start = 2; /* skip system solvable */
865 end = pool->nsolvables;
867 for (p = start, s = pool->solvables + p; p < end; p++, s++)
869 if (!s->repo || (repoonly && s->repo != repoonly))
871 /* check if p is in (oldrepo,data) */
872 if (s->repo != oldrepo || (data && p >= data->end))
879 /* nope, find new repo/repodata */
880 /* if we don't find a match, set data to the next repodata */
882 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
886 if (data->state != REPODATA_AVAILABLE)
888 for (j = 1; j < data->nkeys; j++)
889 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
891 if (j == data->nkeys)
893 /* great, this repodata contains addedfileprovides */
894 if (!nextdata || nextdata->start > data->start)
896 if (p >= data->start)
899 if (i == s->repo->nrepodata)
900 data = nextdata; /* no direct hit, use next repodata */
903 map_init(&providedids, pool->ss.nstrings);
904 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
905 for (i = 0; i < cbd->nfiles; i++)
906 if (!MAPTST(&providedids, cbd->ids[i]))
908 map_free(&providedids);
909 dataincludes = i == cbd->nfiles;
913 if (data && p >= data->start && dataincludes)
915 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
920 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
924 struct searchfiles sf, isf, *isfp;
925 struct addfileprovides_cbdata cbd;
928 memset(&sf, 0, sizeof(sf));
929 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
930 memset(&isf, 0, sizeof(isf));
931 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
933 isfp = installed ? &isf : 0;
934 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
940 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
942 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
944 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
946 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
948 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
950 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
952 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
956 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
957 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
959 map_init(&cbd.useddirs, 1);
965 for (i = 0; i < sf.nfiles; i++)
966 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
968 pool_addfileprovides_search(pool, &cbd, &sf, 0);
971 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
972 sf.ids[sf.nfiles] = 0;
977 for (i = 0; i < sf.nfiles; i++)
979 sat_free(sf.dirs[i]);
980 sat_free(sf.names[i]);
988 for (i = 0; i < isf.nfiles; i++)
989 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
992 pool_addfileprovides_search(pool, &cbd, &isf, installed);
994 for (i = 0; i < isf.nfiles; i++)
996 sat_free(isf.dirs[i]);
997 sat_free(isf.names[i]);
1000 sat_free(isf.names);
1002 map_free(&cbd.useddirs);
1004 pool_freewhatprovides(pool); /* as we have added provides */
1008 pool_addfileprovides(Pool *pool)
1010 pool_addfileprovides_ids(pool, pool->installed, 0);
1014 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)
1018 if (pool->solvables[p].repo)
1019 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1022 /* FIXME: obey callback return value! */
1023 for (p = 1; p < pool->nsolvables; p++)
1024 if (pool->solvables[p].repo)
1025 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1029 pool_clear_pos(Pool *pool)
1031 memset(&pool->pos, 0, sizeof(pool->pos));
1036 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1040 pool->languagecache = sat_free(pool->languagecache);
1041 pool->languagecacheother = 0;
1042 if (pool->nlanguages)
1044 for (i = 0; i < pool->nlanguages; i++)
1045 free((char *)pool->languages[i]);
1046 free(pool->languages);
1048 pool->nlanguages = nlanguages;
1051 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1052 for (i = 0; i < pool->nlanguages; i++)
1053 pool->languages[i] = strdup(languages[i]);
1057 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1065 n = id2str(pool, id);
1066 l = strlen(n) + strlen(lang) + 2;
1067 if (l > sizeof(buf))
1068 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1071 sprintf(p, "%s:%s", n, lang);
1072 id = str2id(pool, p, create);
1079 pool_alloctmpspace(Pool *pool, int len)
1081 int n = pool->tmpspacen;
1084 if (len > pool->tmpspacelen[n])
1086 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1087 pool->tmpspacelen[n] = len + 32;
1089 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1090 return pool->tmpspacebuf[n];
1093 /*******************************************************************/
1105 struct mptree *mptree;
1116 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1118 struct ducbdata *cbd = cbdata;
1121 if (data != cbd->olddata)
1123 Id dn, mp, comp, *dirmap, *dirs;
1125 const char *compstr;
1126 struct mptree *mptree;
1128 /* create map from dir to mptree */
1129 cbd->dirmap = sat_free(cbd->dirmap);
1131 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1132 mptree = cbd->mptree;
1134 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1148 if (!mptree[mp].child)
1153 if (data->localpool)
1154 compstr = stringpool_id2str(&data->spool, comp);
1156 compstr = id2str(data->repo->pool, comp);
1157 compl = strlen(compstr);
1158 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1159 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1161 dirmap[dn] = i ? i : -mp;
1163 /* change dirmap to point to mountpoint instead of mptree */
1164 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1167 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1169 cbd->dirmap = dirmap;
1170 cbd->nmap = data->dirpool.ndirs;
1171 cbd->olddata = data;
1174 if (value->id < 0 || value->id >= cbd->nmap)
1176 mp = cbd->dirmap[value->id];
1179 if (cbd->addsub > 0)
1181 cbd->mps[mp].kbytes += value->num;
1182 cbd->mps[mp].files += value->num2;
1186 cbd->mps[mp].kbytes -= value->num;
1187 cbd->mps[mp].files -= value->num2;
1193 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1196 if (mptree[pos].mountpoint == -1)
1197 mptree[pos].mountpoint = mountpoint;
1199 mountpoint = mptree[pos].mountpoint;
1200 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1201 propagate_mountpoints(mptree, i, mountpoint);
1204 #define MPTREE_BLOCK 15
1207 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1210 const char *path, *compstr;
1211 struct mptree *mptree;
1215 struct ducbdata cbd;
1219 Repo *oldinstalled = pool->installed;
1221 memset(&ignoredu, 0, sizeof(ignoredu));
1228 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1231 mptree[0].sibling = 0;
1232 mptree[0].child = 0;
1234 mptree[0].compl = 0;
1235 mptree[0].mountpoint = -1;
1238 /* create component tree */
1239 for (mp = 0; mp < nmps; mp++)
1244 path = mps[mp].path;
1249 if ((p = strchr(path, '/')) == 0)
1252 compl = strlen(compstr);
1263 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1264 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1268 /* create new node */
1269 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1271 mptree[i].sibling = mptree[pos].child;
1272 mptree[i].child = 0;
1273 mptree[i].comp = compstr;
1274 mptree[i].compl = compl;
1275 mptree[i].mountpoint = -1;
1276 mptree[pos].child = i;
1280 mptree[pos].mountpoint = mp;
1283 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1286 for (i = 0; i < nmptree; i++)
1288 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1289 printf("#%d child: %d\n", i, mptree[i].child);
1290 printf("#%d comp: %s\n", i, mptree[i].comp);
1291 printf("#%d compl: %d\n", i, mptree[i].compl);
1292 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1296 cbd.mptree = mptree;
1298 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1300 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1302 if (!MAPTST(installedmap, sp))
1305 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1306 if (!cbd.hasdu && oldinstalled)
1309 /* no du data available, ignore data of all installed solvables we obsolete */
1311 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1314 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1315 while ((obs = *obsp++) != 0)
1316 FOR_PROVIDES(op, opp, obs)
1317 if (op >= oldinstalled->start && op < oldinstalled->end)
1318 MAPSET(&ignoredu, op - oldinstalled->start);
1320 FOR_PROVIDES(op, opp, s->name)
1321 if (pool->solvables[op].name == s->name)
1322 if (op >= oldinstalled->start && op < oldinstalled->end)
1323 MAPSET(&ignoredu, op - oldinstalled->start);
1329 /* assumes we allways have du data for installed solvables */
1330 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1332 if (MAPTST(installedmap, sp))
1334 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1336 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1340 map_free(&ignoredu);
1341 sat_free(cbd.dirmap);
1346 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1351 Repo *oldinstalled = pool->installed;
1353 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1355 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1357 if (!MAPTST(installedmap, sp))
1359 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1363 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1365 if (MAPTST(installedmap, sp))
1367 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1375 * 2: conflicts with installed
1376 * 8: interesting (only true if installed)
1380 static inline Id dep2name(Pool *pool, Id dep)
1382 while (ISRELDEP(dep))
1384 Reldep *rd = rd = GETRELDEP(pool, dep);
1390 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch)
1394 FOR_PROVIDES(p, pp, dep)
1396 if (p == SYSTEMSOLVABLE)
1397 return 1; /* always boring, as never constraining */
1398 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1400 if ((map[p] & 9) == 9)
1408 * pool_trivial_installable - calculate if a set of solvables is
1409 * trivial installable without any other installs/deinstalls of
1410 * packages not belonging to the set.
1412 * the state is returned in the result queue:
1413 * 1: solvable is installable without any other package changes
1414 * 0: solvable is not installable
1415 * -1: solvable is installable, but doesn't constrain any installed packages
1419 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1422 Id p, *dp, con, *conp, req, *reqp;
1426 map = sat_calloc(pool->nsolvables, 1);
1427 for (p = 1; p < pool->nsolvables; p++)
1429 if (!MAPTST(installedmap, p))
1432 s = pool->solvables + p;
1435 conp = s->repo->idarraydata + s->conflicts;
1436 while ((con = *conp++) != 0)
1438 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
1440 map[p] |= 2; /* XXX: self conflict ? */
1443 for (i = 0; i < pkgs->count; i++)
1444 map[pkgs->elements[i]] = 16;
1446 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1448 if (i == pkgs->count)
1450 p = pkgs->elements[i];
1451 if ((map[p] & 16) == 0)
1453 if ((map[p] & 2) != 0)
1458 s = pool->solvables + p;
1462 reqp = s->repo->idarraydata + s->requires;
1463 while ((req = *reqp++) != 0)
1465 if (req == SOLVABLE_PREREQMARKER)
1467 r = providedbyinstalled(pool, map, req, 0);
1470 /* decided and miss */
1474 m |= r; /* 1 | 9 | 16 | 17 */
1483 int ispatch = 0; /* see solver.c patch handling */
1485 if (!strncmp("patch:", id2str(pool, s->name), 6))
1487 conp = s->repo->idarraydata + s->conflicts;
1488 while ((con = *conp++) != 0)
1490 if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
1495 if ((m == 1 || m == 17) && ISRELDEP(con))
1497 con = dep2name(pool, con);
1498 if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
1503 continue; /* found a conflict */
1506 if (s->repo && s->repo != oldinstalled)
1508 Id p2, obs, *obsp, *pp;
1512 obsp = s->repo->idarraydata + s->obsoletes;
1513 while ((obs = *obsp++) != 0)
1515 if ((providedbyinstalled(pool, map, obs, 0) & 1) != 0)
1524 FOR_PROVIDES(p2, pp, s->name)
1526 s2 = pool->solvables + p2;
1527 if (s2->name == s->name && (map[p2] & 1) != 0)
1544 queue_clone(res, pkgs);
1545 for (i = 0; i < pkgs->count; i++)
1547 m = map[pkgs->elements[i]];
1554 res->elements[i] = r;