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);
136 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
141 oa = pool->whatprovides[*(Id *)ap];
142 ob = pool->whatprovides[*(Id *)bp];
144 return *(Id *)ap - *(Id *)bp;
149 da = pool->whatprovidesdata + oa;
150 db = pool->whatprovidesdata + ob;
152 if ((r = (*da++ - *db++)) != 0)
156 return *(Id *)ap - *(Id *)bp;
160 * pool_shrink_whatprovides - unify whatprovides data
162 * whatprovides_rel must be empty for this to work!
166 pool_shrink_whatprovides(Pool *pool)
170 Id lastid, *last, *dp, *lp;
174 if (pool->ss.nstrings < 3)
176 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
177 for (id = 0; id < pool->ss.nstrings; id++)
179 sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
182 for (i = 1; i < pool->ss.nstrings; i++)
185 o = pool->whatprovides[id];
186 if (o == 0 || o == 1)
188 dp = pool->whatprovidesdata + o;
202 pool->whatprovides[id] = -lastid;
206 last = pool->whatprovidesdata + o;
210 dp = pool->whatprovidesdata + 2;
211 for (id = 1; id < pool->ss.nstrings; id++)
213 o = pool->whatprovides[id];
214 if (o == 0 || o == 1)
221 pool->whatprovides[id] = pool->whatprovides[i];
224 lp = pool->whatprovidesdata + o;
227 pool->whatprovides[id] = dp - pool->whatprovidesdata;
228 while ((*dp++ = *lp++) != 0)
231 o = dp - pool->whatprovidesdata;
232 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
233 if (pool->whatprovidesdataoff == o)
235 r = pool->whatprovidesdataoff - o;
236 pool->whatprovidesdataoff = o;
237 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
238 if (r > pool->whatprovidesdataleft)
239 r = pool->whatprovidesdataleft;
240 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
245 * pool_createwhatprovides()
247 * create hashes over pool of solvables to ease provide lookups
251 pool_createwhatprovides(Pool *pool)
253 int i, num, np, extra;
258 Offset *whatprovides;
259 Id *whatprovidesdata, *d;
260 Repo *installed = pool->installed;
264 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
265 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
267 pool_freeidhashes(pool); /* XXX: should not be here! */
268 pool_freewhatprovides(pool);
269 num = pool->ss.nstrings;
270 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
271 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
273 /* count providers for each name */
274 for (i = 1; i < pool->nsolvables; i++)
277 s = pool->solvables + i;
280 /* we always need the installed solvable in the whatprovides data,
281 otherwise obsoletes/conflicts on them won't work */
282 if (s->repo != installed && !pool_installable(pool, s))
284 pp = s->repo->idarraydata + s->provides;
285 while ((id = *pp++) != ID_NULL)
289 Reldep *rd = GETRELDEP(pool, id);
292 whatprovides[id]++; /* inc count of providers */
296 off = 2; /* first entry is undef, second is empty list */
298 np = 0; /* number of names provided */
299 for (i = 0; i < num; i++, idp++)
302 if (!n) /* no providers */
304 *idp = off; /* move from counts to offsets into whatprovidesdata */
305 off += n + 1; /* make space for all providers + terminating ID_NULL */
306 np++; /* inc # of provider 'slots' */
309 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
311 /* reserve some space for relation data */
312 extra = 2 * pool->nrels;
316 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
318 /* alloc space for all providers + extra */
319 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
321 /* now fill data for all provides */
322 for (i = 1; i < pool->nsolvables; i++)
325 s = pool->solvables + i;
328 if (s->repo != installed && !pool_installable(pool, s))
331 /* for all provides of this solvable */
332 pp = s->repo->idarraydata + s->provides;
333 while ((id = *pp++) != 0)
337 Reldep *rd = GETRELDEP(pool, id);
340 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
344 while (*d) /* find free slot */
346 if (d[-1] == i) /* solvable already tacked at end ? */
347 continue; /* Y: skip, on to next provides */
349 *d = i; /* put solvable Id into data */
352 pool->whatprovidesdata = whatprovidesdata;
353 pool->whatprovidesdataoff = off;
354 pool->whatprovidesdataleft = extra;
355 pool_shrink_whatprovides(pool);
356 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)));
357 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
361 * free all of our whatprovides data
362 * be careful, everything internalized with pool_queuetowhatprovides is
366 pool_freewhatprovides(Pool *pool)
368 pool->whatprovides = sat_free(pool->whatprovides);
369 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
370 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
371 pool->whatprovidesdataoff = 0;
372 pool->whatprovidesdataleft = 0;
376 /******************************************************************************/
379 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
381 * on-demand filling of provider information
382 * move queue data into whatprovidesdata
384 * returns: Offset into whatprovides
388 pool_queuetowhatprovides(Pool *pool, Queue *q)
391 int count = q->count;
393 if (count == 0) /* queue empty -> 1 */
396 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
397 if (pool->whatprovidesdataleft < count + 1)
399 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
400 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
401 pool->whatprovidesdataleft = count + 4096;
404 /* copy queue to next free slot */
405 off = pool->whatprovidesdataoff;
406 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
408 /* adapt count and ID_NULL-terminate */
409 pool->whatprovidesdataoff += count;
410 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
411 pool->whatprovidesdataleft -= count + 1;
417 /*************************************************************************/
419 /* check if a package's nevr matches a dependency */
422 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
424 Reldep *rd = GETRELDEP(pool, d);
427 int flags = rd->flags;
436 return pool_match_nevr(pool, s, name);
438 if (pool_match_nevr(pool, s, name))
440 return pool_match_nevr(pool, s, evr);
443 if (!pool_match_nevr(pool, s, name))
445 return pool_match_nevr(pool, s, evr);
450 if (!pool_match_nevr(pool, s, name))
453 return flags & 2 ? 1 : 0;
458 if (flags != 2 && flags != 5)
460 #ifdef DEBIAN_SEMANTICS
461 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_COMPARE)))) != 0)
464 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
470 /* match two dependencies */
473 pool_match_dep(Pool *pool, Id d1, Id d2)
484 rd2 = GETRELDEP(pool, d2);
485 return pool_match_dep(pool, d1, rd2->name);
487 rd1 = GETRELDEP(pool, d1);
490 return pool_match_dep(pool, rd1->name, d2);
492 rd2 = GETRELDEP(pool, d2);
493 if (!pool_match_dep(pool, rd1->name, rd2->name))
497 if (!pflags || !flags || pflags >= 8 || flags >= 8)
499 if (flags == 7 || pflags == 7)
501 if ((pflags & flags & 5) != 0)
503 if (rd1->evr == rd2->evr)
505 if ((pflags & flags & 2) != 0)
510 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
511 #ifdef DEBIAN_SEMANTICS
512 if ((f & (1 << (1 + evrcmp(pool, rd1->evr, rd2->evr, EVRCMP_COMPARE)))) != 0)
515 if ((f & (1 << (1 + evrcmp(pool, rd1->evr, rd2->evr, EVRCMP_MATCH_RELEASE)))) != 0)
525 * add packages fulfilling the relation to whatprovides array
526 * no exact providers, do range match
531 pool_addrelproviders(Pool *pool, Id d)
533 Reldep *rd = GETRELDEP(pool, d);
539 int flags = rd->flags;
541 Id p, wp, *pp, *pp2, *pp3;
544 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
549 pp = pool_whatprovides_ptr(pool, name);
550 pp2 = pool_whatprovides_ptr(pool, evr);
551 while ((p = *pp++) != 0)
553 for (pp3 = pp2; *pp3;)
556 queue_push(&plist, p);
562 pp = pool_whatprovides_ptr(pool, name);
563 while ((p = *pp++) != 0)
564 queue_push(&plist, p);
565 pp = pool_whatprovides_ptr(pool, evr);
566 while ((p = *pp++) != 0)
567 queue_pushunique(&plist, p);
570 if (name == NAMESPACE_OTHERPROVIDERS)
572 wp = pool_whatprovides(pool, evr);
573 pool->whatprovides_rel[d] = wp;
576 if (pool->nscallback)
578 /* ask callback which packages provide the dependency
580 * 1: the system (aka SYSTEMSOLVABLE)
581 * >1: a set of packages, stored as offset on whatprovidesdata
583 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
587 pool->whatprovides_rel[d] = p;
591 queue_push(&plist, SYSTEMSOLVABLE);
595 /* small hack: make it possible to match <pkg>.src
596 * we have to iterate over the solvables as src packages do not
597 * provide anything, thus they are not indexed in our
598 * whatprovides hash */
602 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
604 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
606 if (pool_match_nevr(pool, s, name))
607 queue_push(&plist, p);
611 wp = pool_whatprovides(pool, name);
612 pp = pool->whatprovidesdata + wp;
613 while ((p = *pp++) != 0)
615 Solvable *s = pool->solvables + p;
617 queue_push(&plist, p);
623 /* all solvables match, no need to create a new list */
624 pool->whatprovides_rel[d] = wp;
628 case REL_FILECONFLICT:
629 pp = pool_whatprovides_ptr(pool, name);
630 while ((p = *pp++) != 0)
632 Id origd = MAKERELDEP(d);
633 Solvable *s = pool->solvables + p;
636 pidp = s->repo->idarraydata + s->provides;
637 while ((pid = *pidp++) != 0)
641 queue_push(&plist, p);
648 /* convert to whatprovides id */
650 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
652 if (flags && flags < 8)
654 pp = pool_whatprovides_ptr(pool, name);
655 while (ISRELDEP(name))
657 rd = GETRELDEP(pool, name);
660 while ((p = *pp++) != 0)
662 Solvable *s = pool->solvables + p;
664 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
668 /* no provides - check nevr */
669 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
670 queue_push(&plist, p);
673 /* solvable p provides name in some rels */
674 pidp = s->repo->idarraydata + s->provides;
675 while ((pid = *pidp++) != 0)
682 #ifdef DEBIAN_SEMANTICS
683 continue; /* unversioned provides can
684 * never match versioned deps */
686 break; /* yes, provides all versions */
690 continue; /* wrong provides name */
691 prd = GETRELDEP(pool, pid);
692 if (prd->name != name)
693 continue; /* wrong provides name */
694 /* right package, both deps are rels */
698 if (flags == 7 || pflags == 7)
699 break; /* included */
700 if ((pflags & flags & 5) != 0)
701 break; /* same direction, match */
705 if ((pflags & flags & 2) != 0)
706 break; /* both have =, match */
710 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
711 #ifdef DEBIAN_SEMANTICS
712 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_COMPARE)))) != 0)
715 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
721 continue; /* no rel match */
722 queue_push(&plist, p);
724 /* make our system solvable provide all unknown rpmlib() stuff */
725 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
726 queue_push(&plist, SYSTEMSOLVABLE);
728 /* add providers to whatprovides */
730 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
732 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
735 return pool->whatprovides_rel[d];
738 /*************************************************************************/
741 pool_debug(Pool *pool, int type, const char *format, ...)
746 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
748 if ((pool->debugmask & type) == 0)
751 va_start(args, format);
752 if (!pool->debugcallback)
754 if ((type & (SAT_FATAL|SAT_ERROR)) == 0 || !(pool->debugmask & SAT_DEBUG_TO_STDERR))
755 vprintf(format, args);
757 vfprintf(stderr, format, args);
760 vsnprintf(buf, sizeof(buf), format, args);
761 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
765 pool_setdebuglevel(Pool *pool, int level)
767 int mask = SAT_DEBUG_RESULT;
769 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
771 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
773 mask |= SAT_DEBUG_PROPAGATE;
775 mask |= SAT_DEBUG_RULE_CREATION;
777 mask |= SAT_DEBUG_SCHUBI;
778 mask |= pool->debugmask & SAT_DEBUG_TO_STDERR; /* keep bit */
779 pool->debugmask = mask;
782 /*************************************************************************/
792 #define SEARCHFILES_BLOCK 127
795 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
799 struct searchfiles *csf;
801 while ((dep = *ida++) != 0)
804 while (ISRELDEP(dep))
807 sid = pool->ss.nstrings + GETRELID(dep);
808 if (MAPTST(&csf->seen, sid))
813 MAPSET(&csf->seen, sid);
814 rd = GETRELDEP(pool, dep);
817 else if (rd->flags == REL_NAMESPACE)
819 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
822 if (!csf || MAPTST(&csf->seen, sid))
827 MAPSET(&csf->seen, sid);
831 else if (rd->flags == REL_FILECONFLICT)
841 pool_addfileprovides_dep(pool, ids, csf, isf);
847 if (MAPTST(&csf->seen, dep))
849 MAPSET(&csf->seen, dep);
850 s = id2str(pool, dep);
853 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
854 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
855 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
856 csf->ids[csf->nfiles] = dep;
857 sr = strrchr(s, '/');
858 csf->names[csf->nfiles] = strdup(sr + 1);
859 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
861 strncpy(csf->dirs[csf->nfiles], s, sr - s);
862 csf->dirs[csf->nfiles][sr - s] = 0;
867 struct addfileprovides_cbdata {
879 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
881 struct addfileprovides_cbdata *cbd = cbdata;
884 if (data != cbd->olddata)
886 map_free(&cbd->useddirs);
887 map_init(&cbd->useddirs, data->dirpool.ndirs);
888 for (i = 0; i < cbd->nfiles; i++)
890 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
893 MAPSET(&cbd->useddirs, did);
897 if (!MAPTST(&cbd->useddirs, value->id))
899 for (i = 0; i < cbd->nfiles; i++)
901 if (cbd->dids[i] != value->id)
903 if (!strcmp(cbd->names[i], value->str))
906 if (i == cbd->nfiles)
908 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
913 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
915 Map *provideids = cbdata;
916 if (key->type != REPOKEY_TYPE_IDARRAY)
918 MAPSET(provideids, kv->id);
919 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
924 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
928 Repodata *data = 0, *nextdata;
930 int dataincludes = 0;
934 cbd->nfiles = sf->nfiles;
936 cbd->dirs = sf->dirs;
937 cbd->names = sf->names;
939 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
942 start = repoonly->start;
947 start = 2; /* skip system solvable */
948 end = pool->nsolvables;
950 for (p = start, s = pool->solvables + p; p < end; p++, s++)
952 if (!s->repo || (repoonly && s->repo != repoonly))
954 /* check if p is in (oldrepo,data) */
955 if (s->repo != oldrepo || (data && p >= data->end))
962 /* nope, find new repo/repodata */
963 /* if we don't find a match, set data to the next repodata */
965 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
969 if (data->state != REPODATA_AVAILABLE)
971 for (j = 1; j < data->nkeys; j++)
972 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
974 if (j == data->nkeys)
976 /* great, this repodata contains addedfileprovides */
977 if (!nextdata || nextdata->start > data->start)
979 if (p >= data->start)
982 if (i == s->repo->nrepodata)
983 data = nextdata; /* no direct hit, use next repodata */
986 map_init(&providedids, pool->ss.nstrings);
987 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
988 for (i = 0; i < cbd->nfiles; i++)
989 if (!MAPTST(&providedids, cbd->ids[i]))
991 map_free(&providedids);
992 dataincludes = i == cbd->nfiles;
996 if (data && p >= data->start && dataincludes)
998 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
1003 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1007 struct searchfiles sf, isf, *isfp;
1008 struct addfileprovides_cbdata cbd;
1011 memset(&sf, 0, sizeof(sf));
1012 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1013 memset(&isf, 0, sizeof(isf));
1014 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1016 isfp = installed ? &isf : 0;
1017 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1023 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1025 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1027 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1029 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1031 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1033 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1035 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1038 map_free(&isf.seen);
1039 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
1040 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
1042 map_init(&cbd.useddirs, 1);
1048 for (i = 0; i < sf.nfiles; i++)
1049 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
1051 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1054 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1055 sf.ids[sf.nfiles] = 0;
1060 for (i = 0; i < sf.nfiles; i++)
1062 sat_free(sf.dirs[i]);
1063 sat_free(sf.names[i]);
1071 for (i = 0; i < isf.nfiles; i++)
1072 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
1075 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1077 for (i = 0; i < isf.nfiles; i++)
1079 sat_free(isf.dirs[i]);
1080 sat_free(isf.names[i]);
1083 sat_free(isf.names);
1085 map_free(&cbd.useddirs);
1087 pool_freewhatprovides(pool); /* as we have added provides */
1091 pool_addfileprovides(Pool *pool)
1093 pool_addfileprovides_ids(pool, pool->installed, 0);
1097 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)
1101 if (pool->solvables[p].repo)
1102 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1105 /* FIXME: obey callback return value! */
1106 for (p = 1; p < pool->nsolvables; p++)
1107 if (pool->solvables[p].repo)
1108 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1112 pool_clear_pos(Pool *pool)
1114 memset(&pool->pos, 0, sizeof(pool->pos));
1119 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1123 pool->languagecache = sat_free(pool->languagecache);
1124 pool->languagecacheother = 0;
1125 if (pool->nlanguages)
1127 for (i = 0; i < pool->nlanguages; i++)
1128 free((char *)pool->languages[i]);
1129 free(pool->languages);
1131 pool->nlanguages = nlanguages;
1134 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1135 for (i = 0; i < pool->nlanguages; i++)
1136 pool->languages[i] = strdup(languages[i]);
1140 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1148 n = id2str(pool, id);
1149 l = strlen(n) + strlen(lang) + 2;
1150 if (l > sizeof(buf))
1151 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1154 sprintf(p, "%s:%s", n, lang);
1155 id = str2id(pool, p, create);
1162 pool_alloctmpspace(Pool *pool, int len)
1164 int n = pool->tmpspacen;
1167 if (len > pool->tmpspacelen[n])
1169 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1170 pool->tmpspacelen[n] = len + 32;
1172 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1173 return pool->tmpspacebuf[n];
1176 /*******************************************************************/
1188 struct mptree *mptree;
1199 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1201 struct ducbdata *cbd = cbdata;
1204 if (data != cbd->olddata)
1206 Id dn, mp, comp, *dirmap, *dirs;
1208 const char *compstr;
1209 struct mptree *mptree;
1211 /* create map from dir to mptree */
1212 cbd->dirmap = sat_free(cbd->dirmap);
1214 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1215 mptree = cbd->mptree;
1217 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1231 if (!mptree[mp].child)
1236 if (data->localpool)
1237 compstr = stringpool_id2str(&data->spool, comp);
1239 compstr = id2str(data->repo->pool, comp);
1240 compl = strlen(compstr);
1241 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1242 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1244 dirmap[dn] = i ? i : -mp;
1246 /* change dirmap to point to mountpoint instead of mptree */
1247 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1250 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1252 cbd->dirmap = dirmap;
1253 cbd->nmap = data->dirpool.ndirs;
1254 cbd->olddata = data;
1257 if (value->id < 0 || value->id >= cbd->nmap)
1259 mp = cbd->dirmap[value->id];
1262 if (cbd->addsub > 0)
1264 cbd->mps[mp].kbytes += value->num;
1265 cbd->mps[mp].files += value->num2;
1269 cbd->mps[mp].kbytes -= value->num;
1270 cbd->mps[mp].files -= value->num2;
1276 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1279 if (mptree[pos].mountpoint == -1)
1280 mptree[pos].mountpoint = mountpoint;
1282 mountpoint = mptree[pos].mountpoint;
1283 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1284 propagate_mountpoints(mptree, i, mountpoint);
1287 #define MPTREE_BLOCK 15
1290 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1293 const char *path, *compstr;
1294 struct mptree *mptree;
1298 struct ducbdata cbd;
1302 Repo *oldinstalled = pool->installed;
1304 memset(&ignoredu, 0, sizeof(ignoredu));
1311 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1314 mptree[0].sibling = 0;
1315 mptree[0].child = 0;
1317 mptree[0].compl = 0;
1318 mptree[0].mountpoint = -1;
1321 /* create component tree */
1322 for (mp = 0; mp < nmps; mp++)
1327 path = mps[mp].path;
1332 if ((p = strchr(path, '/')) == 0)
1335 compl = strlen(compstr);
1346 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1347 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1351 /* create new node */
1352 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1354 mptree[i].sibling = mptree[pos].child;
1355 mptree[i].child = 0;
1356 mptree[i].comp = compstr;
1357 mptree[i].compl = compl;
1358 mptree[i].mountpoint = -1;
1359 mptree[pos].child = i;
1363 mptree[pos].mountpoint = mp;
1366 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1369 for (i = 0; i < nmptree; i++)
1371 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1372 printf("#%d child: %d\n", i, mptree[i].child);
1373 printf("#%d comp: %s\n", i, mptree[i].comp);
1374 printf("#%d compl: %d\n", i, mptree[i].compl);
1375 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1379 cbd.mptree = mptree;
1381 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1383 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1385 if (!MAPTST(installedmap, sp))
1388 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1389 if (!cbd.hasdu && oldinstalled)
1392 /* no du data available, ignore data of all installed solvables we obsolete */
1394 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1397 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1398 while ((obs = *obsp++) != 0)
1399 FOR_PROVIDES(op, opp, obs)
1400 if (op >= oldinstalled->start && op < oldinstalled->end)
1401 MAPSET(&ignoredu, op - oldinstalled->start);
1403 FOR_PROVIDES(op, opp, s->name)
1404 if (pool->solvables[op].name == s->name)
1405 if (op >= oldinstalled->start && op < oldinstalled->end)
1406 MAPSET(&ignoredu, op - oldinstalled->start);
1412 /* assumes we allways have du data for installed solvables */
1413 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1415 if (MAPTST(installedmap, sp))
1417 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1419 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1423 map_free(&ignoredu);
1424 sat_free(cbd.dirmap);
1429 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1434 Repo *oldinstalled = pool->installed;
1436 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1438 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1440 if (!MAPTST(installedmap, sp))
1442 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1446 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1448 if (MAPTST(installedmap, sp))
1450 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1458 * 2: conflicts with installed
1459 * 8: interesting (only true if installed)
1463 static inline Id dep2name(Pool *pool, Id dep)
1465 while (ISRELDEP(dep))
1467 Reldep *rd = rd = GETRELDEP(pool, dep);
1473 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id dep)
1476 Solvable *sn = pool->solvables + n;
1478 FOR_PROVIDES(p, pp, sn->name)
1480 Solvable *s = pool->solvables + p;
1481 if (s->name != sn->name || s->arch != sn->arch)
1483 if ((map[p] & 9) == 9)
1489 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1493 FOR_PROVIDES(p, pp, dep)
1495 if (p == SYSTEMSOLVABLE)
1496 return 1; /* always boring, as never constraining */
1497 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1499 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1500 if (providedbyinstalled_multiversion(pool, map, p, dep))
1502 if ((map[p] & 9) == 9)
1510 * pool_trivial_installable - calculate if a set of solvables is
1511 * trivial installable without any other installs/deinstalls of
1512 * packages not belonging to the set.
1514 * the state is returned in the result queue:
1515 * 1: solvable is installable without any other package changes
1516 * 0: solvable is not installable
1517 * -1: solvable is installable, but doesn't constrain any installed packages
1521 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1524 Id p, *dp, con, *conp, req, *reqp;
1528 map = sat_calloc(pool->nsolvables, 1);
1529 for (p = 1; p < pool->nsolvables; p++)
1531 if (!MAPTST(installedmap, p))
1534 s = pool->solvables + p;
1537 conp = s->repo->idarraydata + s->conflicts;
1538 while ((con = *conp++) != 0)
1540 dp = pool_whatprovides_ptr(pool, con);
1542 map[p] |= 2; /* XXX: self conflict ? */
1545 for (i = 0; i < pkgs->count; i++)
1546 map[pkgs->elements[i]] = 16;
1548 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1550 if (i == pkgs->count)
1552 p = pkgs->elements[i];
1553 if ((map[p] & 16) == 0)
1555 if ((map[p] & 2) != 0)
1560 s = pool->solvables + p;
1564 reqp = s->repo->idarraydata + s->requires;
1565 while ((req = *reqp++) != 0)
1567 if (req == SOLVABLE_PREREQMARKER)
1569 r = providedbyinstalled(pool, map, req, 0, 0);
1572 /* decided and miss */
1576 m |= r; /* 1 | 9 | 16 | 17 */
1585 int ispatch = 0; /* see solver.c patch handling */
1587 if (!strncmp("patch:", id2str(pool, s->name), 6))
1589 conp = s->repo->idarraydata + s->conflicts;
1590 while ((con = *conp++) != 0)
1592 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1597 if ((m == 1 || m == 17) && ISRELDEP(con))
1599 con = dep2name(pool, con);
1600 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1605 continue; /* found a conflict */
1608 if (s->repo && s->repo != oldinstalled)
1610 Id p2, obs, *obsp, *pp;
1614 obsp = s->repo->idarraydata + s->obsoletes;
1615 while ((obs = *obsp++) != 0)
1617 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1626 FOR_PROVIDES(p2, pp, s->name)
1628 s2 = pool->solvables + p2;
1629 if (s2->name == s->name && (map[p2] & 1) != 0)
1646 queue_init_clone(res, pkgs);
1647 for (i = 0; i < pkgs->count; i++)
1649 m = map[pkgs->elements[i]];
1656 res->elements[i] = r;
1662 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1664 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1668 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1670 if (entry == SOLVID_POS && pool->pos.repo)
1671 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1674 return solvable_lookup_str(pool->solvables + entry, keyname);
1678 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1680 if (entry == SOLVID_POS && pool->pos.repo)
1681 return repodata_lookup_id(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1684 return solvable_lookup_id(pool->solvables + entry, keyname);
1688 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1690 if (entry == SOLVID_POS && pool->pos.repo)
1693 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1699 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1703 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1705 if (entry == SOLVID_POS && pool->pos.repo)
1706 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1709 return solvable_lookup_void(pool->solvables + entry, keyname);
1712 const unsigned char *
1713 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1715 if (entry == SOLVID_POS && pool->pos.repo)
1716 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1719 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1723 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1725 if (entry == SOLVID_POS && pool->pos.repo)
1727 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1728 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1732 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1736 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1738 int hadhashes = pool->relhashtbl ? 1 : 0;
1744 if (!conflicts->count)
1746 pool_freewhatprovides(pool);
1747 for (i = 0; i < conflicts->count; i += 5)
1749 fn = conflicts->elements[i];
1750 p = conflicts->elements[i + 1];
1751 md5 = conflicts->elements[i + 2];
1752 q = conflicts->elements[i + 3];
1753 id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1754 s = pool->solvables + p;
1757 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1758 s = pool->solvables + q;
1761 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1764 pool_freeidhashes(pool);