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);
126 static Pool *pool_shrink_whatprovides_sortcmp_data;
129 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
132 Pool *pool = pool_shrink_whatprovides_sortcmp_data;
134 oa = pool->whatprovides[*(Id *)ap];
135 ob = pool->whatprovides[*(Id *)bp];
137 return *(Id *)ap - *(Id *)bp;
142 da = pool->whatprovidesdata + oa;
143 db = pool->whatprovidesdata + ob;
145 if ((r = (*da++ - *db++)) != 0)
149 return *(Id *)ap - *(Id *)bp;
153 * pool_shrink_whatprovides - unify whatprovides data
155 * whatprovides_rel must be empty for this to work!
159 pool_shrink_whatprovides(Pool *pool)
163 Id lastid, *last, *dp, *lp;
167 if (pool->ss.nstrings < 3)
169 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
170 for (id = 0; id < pool->ss.nstrings; id++)
172 pool_shrink_whatprovides_sortcmp_data = pool;
173 qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
176 for (i = 1; i < pool->ss.nstrings; i++)
179 o = pool->whatprovides[id];
180 if (o == 0 || o == 1)
182 dp = pool->whatprovidesdata + o;
196 pool->whatprovides[id] = -lastid;
200 last = pool->whatprovidesdata + o;
204 dp = pool->whatprovidesdata + 2;
205 for (id = 1; id < pool->ss.nstrings; id++)
207 o = pool->whatprovides[id];
208 if (o == 0 || o == 1)
215 pool->whatprovides[id] = pool->whatprovides[i];
218 lp = pool->whatprovidesdata + o;
221 pool->whatprovides[id] = dp - pool->whatprovidesdata;
222 while ((*dp++ = *lp++) != 0)
225 o = dp - pool->whatprovidesdata;
226 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
227 if (pool->whatprovidesdataoff == o)
229 r = pool->whatprovidesdataoff - o;
230 pool->whatprovidesdataoff = o;
231 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
232 if (r > pool->whatprovidesdataleft)
233 r = pool->whatprovidesdataleft;
234 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
239 * pool_createwhatprovides()
241 * create hashes over pool of solvables to ease provide lookups
245 pool_createwhatprovides(Pool *pool)
247 int i, num, np, extra;
252 Offset *whatprovides;
253 Id *whatprovidesdata, *d;
255 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
256 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
258 pool_freeidhashes(pool); /* XXX: should not be here! */
259 pool_freewhatprovides(pool);
260 num = pool->ss.nstrings;
261 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
262 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
264 /* count providers for each name */
265 for (i = 1; i < pool->nsolvables; i++)
268 s = pool->solvables + i;
271 if (!pool_installable(pool, s))
273 pp = s->repo->idarraydata + s->provides;
274 while ((id = *pp++) != ID_NULL)
278 Reldep *rd = GETRELDEP(pool, id);
281 whatprovides[id]++; /* inc count of providers */
285 off = 2; /* first entry is undef, second is empty list */
287 np = 0; /* number of names provided */
288 for (i = 0; i < num; i++, idp++)
291 if (!n) /* no providers */
293 *idp = off; /* move from counts to offsets into whatprovidesdata */
294 off += n + 1; /* make space for all providers + terminating ID_NULL */
295 np++; /* inc # of provider 'slots' */
298 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
300 /* reserve some space for relation data */
301 extra = 2 * pool->nrels;
305 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
307 /* alloc space for all providers + extra */
308 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
310 /* now fill data for all provides */
311 for (i = 1; i < pool->nsolvables; i++)
314 s = pool->solvables + i;
317 if (!pool_installable(pool, s))
320 /* for all provides of this solvable */
321 pp = s->repo->idarraydata + s->provides;
322 while ((id = *pp++) != 0)
326 Reldep *rd = GETRELDEP(pool, id);
329 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
333 while (*d) /* find free slot */
335 if (d[-1] == i) /* solvable already tacked at end ? */
336 continue; /* Y: skip, on to next provides */
338 *d = i; /* put solvable Id into data */
341 pool->whatprovidesdata = whatprovidesdata;
342 pool->whatprovidesdataoff = off;
343 pool->whatprovidesdataleft = extra;
344 pool_shrink_whatprovides(pool);
348 * free all of our whatprovides data
349 * be careful, everything internalized with pool_queuetowhatprovides is gone, too
352 pool_freewhatprovides(Pool *pool)
354 pool->whatprovides = sat_free(pool->whatprovides);
355 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
356 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
357 pool->whatprovidesdataoff = 0;
358 pool->whatprovidesdataleft = 0;
362 /******************************************************************************/
365 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
367 * on-demand filling of provider information
368 * move queue data into whatprovidesdata
370 * returns: Offset into whatprovides
374 pool_queuetowhatprovides(Pool *pool, Queue *q)
377 int count = q->count;
379 if (count == 0) /* queue empty -> 1 */
382 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
383 if (pool->whatprovidesdataleft < count + 1)
385 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
386 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
387 pool->whatprovidesdataleft = count + 4096;
390 /* copy queue to next free slot */
391 off = pool->whatprovidesdataoff;
392 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
394 /* adapt count and ID_NULL-terminate */
395 pool->whatprovidesdataoff += count;
396 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
397 pool->whatprovidesdataleft -= count + 1;
403 /*************************************************************************/
405 /* check if a package's nevr matches a dependency */
408 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
410 Reldep *rd = GETRELDEP(pool, d);
413 int flags = rd->flags;
422 return pool_match_nevr(pool, s, name);
424 if (pool_match_nevr(pool, s, name))
426 return pool_match_nevr(pool, s, evr);
429 if (!pool_match_nevr(pool, s, name))
431 return pool_match_nevr(pool, s, evr);
436 if (!pool_match_nevr(pool, s, name))
439 return flags & 2 ? 1 : 0;
444 if (flags != 2 && flags != 5)
446 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
454 * add packages fulfilling the relation to whatprovides array
455 * no exact providers, do range match
460 pool_addrelproviders(Pool *pool, Id d)
462 Reldep *rd = GETRELDEP(pool, d);
468 int flags = rd->flags;
470 Id p, wp, *pp, *pp2, *pp3;
473 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
478 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
479 pp2 = pool->whatprovidesdata + pool_whatprovides(pool, evr);
480 while ((p = *pp++) != 0)
482 for (pp3 = pp2; *pp3;)
485 queue_push(&plist, p);
491 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
492 while ((p = *pp++) != 0)
493 queue_push(&plist, p);
494 pp = pool->whatprovidesdata + pool_whatprovides(pool, evr);
495 while ((p = *pp++) != 0)
496 queue_pushunique(&plist, p);
499 if (name == NAMESPACE_OTHERPROVIDERS)
501 wp = pool_whatprovides(pool, evr);
502 pool->whatprovides_rel[d] = wp;
505 if (pool->nscallback)
507 /* ask callback which packages provide the dependency
509 * 1: the system (aka SYSTEMSOLVABLE)
510 * >1: a set of packages, stored as offset on whatprovidesdata
512 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
516 pool->whatprovides_rel[d] = p;
520 queue_push(&plist, SYSTEMSOLVABLE);
524 /* small hack: make it possible to match <pkg>.src
525 * we have to iterate over the solvables as src packages do not
526 * provide anything, thus they are not indexed in our
527 * whatprovides hash */
531 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
533 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
535 if (pool_match_nevr(pool, s, name))
536 queue_push(&plist, p);
540 wp = pool_whatprovides(pool, name);
541 pp = pool->whatprovidesdata + wp;
542 while ((p = *pp++) != 0)
544 Solvable *s = pool->solvables + p;
546 queue_push(&plist, p);
552 pool->whatprovides_rel[d] = wp;
560 /* convert to whatprovides id */
562 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
564 if (flags && flags < 8)
566 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
567 while (ISRELDEP(name))
569 rd = GETRELDEP(pool, name);
572 while ((p = *pp++) != 0)
574 Solvable *s = pool->solvables + p;
576 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
580 /* no provides - check nevr */
581 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
582 queue_push(&plist, p);
585 /* solvable p provides name in some rels */
586 pidp = s->repo->idarraydata + s->provides;
587 while ((pid = *pidp++) != 0)
594 #ifdef DEBIAN_SEMANTICS
595 continue; /* unversioned provides can
596 * never match versioned deps */
598 break; /* yes, provides all versions */
602 continue; /* wrong provides name */
603 prd = GETRELDEP(pool, pid);
604 if (prd->name != name)
605 continue; /* wrong provides name */
606 /* right package, both deps are rels */
610 if (flags == 7 || pflags == 7)
611 break; /* included */
612 if ((pflags & flags & 5) != 0)
613 break; /* same direction, match */
617 if ((pflags & flags & 2) != 0)
618 break; /* both have =, match */
622 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
623 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
628 continue; /* no rel match */
629 queue_push(&plist, p);
631 /* make our system solvable provide all unknown rpmlib() stuff */
632 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
633 queue_push(&plist, SYSTEMSOLVABLE);
635 /* add providers to whatprovides */
637 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
639 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
642 return pool->whatprovides_rel[d];
645 /*************************************************************************/
648 pool_debug(Pool *pool, int type, const char *format, ...)
653 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
655 if ((pool->debugmask & type) == 0)
658 va_start(args, format);
659 if (!pool->debugcallback)
661 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
662 vprintf(format, args);
664 vfprintf(stderr, format, args);
667 vsnprintf(buf, sizeof(buf), format, args);
668 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
672 pool_setdebuglevel(Pool *pool, int level)
674 int mask = SAT_DEBUG_RESULT;
676 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
678 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
680 mask |= SAT_DEBUG_PROPAGATE;
682 mask |= SAT_DEBUG_RULE_CREATION;
684 mask |= SAT_DEBUG_SCHUBI;
685 pool->debugmask = mask;
688 /*************************************************************************/
698 #define SEARCHFILES_BLOCK 127
701 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
705 struct searchfiles *csf;
707 while ((dep = *ida++) != 0)
710 while (ISRELDEP(dep))
713 sid = pool->ss.nstrings + GETRELID(dep);
714 if (MAPTST(&csf->seen, sid))
719 MAPSET(&csf->seen, sid);
720 rd = GETRELDEP(pool, dep);
723 else if (rd->flags == REL_NAMESPACE)
725 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
728 if (!csf || MAPTST(&csf->seen, sid))
733 MAPSET(&csf->seen, sid);
742 pool_addfileprovides_dep(pool, ids, csf, isf);
748 if (MAPTST(&csf->seen, dep))
750 MAPSET(&csf->seen, dep);
751 s = id2str(pool, dep);
754 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
755 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
756 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
757 csf->ids[csf->nfiles] = dep;
758 sr = strrchr(s, '/');
759 csf->names[csf->nfiles] = strdup(sr + 1);
760 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
762 strncpy(csf->dirs[csf->nfiles], s, sr - s);
763 csf->dirs[csf->nfiles][sr - s] = 0;
768 struct addfileprovides_cbdata {
780 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
782 struct addfileprovides_cbdata *cbd = cbdata;
785 if (data != cbd->olddata)
787 map_free(&cbd->useddirs);
788 map_init(&cbd->useddirs, data->dirpool.ndirs);
789 for (i = 0; i < cbd->nfiles; i++)
791 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
794 MAPSET(&cbd->useddirs, did);
798 if (!MAPTST(&cbd->useddirs, value->id))
800 for (i = 0; i < cbd->nfiles; i++)
802 if (cbd->dids[i] != value->id)
804 if (!strcmp(cbd->names[i], value->str))
807 if (i == cbd->nfiles)
809 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
814 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
816 Map *provideids = cbdata;
817 if (key->type != REPOKEY_TYPE_IDARRAY)
819 MAPSET(provideids, kv->id);
820 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
825 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
829 Repodata *data = 0, *nextdata;
831 int dataincludes = 0;
835 cbd->nfiles = sf->nfiles;
837 cbd->dirs = sf->dirs;
838 cbd->names = sf->names;
840 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
843 start = repoonly->start;
848 start = 2; /* skip system solvable */
849 end = pool->nsolvables;
851 for (p = start, s = pool->solvables + p; p < end; p++, s++)
853 if (!s->repo || (repoonly && s->repo != repoonly))
855 /* check if p is in (oldrepo,data) */
856 if (s->repo != oldrepo || (data && p >= data->end))
863 /* nope, find new repo/repodata */
864 /* if we don't find a match, set data to the next repodata */
866 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
870 if (data->state != REPODATA_AVAILABLE)
872 for (j = 1; j < data->nkeys; j++)
873 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
875 if (j == data->nkeys)
877 /* great, this repodata contains addedfileprovides */
878 if (!nextdata || nextdata->start > data->start)
880 if (p >= data->start)
883 if (i == s->repo->nrepodata)
884 data = nextdata; /* no direct hit, use next repodata */
887 map_init(&providedids, pool->ss.nstrings);
888 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, addfileprovides_setid_cb, &providedids);
889 for (i = 0; i < cbd->nfiles; i++)
890 if (!MAPTST(&providedids, cbd->ids[i]))
892 map_free(&providedids);
893 dataincludes = i == cbd->nfiles;
897 if (data && p >= data->start && dataincludes)
899 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
904 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
908 struct searchfiles sf, isf, *isfp;
909 struct addfileprovides_cbdata cbd;
912 memset(&sf, 0, sizeof(sf));
913 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
914 memset(&isf, 0, sizeof(isf));
915 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
917 isfp = installed ? &isf : 0;
918 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
924 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
926 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
928 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
930 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
932 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
934 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
936 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
940 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
941 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
943 map_init(&cbd.useddirs, 1);
949 for (i = 0; i < sf.nfiles; i++)
950 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
952 pool_addfileprovides_search(pool, &cbd, &sf, 0);
955 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
956 sf.ids[sf.nfiles] = 0;
961 for (i = 0; i < sf.nfiles; i++)
963 sat_free(sf.dirs[i]);
964 sat_free(sf.names[i]);
972 for (i = 0; i < isf.nfiles; i++)
973 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
976 pool_addfileprovides_search(pool, &cbd, &isf, installed);
978 for (i = 0; i < isf.nfiles; i++)
980 sat_free(isf.dirs[i]);
981 sat_free(isf.names[i]);
986 map_free(&cbd.useddirs);
988 pool_freewhatprovides(pool); /* as we have added provides */
992 pool_addfileprovides(Pool *pool, Repo *installed)
994 pool_addfileprovides_ids(pool, installed, 0);
998 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)
1002 if (pool->solvables[p].repo)
1003 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1006 /* FIXME: obey callback return value! */
1007 for (p = 1; p < pool->nsolvables; p++)
1008 if (pool->solvables[p].repo)
1009 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1014 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1018 pool->languagecache = sat_free(pool->languagecache);
1019 pool->languagecacheother = 0;
1020 if (pool->nlanguages)
1022 for (i = 0; i < pool->nlanguages; i++)
1023 free((char *)pool->languages[i]);
1024 free(pool->languages);
1026 pool->nlanguages = nlanguages;
1029 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1030 for (i = 0; i < pool->nlanguages; i++)
1031 pool->languages[i] = strdup(languages[i]);
1035 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1043 n = id2str(pool, id);
1044 l = strlen(n) + strlen(lang) + 2;
1045 if (l > sizeof(buf))
1046 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1049 sprintf(p, "%s:%s", n, lang);
1050 id = str2id(pool, p, create);
1057 pool_alloctmpspace(Pool *pool, int len)
1059 int n = pool->tmpspacen;
1062 if (len > pool->tmpspacelen[n])
1064 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1065 pool->tmpspacelen[n] = len + 32;
1067 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1068 return pool->tmpspacebuf[n];
1071 /*******************************************************************/
1083 struct mptree *mptree;
1094 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1096 struct ducbdata *cbd = cbdata;
1099 if (data != cbd->olddata)
1101 Id dn, mp, comp, *dirmap, *dirs;
1103 const char *compstr;
1104 struct mptree *mptree;
1106 /* create map from dir to mptree */
1107 cbd->dirmap = sat_free(cbd->dirmap);
1109 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1110 mptree = cbd->mptree;
1112 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1126 if (!mptree[mp].child)
1131 if (data->localpool)
1132 compstr = stringpool_id2str(&data->spool, comp);
1134 compstr = id2str(data->repo->pool, comp);
1135 compl = strlen(compstr);
1136 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1137 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1139 dirmap[dn] = i ? i : -mp;
1141 /* change dirmap to point to mountpoint instead of mptree */
1142 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1145 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1147 cbd->dirmap = dirmap;
1148 cbd->nmap = data->dirpool.ndirs;
1149 cbd->olddata = data;
1152 if (value->id < 0 || value->id >= cbd->nmap)
1154 mp = cbd->dirmap[value->id];
1157 if (cbd->addsub > 0)
1159 cbd->mps[mp].kbytes += value->num;
1160 cbd->mps[mp].files += value->num2;
1164 cbd->mps[mp].kbytes -= value->num;
1165 cbd->mps[mp].files -= value->num2;
1171 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1174 if (mptree[pos].mountpoint == -1)
1175 mptree[pos].mountpoint = mountpoint;
1177 mountpoint = mptree[pos].mountpoint;
1178 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1179 propagate_mountpoints(mptree, i, mountpoint);
1182 #define MPTREE_BLOCK 15
1185 pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges *mps, int nmps)
1188 const char *path, *compstr;
1189 struct mptree *mptree;
1193 struct ducbdata cbd;
1198 memset(&ignoredu, 0, sizeof(ignoredu));
1205 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1208 mptree[0].sibling = 0;
1209 mptree[0].child = 0;
1211 mptree[0].compl = 0;
1212 mptree[0].mountpoint = -1;
1215 /* create component tree */
1216 for (mp = 0; mp < nmps; mp++)
1221 path = mps[mp].path;
1226 if ((p = strchr(path, '/')) == 0)
1229 compl = strlen(compstr);
1240 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1241 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1245 /* create new node */
1246 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1248 mptree[i].sibling = mptree[pos].child;
1249 mptree[i].child = 0;
1250 mptree[i].comp = compstr;
1251 mptree[i].compl = compl;
1252 mptree[i].mountpoint = -1;
1253 mptree[pos].child = i;
1257 mptree[pos].mountpoint = mp;
1260 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1263 for (i = 0; i < nmptree; i++)
1265 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1266 printf("#%d child: %d\n", i, mptree[i].child);
1267 printf("#%d comp: %s\n", i, mptree[i].comp);
1268 printf("#%d compl: %d\n", i, mptree[i].compl);
1269 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1273 cbd.mptree = mptree;
1275 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1277 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1279 if (!MAPTST(installedmap, sp))
1282 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1283 if (!cbd.hasdu && oldinstalled)
1286 /* no du data available, ignore data of all installed solvables we obsolete */
1288 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1291 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1292 while ((obs = *obsp++) != 0)
1293 FOR_PROVIDES(op, opp, obs)
1294 if (op >= oldinstalled->start && op < oldinstalled->end)
1295 MAPSET(&ignoredu, op - oldinstalled->start);
1297 FOR_PROVIDES(op, opp, s->name)
1298 if (pool->solvables[op].name == s->name)
1299 if (op >= oldinstalled->start && op < oldinstalled->end)
1300 MAPSET(&ignoredu, op - oldinstalled->start);
1306 /* assumes we allways have du data for installed solvables */
1307 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1309 if (MAPTST(installedmap, sp))
1311 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1313 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1317 map_free(&ignoredu);
1318 sat_free(cbd.dirmap);
1323 pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
1329 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1331 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1333 if (!MAPTST(installedmap, sp))
1335 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1339 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1341 if (MAPTST(installedmap, sp))
1343 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1351 * 2: conflicts with installed
1352 * 8: interesting (only true if installed)
1356 static inline Id dep2name(Pool *pool, Id dep)
1358 while (ISRELDEP(dep))
1360 Reldep *rd = rd = GETRELDEP(pool, dep);
1366 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
1370 FOR_PROVIDES(p, pp, dep)
1372 if (p == SYSTEMSOLVABLE)
1373 return 1; /* always boring, as never constraining */
1374 if ((map[p] & 9) == 9)
1382 * pool_trivial_installable - calculate if a set of solvables is
1383 * trivial installable without any other installs/deinstalls of
1384 * packages not belonging to the set.
1386 * the state is returned in the result queue:
1387 * 1: solvable is installable without any other package changes
1388 * 0: solvable is not installable
1389 * -1: solvable is installable, but doesn't constrain any installed packages
1393 pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queue *pkgs, Queue *res)
1396 Id p, *dp, con, *conp, req, *reqp;
1400 map = sat_calloc(pool->nsolvables, 1);
1401 for (p = 1; p < pool->nsolvables; p++)
1403 if (!MAPTST(installedmap, p))
1406 s = pool->solvables + p;
1409 conp = s->repo->idarraydata + s->conflicts;
1410 while ((con = *conp++) != 0)
1412 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
1414 map[p] |= 2; /* XXX: self conflict ? */
1417 for (i = 0; i < pkgs->count; i++)
1418 map[pkgs->elements[i]] = 16;
1420 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1422 if (i == pkgs->count)
1424 p = pkgs->elements[i];
1425 if ((map[p] & 16) == 0)
1427 if ((map[p] & 2) != 0)
1432 s = pool->solvables + p;
1436 reqp = s->repo->idarraydata + s->requires;
1437 while ((req = *reqp++) != 0)
1439 if (req == SOLVABLE_PREREQMARKER)
1441 r = providedbyinstalled(pool, map, req);
1444 /* decided and miss */
1448 m |= r; /* 1 | 9 | 16 | 17 */
1457 conp = s->repo->idarraydata + s->conflicts;
1458 while ((con = *conp++) != 0)
1460 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1465 if ((m == 1 || m == 17) && ISRELDEP(con))
1467 con = dep2name(pool, con);
1468 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1473 continue; /* found a conflict */
1476 if (s->repo && s->repo != oldinstalled)
1478 Id p2, obs, *obsp, *pp;
1482 obsp = s->repo->idarraydata + s->obsoletes;
1483 while ((obs = *obsp++) != 0)
1485 if ((providedbyinstalled(pool, map, obs) & 1) != 0)
1494 FOR_PROVIDES(p2, pp, s->name)
1496 s2 = pool->solvables + p2;
1497 if (s2->name == s->name && (map[p2] & 1) != 0)
1514 queue_clone(res, pkgs);
1515 for (i = 0; i < pkgs->count; i++)
1517 m = map[pkgs->elements[i]];
1524 res->elements[i] = r;