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, "createwhatprovides took %d ms\n", sat_timems(now));
363 * free all of our whatprovides data
364 * be careful, everything internalized with pool_queuetowhatprovides is gone, too
367 pool_freewhatprovides(Pool *pool)
369 pool->whatprovides = sat_free(pool->whatprovides);
370 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
371 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
372 pool->whatprovidesdataoff = 0;
373 pool->whatprovidesdataleft = 0;
377 /******************************************************************************/
380 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
382 * on-demand filling of provider information
383 * move queue data into whatprovidesdata
385 * returns: Offset into whatprovides
389 pool_queuetowhatprovides(Pool *pool, Queue *q)
392 int count = q->count;
394 if (count == 0) /* queue empty -> 1 */
397 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
398 if (pool->whatprovidesdataleft < count + 1)
400 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
401 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
402 pool->whatprovidesdataleft = count + 4096;
405 /* copy queue to next free slot */
406 off = pool->whatprovidesdataoff;
407 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
409 /* adapt count and ID_NULL-terminate */
410 pool->whatprovidesdataoff += count;
411 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
412 pool->whatprovidesdataleft -= count + 1;
418 /*************************************************************************/
420 /* check if a package's nevr matches a dependency */
423 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
425 Reldep *rd = GETRELDEP(pool, d);
428 int flags = rd->flags;
437 return pool_match_nevr(pool, s, name);
439 if (pool_match_nevr(pool, s, name))
441 return pool_match_nevr(pool, s, evr);
444 if (!pool_match_nevr(pool, s, name))
446 return pool_match_nevr(pool, s, evr);
451 if (!pool_match_nevr(pool, s, name))
454 return flags & 2 ? 1 : 0;
459 if (flags != 2 && flags != 5)
461 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
469 * add packages fulfilling the relation to whatprovides array
470 * no exact providers, do range match
475 pool_addrelproviders(Pool *pool, Id d)
477 Reldep *rd = GETRELDEP(pool, d);
483 int flags = rd->flags;
485 Id p, wp, *pp, *pp2, *pp3;
488 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
493 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
494 pp2 = pool->whatprovidesdata + pool_whatprovides(pool, evr);
495 while ((p = *pp++) != 0)
497 for (pp3 = pp2; *pp3;)
500 queue_push(&plist, p);
506 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
507 while ((p = *pp++) != 0)
508 queue_push(&plist, p);
509 pp = pool->whatprovidesdata + pool_whatprovides(pool, evr);
510 while ((p = *pp++) != 0)
511 queue_pushunique(&plist, p);
514 if (name == NAMESPACE_OTHERPROVIDERS)
516 wp = pool_whatprovides(pool, evr);
517 pool->whatprovides_rel[d] = wp;
520 if (pool->nscallback)
522 /* ask callback which packages provide the dependency
524 * 1: the system (aka SYSTEMSOLVABLE)
525 * >1: a set of packages, stored as offset on whatprovidesdata
527 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
531 pool->whatprovides_rel[d] = p;
535 queue_push(&plist, SYSTEMSOLVABLE);
539 /* small hack: make it possible to match <pkg>.src
540 * we have to iterate over the solvables as src packages do not
541 * provide anything, thus they are not indexed in our
542 * whatprovides hash */
546 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
548 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
550 if (pool_match_nevr(pool, s, name))
551 queue_push(&plist, p);
555 wp = pool_whatprovides(pool, name);
556 pp = pool->whatprovidesdata + wp;
557 while ((p = *pp++) != 0)
559 Solvable *s = pool->solvables + p;
561 queue_push(&plist, p);
567 pool->whatprovides_rel[d] = wp;
575 /* convert to whatprovides id */
577 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
579 if (flags && flags < 8)
581 pp = pool->whatprovidesdata + pool_whatprovides(pool, name);
582 while (ISRELDEP(name))
584 rd = GETRELDEP(pool, name);
587 while ((p = *pp++) != 0)
589 Solvable *s = pool->solvables + p;
591 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
595 /* no provides - check nevr */
596 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
597 queue_push(&plist, p);
600 /* solvable p provides name in some rels */
601 pidp = s->repo->idarraydata + s->provides;
602 while ((pid = *pidp++) != 0)
609 #ifdef DEBIAN_SEMANTICS
610 continue; /* unversioned provides can
611 * never match versioned deps */
613 break; /* yes, provides all versions */
617 continue; /* wrong provides name */
618 prd = GETRELDEP(pool, pid);
619 if (prd->name != name)
620 continue; /* wrong provides name */
621 /* right package, both deps are rels */
625 if (flags == 7 || pflags == 7)
626 break; /* included */
627 if ((pflags & flags & 5) != 0)
628 break; /* same direction, match */
632 if ((pflags & flags & 2) != 0)
633 break; /* both have =, match */
637 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
638 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
643 continue; /* no rel match */
644 queue_push(&plist, p);
646 /* make our system solvable provide all unknown rpmlib() stuff */
647 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
648 queue_push(&plist, SYSTEMSOLVABLE);
650 /* add providers to whatprovides */
652 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
654 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
657 return pool->whatprovides_rel[d];
660 /*************************************************************************/
663 pool_debug(Pool *pool, int type, const char *format, ...)
668 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
670 if ((pool->debugmask & type) == 0)
673 va_start(args, format);
674 if (!pool->debugcallback)
676 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
677 vprintf(format, args);
679 vfprintf(stderr, format, args);
682 vsnprintf(buf, sizeof(buf), format, args);
683 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
687 pool_setdebuglevel(Pool *pool, int level)
689 int mask = SAT_DEBUG_RESULT;
691 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
693 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
695 mask |= SAT_DEBUG_PROPAGATE;
697 mask |= SAT_DEBUG_RULE_CREATION;
699 mask |= SAT_DEBUG_SCHUBI;
700 pool->debugmask = mask;
703 /*************************************************************************/
713 #define SEARCHFILES_BLOCK 127
716 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
720 struct searchfiles *csf;
722 while ((dep = *ida++) != 0)
725 while (ISRELDEP(dep))
728 sid = pool->ss.nstrings + GETRELID(dep);
729 if (MAPTST(&csf->seen, sid))
734 MAPSET(&csf->seen, sid);
735 rd = GETRELDEP(pool, dep);
738 else if (rd->flags == REL_NAMESPACE)
740 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
743 if (!csf || MAPTST(&csf->seen, sid))
748 MAPSET(&csf->seen, sid);
757 pool_addfileprovides_dep(pool, ids, csf, isf);
763 if (MAPTST(&csf->seen, dep))
765 MAPSET(&csf->seen, dep);
766 s = id2str(pool, dep);
769 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
770 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
771 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
772 csf->ids[csf->nfiles] = dep;
773 sr = strrchr(s, '/');
774 csf->names[csf->nfiles] = strdup(sr + 1);
775 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
777 strncpy(csf->dirs[csf->nfiles], s, sr - s);
778 csf->dirs[csf->nfiles][sr - s] = 0;
783 struct addfileprovides_cbdata {
795 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
797 struct addfileprovides_cbdata *cbd = cbdata;
800 if (data != cbd->olddata)
802 map_free(&cbd->useddirs);
803 map_init(&cbd->useddirs, data->dirpool.ndirs);
804 for (i = 0; i < cbd->nfiles; i++)
806 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
809 MAPSET(&cbd->useddirs, did);
813 if (!MAPTST(&cbd->useddirs, value->id))
815 for (i = 0; i < cbd->nfiles; i++)
817 if (cbd->dids[i] != value->id)
819 if (!strcmp(cbd->names[i], value->str))
822 if (i == cbd->nfiles)
824 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
829 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
831 Map *provideids = cbdata;
832 if (key->type != REPOKEY_TYPE_IDARRAY)
834 MAPSET(provideids, kv->id);
835 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
840 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
844 Repodata *data = 0, *nextdata;
846 int dataincludes = 0;
850 cbd->nfiles = sf->nfiles;
852 cbd->dirs = sf->dirs;
853 cbd->names = sf->names;
855 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
858 start = repoonly->start;
863 start = 2; /* skip system solvable */
864 end = pool->nsolvables;
866 for (p = start, s = pool->solvables + p; p < end; p++, s++)
868 if (!s->repo || (repoonly && s->repo != repoonly))
870 /* check if p is in (oldrepo,data) */
871 if (s->repo != oldrepo || (data && p >= data->end))
878 /* nope, find new repo/repodata */
879 /* if we don't find a match, set data to the next repodata */
881 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
885 if (data->state != REPODATA_AVAILABLE)
887 for (j = 1; j < data->nkeys; j++)
888 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
890 if (j == data->nkeys)
892 /* great, this repodata contains addedfileprovides */
893 if (!nextdata || nextdata->start > data->start)
895 if (p >= data->start)
898 if (i == s->repo->nrepodata)
899 data = nextdata; /* no direct hit, use next repodata */
902 map_init(&providedids, pool->ss.nstrings);
903 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
904 for (i = 0; i < cbd->nfiles; i++)
905 if (!MAPTST(&providedids, cbd->ids[i]))
907 map_free(&providedids);
908 dataincludes = i == cbd->nfiles;
912 if (data && p >= data->start && dataincludes)
914 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
919 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
923 struct searchfiles sf, isf, *isfp;
924 struct addfileprovides_cbdata cbd;
927 memset(&sf, 0, sizeof(sf));
928 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
929 memset(&isf, 0, sizeof(isf));
930 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
932 isfp = installed ? &isf : 0;
933 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
939 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
941 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
943 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
945 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
947 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
949 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
951 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
955 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
956 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
958 map_init(&cbd.useddirs, 1);
964 for (i = 0; i < sf.nfiles; i++)
965 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
967 pool_addfileprovides_search(pool, &cbd, &sf, 0);
970 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
971 sf.ids[sf.nfiles] = 0;
976 for (i = 0; i < sf.nfiles; i++)
978 sat_free(sf.dirs[i]);
979 sat_free(sf.names[i]);
987 for (i = 0; i < isf.nfiles; i++)
988 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
991 pool_addfileprovides_search(pool, &cbd, &isf, installed);
993 for (i = 0; i < isf.nfiles; i++)
995 sat_free(isf.dirs[i]);
996 sat_free(isf.names[i]);
1001 map_free(&cbd.useddirs);
1003 pool_freewhatprovides(pool); /* as we have added provides */
1007 pool_addfileprovides(Pool *pool)
1009 pool_addfileprovides_ids(pool, pool->installed, 0);
1013 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)
1017 if (pool->solvables[p].repo)
1018 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1021 /* FIXME: obey callback return value! */
1022 for (p = 1; p < pool->nsolvables; p++)
1023 if (pool->solvables[p].repo)
1024 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1028 pool_clear_pos(Pool *pool)
1030 memset(&pool->pos, 0, sizeof(pool->pos));
1035 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1039 pool->languagecache = sat_free(pool->languagecache);
1040 pool->languagecacheother = 0;
1041 if (pool->nlanguages)
1043 for (i = 0; i < pool->nlanguages; i++)
1044 free((char *)pool->languages[i]);
1045 free(pool->languages);
1047 pool->nlanguages = nlanguages;
1050 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1051 for (i = 0; i < pool->nlanguages; i++)
1052 pool->languages[i] = strdup(languages[i]);
1056 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1064 n = id2str(pool, id);
1065 l = strlen(n) + strlen(lang) + 2;
1066 if (l > sizeof(buf))
1067 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1070 sprintf(p, "%s:%s", n, lang);
1071 id = str2id(pool, p, create);
1078 pool_alloctmpspace(Pool *pool, int len)
1080 int n = pool->tmpspacen;
1083 if (len > pool->tmpspacelen[n])
1085 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1086 pool->tmpspacelen[n] = len + 32;
1088 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1089 return pool->tmpspacebuf[n];
1092 /*******************************************************************/
1104 struct mptree *mptree;
1115 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1117 struct ducbdata *cbd = cbdata;
1120 if (data != cbd->olddata)
1122 Id dn, mp, comp, *dirmap, *dirs;
1124 const char *compstr;
1125 struct mptree *mptree;
1127 /* create map from dir to mptree */
1128 cbd->dirmap = sat_free(cbd->dirmap);
1130 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1131 mptree = cbd->mptree;
1133 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1147 if (!mptree[mp].child)
1152 if (data->localpool)
1153 compstr = stringpool_id2str(&data->spool, comp);
1155 compstr = id2str(data->repo->pool, comp);
1156 compl = strlen(compstr);
1157 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1158 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1160 dirmap[dn] = i ? i : -mp;
1162 /* change dirmap to point to mountpoint instead of mptree */
1163 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1166 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1168 cbd->dirmap = dirmap;
1169 cbd->nmap = data->dirpool.ndirs;
1170 cbd->olddata = data;
1173 if (value->id < 0 || value->id >= cbd->nmap)
1175 mp = cbd->dirmap[value->id];
1178 if (cbd->addsub > 0)
1180 cbd->mps[mp].kbytes += value->num;
1181 cbd->mps[mp].files += value->num2;
1185 cbd->mps[mp].kbytes -= value->num;
1186 cbd->mps[mp].files -= value->num2;
1192 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1195 if (mptree[pos].mountpoint == -1)
1196 mptree[pos].mountpoint = mountpoint;
1198 mountpoint = mptree[pos].mountpoint;
1199 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1200 propagate_mountpoints(mptree, i, mountpoint);
1203 #define MPTREE_BLOCK 15
1206 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1209 const char *path, *compstr;
1210 struct mptree *mptree;
1214 struct ducbdata cbd;
1218 Repo *oldinstalled = pool->installed;
1220 memset(&ignoredu, 0, sizeof(ignoredu));
1227 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1230 mptree[0].sibling = 0;
1231 mptree[0].child = 0;
1233 mptree[0].compl = 0;
1234 mptree[0].mountpoint = -1;
1237 /* create component tree */
1238 for (mp = 0; mp < nmps; mp++)
1243 path = mps[mp].path;
1248 if ((p = strchr(path, '/')) == 0)
1251 compl = strlen(compstr);
1262 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1263 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1267 /* create new node */
1268 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1270 mptree[i].sibling = mptree[pos].child;
1271 mptree[i].child = 0;
1272 mptree[i].comp = compstr;
1273 mptree[i].compl = compl;
1274 mptree[i].mountpoint = -1;
1275 mptree[pos].child = i;
1279 mptree[pos].mountpoint = mp;
1282 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1285 for (i = 0; i < nmptree; i++)
1287 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1288 printf("#%d child: %d\n", i, mptree[i].child);
1289 printf("#%d comp: %s\n", i, mptree[i].comp);
1290 printf("#%d compl: %d\n", i, mptree[i].compl);
1291 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1295 cbd.mptree = mptree;
1297 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1299 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1301 if (!MAPTST(installedmap, sp))
1304 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1305 if (!cbd.hasdu && oldinstalled)
1308 /* no du data available, ignore data of all installed solvables we obsolete */
1310 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1313 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1314 while ((obs = *obsp++) != 0)
1315 FOR_PROVIDES(op, opp, obs)
1316 if (op >= oldinstalled->start && op < oldinstalled->end)
1317 MAPSET(&ignoredu, op - oldinstalled->start);
1319 FOR_PROVIDES(op, opp, s->name)
1320 if (pool->solvables[op].name == s->name)
1321 if (op >= oldinstalled->start && op < oldinstalled->end)
1322 MAPSET(&ignoredu, op - oldinstalled->start);
1328 /* assumes we allways have du data for installed solvables */
1329 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1331 if (MAPTST(installedmap, sp))
1333 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1335 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1339 map_free(&ignoredu);
1340 sat_free(cbd.dirmap);
1345 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1350 Repo *oldinstalled = pool->installed;
1352 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1354 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1356 if (!MAPTST(installedmap, sp))
1358 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1362 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1364 if (MAPTST(installedmap, sp))
1366 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1374 * 2: conflicts with installed
1375 * 8: interesting (only true if installed)
1379 static inline Id dep2name(Pool *pool, Id dep)
1381 while (ISRELDEP(dep))
1383 Reldep *rd = rd = GETRELDEP(pool, dep);
1389 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
1393 FOR_PROVIDES(p, pp, dep)
1395 if (p == SYSTEMSOLVABLE)
1396 return 1; /* always boring, as never constraining */
1397 if ((map[p] & 9) == 9)
1405 * pool_trivial_installable - calculate if a set of solvables is
1406 * trivial installable without any other installs/deinstalls of
1407 * packages not belonging to the set.
1409 * the state is returned in the result queue:
1410 * 1: solvable is installable without any other package changes
1411 * 0: solvable is not installable
1412 * -1: solvable is installable, but doesn't constrain any installed packages
1416 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1419 Id p, *dp, con, *conp, req, *reqp;
1423 map = sat_calloc(pool->nsolvables, 1);
1424 for (p = 1; p < pool->nsolvables; p++)
1426 if (!MAPTST(installedmap, p))
1429 s = pool->solvables + p;
1432 conp = s->repo->idarraydata + s->conflicts;
1433 while ((con = *conp++) != 0)
1435 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
1437 map[p] |= 2; /* XXX: self conflict ? */
1440 for (i = 0; i < pkgs->count; i++)
1441 map[pkgs->elements[i]] = 16;
1443 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1445 if (i == pkgs->count)
1447 p = pkgs->elements[i];
1448 if ((map[p] & 16) == 0)
1450 if ((map[p] & 2) != 0)
1455 s = pool->solvables + p;
1459 reqp = s->repo->idarraydata + s->requires;
1460 while ((req = *reqp++) != 0)
1462 if (req == SOLVABLE_PREREQMARKER)
1464 r = providedbyinstalled(pool, map, req);
1467 /* decided and miss */
1471 m |= r; /* 1 | 9 | 16 | 17 */
1480 conp = s->repo->idarraydata + s->conflicts;
1481 while ((con = *conp++) != 0)
1483 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1488 if ((m == 1 || m == 17) && ISRELDEP(con))
1490 con = dep2name(pool, con);
1491 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1496 continue; /* found a conflict */
1499 if (s->repo && s->repo != oldinstalled)
1501 Id p2, obs, *obsp, *pp;
1505 obsp = s->repo->idarraydata + s->obsoletes;
1506 while ((obs = *obsp++) != 0)
1508 if ((providedbyinstalled(pool, map, obs) & 1) != 0)
1517 FOR_PROVIDES(p2, pp, s->name)
1519 s2 = pool->solvables + p2;
1520 if (s2->name == s->name && (map[p2] & 1) != 0)
1537 queue_clone(res, pkgs);
1538 for (i = 0; i < pkgs->count; i++)
1540 m = map[pkgs->elements[i]];
1547 res->elements[i] = r;