2 * Copyright (c) 2007-2009, 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 #ifdef DEBIAN_SEMANTICS
640 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_COMPARE)))) != 0)
643 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
649 continue; /* no rel match */
650 queue_push(&plist, p);
652 /* make our system solvable provide all unknown rpmlib() stuff */
653 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
654 queue_push(&plist, SYSTEMSOLVABLE);
656 /* add providers to whatprovides */
658 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
660 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
663 return pool->whatprovides_rel[d];
666 /*************************************************************************/
669 pool_debug(Pool *pool, int type, const char *format, ...)
674 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
676 if ((pool->debugmask & type) == 0)
679 va_start(args, format);
680 if (!pool->debugcallback)
682 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
683 vprintf(format, args);
685 vfprintf(stderr, format, args);
688 vsnprintf(buf, sizeof(buf), format, args);
689 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
693 pool_setdebuglevel(Pool *pool, int level)
695 int mask = SAT_DEBUG_RESULT;
697 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
699 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
701 mask |= SAT_DEBUG_PROPAGATE;
703 mask |= SAT_DEBUG_RULE_CREATION;
705 mask |= SAT_DEBUG_SCHUBI;
706 pool->debugmask = mask;
709 /*************************************************************************/
719 #define SEARCHFILES_BLOCK 127
722 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
726 struct searchfiles *csf;
728 while ((dep = *ida++) != 0)
731 while (ISRELDEP(dep))
734 sid = pool->ss.nstrings + GETRELID(dep);
735 if (MAPTST(&csf->seen, sid))
740 MAPSET(&csf->seen, sid);
741 rd = GETRELDEP(pool, dep);
744 else if (rd->flags == REL_NAMESPACE)
746 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
749 if (!csf || MAPTST(&csf->seen, sid))
754 MAPSET(&csf->seen, sid);
763 pool_addfileprovides_dep(pool, ids, csf, isf);
769 if (MAPTST(&csf->seen, dep))
771 MAPSET(&csf->seen, dep);
772 s = id2str(pool, dep);
775 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
776 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
777 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
778 csf->ids[csf->nfiles] = dep;
779 sr = strrchr(s, '/');
780 csf->names[csf->nfiles] = strdup(sr + 1);
781 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
783 strncpy(csf->dirs[csf->nfiles], s, sr - s);
784 csf->dirs[csf->nfiles][sr - s] = 0;
789 struct addfileprovides_cbdata {
801 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
803 struct addfileprovides_cbdata *cbd = cbdata;
806 if (data != cbd->olddata)
808 map_free(&cbd->useddirs);
809 map_init(&cbd->useddirs, data->dirpool.ndirs);
810 for (i = 0; i < cbd->nfiles; i++)
812 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
815 MAPSET(&cbd->useddirs, did);
819 if (!MAPTST(&cbd->useddirs, value->id))
821 for (i = 0; i < cbd->nfiles; i++)
823 if (cbd->dids[i] != value->id)
825 if (!strcmp(cbd->names[i], value->str))
828 if (i == cbd->nfiles)
830 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
835 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
837 Map *provideids = cbdata;
838 if (key->type != REPOKEY_TYPE_IDARRAY)
840 MAPSET(provideids, kv->id);
841 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
846 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
850 Repodata *data = 0, *nextdata;
852 int dataincludes = 0;
856 cbd->nfiles = sf->nfiles;
858 cbd->dirs = sf->dirs;
859 cbd->names = sf->names;
861 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
864 start = repoonly->start;
869 start = 2; /* skip system solvable */
870 end = pool->nsolvables;
872 for (p = start, s = pool->solvables + p; p < end; p++, s++)
874 if (!s->repo || (repoonly && s->repo != repoonly))
876 /* check if p is in (oldrepo,data) */
877 if (s->repo != oldrepo || (data && p >= data->end))
884 /* nope, find new repo/repodata */
885 /* if we don't find a match, set data to the next repodata */
887 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
891 if (data->state != REPODATA_AVAILABLE)
893 for (j = 1; j < data->nkeys; j++)
894 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
896 if (j == data->nkeys)
898 /* great, this repodata contains addedfileprovides */
899 if (!nextdata || nextdata->start > data->start)
901 if (p >= data->start)
904 if (i == s->repo->nrepodata)
905 data = nextdata; /* no direct hit, use next repodata */
908 map_init(&providedids, pool->ss.nstrings);
909 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
910 for (i = 0; i < cbd->nfiles; i++)
911 if (!MAPTST(&providedids, cbd->ids[i]))
913 map_free(&providedids);
914 dataincludes = i == cbd->nfiles;
918 if (data && p >= data->start && dataincludes)
920 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
925 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
929 struct searchfiles sf, isf, *isfp;
930 struct addfileprovides_cbdata cbd;
933 memset(&sf, 0, sizeof(sf));
934 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
935 memset(&isf, 0, sizeof(isf));
936 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
938 isfp = installed ? &isf : 0;
939 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
945 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
947 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
949 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
951 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
953 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
955 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
957 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
961 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
962 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
964 map_init(&cbd.useddirs, 1);
970 for (i = 0; i < sf.nfiles; i++)
971 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
973 pool_addfileprovides_search(pool, &cbd, &sf, 0);
976 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
977 sf.ids[sf.nfiles] = 0;
982 for (i = 0; i < sf.nfiles; i++)
984 sat_free(sf.dirs[i]);
985 sat_free(sf.names[i]);
993 for (i = 0; i < isf.nfiles; i++)
994 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
997 pool_addfileprovides_search(pool, &cbd, &isf, installed);
999 for (i = 0; i < isf.nfiles; i++)
1001 sat_free(isf.dirs[i]);
1002 sat_free(isf.names[i]);
1005 sat_free(isf.names);
1007 map_free(&cbd.useddirs);
1009 pool_freewhatprovides(pool); /* as we have added provides */
1013 pool_addfileprovides(Pool *pool)
1015 pool_addfileprovides_ids(pool, pool->installed, 0);
1019 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)
1023 if (pool->solvables[p].repo)
1024 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1027 /* FIXME: obey callback return value! */
1028 for (p = 1; p < pool->nsolvables; p++)
1029 if (pool->solvables[p].repo)
1030 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1034 pool_clear_pos(Pool *pool)
1036 memset(&pool->pos, 0, sizeof(pool->pos));
1041 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1045 pool->languagecache = sat_free(pool->languagecache);
1046 pool->languagecacheother = 0;
1047 if (pool->nlanguages)
1049 for (i = 0; i < pool->nlanguages; i++)
1050 free((char *)pool->languages[i]);
1051 free(pool->languages);
1053 pool->nlanguages = nlanguages;
1056 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1057 for (i = 0; i < pool->nlanguages; i++)
1058 pool->languages[i] = strdup(languages[i]);
1062 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1070 n = id2str(pool, id);
1071 l = strlen(n) + strlen(lang) + 2;
1072 if (l > sizeof(buf))
1073 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1076 sprintf(p, "%s:%s", n, lang);
1077 id = str2id(pool, p, create);
1084 pool_alloctmpspace(Pool *pool, int len)
1086 int n = pool->tmpspacen;
1089 if (len > pool->tmpspacelen[n])
1091 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1092 pool->tmpspacelen[n] = len + 32;
1094 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1095 return pool->tmpspacebuf[n];
1098 /*******************************************************************/
1110 struct mptree *mptree;
1121 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1123 struct ducbdata *cbd = cbdata;
1126 if (data != cbd->olddata)
1128 Id dn, mp, comp, *dirmap, *dirs;
1130 const char *compstr;
1131 struct mptree *mptree;
1133 /* create map from dir to mptree */
1134 cbd->dirmap = sat_free(cbd->dirmap);
1136 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1137 mptree = cbd->mptree;
1139 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1153 if (!mptree[mp].child)
1158 if (data->localpool)
1159 compstr = stringpool_id2str(&data->spool, comp);
1161 compstr = id2str(data->repo->pool, comp);
1162 compl = strlen(compstr);
1163 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1164 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1166 dirmap[dn] = i ? i : -mp;
1168 /* change dirmap to point to mountpoint instead of mptree */
1169 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1172 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1174 cbd->dirmap = dirmap;
1175 cbd->nmap = data->dirpool.ndirs;
1176 cbd->olddata = data;
1179 if (value->id < 0 || value->id >= cbd->nmap)
1181 mp = cbd->dirmap[value->id];
1184 if (cbd->addsub > 0)
1186 cbd->mps[mp].kbytes += value->num;
1187 cbd->mps[mp].files += value->num2;
1191 cbd->mps[mp].kbytes -= value->num;
1192 cbd->mps[mp].files -= value->num2;
1198 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1201 if (mptree[pos].mountpoint == -1)
1202 mptree[pos].mountpoint = mountpoint;
1204 mountpoint = mptree[pos].mountpoint;
1205 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1206 propagate_mountpoints(mptree, i, mountpoint);
1209 #define MPTREE_BLOCK 15
1212 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1215 const char *path, *compstr;
1216 struct mptree *mptree;
1220 struct ducbdata cbd;
1224 Repo *oldinstalled = pool->installed;
1226 memset(&ignoredu, 0, sizeof(ignoredu));
1233 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1236 mptree[0].sibling = 0;
1237 mptree[0].child = 0;
1239 mptree[0].compl = 0;
1240 mptree[0].mountpoint = -1;
1243 /* create component tree */
1244 for (mp = 0; mp < nmps; mp++)
1249 path = mps[mp].path;
1254 if ((p = strchr(path, '/')) == 0)
1257 compl = strlen(compstr);
1268 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1269 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1273 /* create new node */
1274 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1276 mptree[i].sibling = mptree[pos].child;
1277 mptree[i].child = 0;
1278 mptree[i].comp = compstr;
1279 mptree[i].compl = compl;
1280 mptree[i].mountpoint = -1;
1281 mptree[pos].child = i;
1285 mptree[pos].mountpoint = mp;
1288 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1291 for (i = 0; i < nmptree; i++)
1293 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1294 printf("#%d child: %d\n", i, mptree[i].child);
1295 printf("#%d comp: %s\n", i, mptree[i].comp);
1296 printf("#%d compl: %d\n", i, mptree[i].compl);
1297 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1301 cbd.mptree = mptree;
1303 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1305 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1307 if (!MAPTST(installedmap, sp))
1310 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1311 if (!cbd.hasdu && oldinstalled)
1314 /* no du data available, ignore data of all installed solvables we obsolete */
1316 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1319 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1320 while ((obs = *obsp++) != 0)
1321 FOR_PROVIDES(op, opp, obs)
1322 if (op >= oldinstalled->start && op < oldinstalled->end)
1323 MAPSET(&ignoredu, op - oldinstalled->start);
1325 FOR_PROVIDES(op, opp, s->name)
1326 if (pool->solvables[op].name == s->name)
1327 if (op >= oldinstalled->start && op < oldinstalled->end)
1328 MAPSET(&ignoredu, op - oldinstalled->start);
1334 /* assumes we allways have du data for installed solvables */
1335 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1337 if (MAPTST(installedmap, sp))
1339 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1341 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1345 map_free(&ignoredu);
1346 sat_free(cbd.dirmap);
1351 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1356 Repo *oldinstalled = pool->installed;
1358 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1360 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1362 if (!MAPTST(installedmap, sp))
1364 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1368 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1370 if (MAPTST(installedmap, sp))
1372 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1380 * 2: conflicts with installed
1381 * 8: interesting (only true if installed)
1385 static inline Id dep2name(Pool *pool, Id dep)
1387 while (ISRELDEP(dep))
1389 Reldep *rd = rd = GETRELDEP(pool, dep);
1395 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch)
1399 FOR_PROVIDES(p, pp, dep)
1401 if (p == SYSTEMSOLVABLE)
1402 return 1; /* always boring, as never constraining */
1403 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1405 if ((map[p] & 9) == 9)
1413 * pool_trivial_installable - calculate if a set of solvables is
1414 * trivial installable without any other installs/deinstalls of
1415 * packages not belonging to the set.
1417 * the state is returned in the result queue:
1418 * 1: solvable is installable without any other package changes
1419 * 0: solvable is not installable
1420 * -1: solvable is installable, but doesn't constrain any installed packages
1424 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1427 Id p, *dp, con, *conp, req, *reqp;
1431 map = sat_calloc(pool->nsolvables, 1);
1432 for (p = 1; p < pool->nsolvables; p++)
1434 if (!MAPTST(installedmap, p))
1437 s = pool->solvables + p;
1440 conp = s->repo->idarraydata + s->conflicts;
1441 while ((con = *conp++) != 0)
1443 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
1445 map[p] |= 2; /* XXX: self conflict ? */
1448 for (i = 0; i < pkgs->count; i++)
1449 map[pkgs->elements[i]] = 16;
1451 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1453 if (i == pkgs->count)
1455 p = pkgs->elements[i];
1456 if ((map[p] & 16) == 0)
1458 if ((map[p] & 2) != 0)
1463 s = pool->solvables + p;
1467 reqp = s->repo->idarraydata + s->requires;
1468 while ((req = *reqp++) != 0)
1470 if (req == SOLVABLE_PREREQMARKER)
1472 r = providedbyinstalled(pool, map, req, 0);
1475 /* decided and miss */
1479 m |= r; /* 1 | 9 | 16 | 17 */
1488 int ispatch = 0; /* see solver.c patch handling */
1490 if (!strncmp("patch:", id2str(pool, s->name), 6))
1492 conp = s->repo->idarraydata + s->conflicts;
1493 while ((con = *conp++) != 0)
1495 if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
1500 if ((m == 1 || m == 17) && ISRELDEP(con))
1502 con = dep2name(pool, con);
1503 if ((providedbyinstalled(pool, map, con, ispatch) & 1) != 0)
1508 continue; /* found a conflict */
1511 if (s->repo && s->repo != oldinstalled)
1513 Id p2, obs, *obsp, *pp;
1517 obsp = s->repo->idarraydata + s->obsoletes;
1518 while ((obs = *obsp++) != 0)
1520 if ((providedbyinstalled(pool, map, obs, 0) & 1) != 0)
1529 FOR_PROVIDES(p2, pp, s->name)
1531 s2 = pool->solvables + p2;
1532 if (s2->name == s->name && (map[p2] & 1) != 0)
1549 queue_clone(res, pkgs);
1550 for (i = 0; i < pkgs->count; i++)
1552 m = map[pkgs->elements[i]];
1559 res->elements[i] = r;