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 pool->whatprovides_rel[d] = wp;
631 /* convert to whatprovides id */
633 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
635 if (flags && flags < 8)
637 pp = pool_whatprovides_ptr(pool, name);
638 while (ISRELDEP(name))
640 rd = GETRELDEP(pool, name);
643 while ((p = *pp++) != 0)
645 Solvable *s = pool->solvables + p;
647 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
651 /* no provides - check nevr */
652 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
653 queue_push(&plist, p);
656 /* solvable p provides name in some rels */
657 pidp = s->repo->idarraydata + s->provides;
658 while ((pid = *pidp++) != 0)
665 #ifdef DEBIAN_SEMANTICS
666 continue; /* unversioned provides can
667 * never match versioned deps */
669 break; /* yes, provides all versions */
673 continue; /* wrong provides name */
674 prd = GETRELDEP(pool, pid);
675 if (prd->name != name)
676 continue; /* wrong provides name */
677 /* right package, both deps are rels */
681 if (flags == 7 || pflags == 7)
682 break; /* included */
683 if ((pflags & flags & 5) != 0)
684 break; /* same direction, match */
688 if ((pflags & flags & 2) != 0)
689 break; /* both have =, match */
693 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
694 #ifdef DEBIAN_SEMANTICS
695 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_COMPARE)))) != 0)
698 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
704 continue; /* no rel match */
705 queue_push(&plist, p);
707 /* make our system solvable provide all unknown rpmlib() stuff */
708 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
709 queue_push(&plist, SYSTEMSOLVABLE);
711 /* add providers to whatprovides */
713 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
715 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
718 return pool->whatprovides_rel[d];
721 /*************************************************************************/
724 pool_debug(Pool *pool, int type, const char *format, ...)
729 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
731 if ((pool->debugmask & type) == 0)
734 va_start(args, format);
735 if (!pool->debugcallback)
737 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
738 vprintf(format, args);
740 vfprintf(stderr, format, args);
743 vsnprintf(buf, sizeof(buf), format, args);
744 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
748 pool_setdebuglevel(Pool *pool, int level)
750 int mask = SAT_DEBUG_RESULT;
752 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
754 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
756 mask |= SAT_DEBUG_PROPAGATE;
758 mask |= SAT_DEBUG_RULE_CREATION;
760 mask |= SAT_DEBUG_SCHUBI;
761 pool->debugmask = mask;
764 /*************************************************************************/
774 #define SEARCHFILES_BLOCK 127
777 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
781 struct searchfiles *csf;
783 while ((dep = *ida++) != 0)
786 while (ISRELDEP(dep))
789 sid = pool->ss.nstrings + GETRELID(dep);
790 if (MAPTST(&csf->seen, sid))
795 MAPSET(&csf->seen, sid);
796 rd = GETRELDEP(pool, dep);
799 else if (rd->flags == REL_NAMESPACE)
801 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
804 if (!csf || MAPTST(&csf->seen, sid))
809 MAPSET(&csf->seen, sid);
818 pool_addfileprovides_dep(pool, ids, csf, isf);
824 if (MAPTST(&csf->seen, dep))
826 MAPSET(&csf->seen, dep);
827 s = id2str(pool, dep);
830 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
831 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
832 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
833 csf->ids[csf->nfiles] = dep;
834 sr = strrchr(s, '/');
835 csf->names[csf->nfiles] = strdup(sr + 1);
836 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
838 strncpy(csf->dirs[csf->nfiles], s, sr - s);
839 csf->dirs[csf->nfiles][sr - s] = 0;
844 struct addfileprovides_cbdata {
856 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
858 struct addfileprovides_cbdata *cbd = cbdata;
861 if (data != cbd->olddata)
863 map_free(&cbd->useddirs);
864 map_init(&cbd->useddirs, data->dirpool.ndirs);
865 for (i = 0; i < cbd->nfiles; i++)
867 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
870 MAPSET(&cbd->useddirs, did);
874 if (!MAPTST(&cbd->useddirs, value->id))
876 for (i = 0; i < cbd->nfiles; i++)
878 if (cbd->dids[i] != value->id)
880 if (!strcmp(cbd->names[i], value->str))
883 if (i == cbd->nfiles)
885 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
890 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
892 Map *provideids = cbdata;
893 if (key->type != REPOKEY_TYPE_IDARRAY)
895 MAPSET(provideids, kv->id);
896 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
901 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
905 Repodata *data = 0, *nextdata;
907 int dataincludes = 0;
911 cbd->nfiles = sf->nfiles;
913 cbd->dirs = sf->dirs;
914 cbd->names = sf->names;
916 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
919 start = repoonly->start;
924 start = 2; /* skip system solvable */
925 end = pool->nsolvables;
927 for (p = start, s = pool->solvables + p; p < end; p++, s++)
929 if (!s->repo || (repoonly && s->repo != repoonly))
931 /* check if p is in (oldrepo,data) */
932 if (s->repo != oldrepo || (data && p >= data->end))
939 /* nope, find new repo/repodata */
940 /* if we don't find a match, set data to the next repodata */
942 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
946 if (data->state != REPODATA_AVAILABLE)
948 for (j = 1; j < data->nkeys; j++)
949 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
951 if (j == data->nkeys)
953 /* great, this repodata contains addedfileprovides */
954 if (!nextdata || nextdata->start > data->start)
956 if (p >= data->start)
959 if (i == s->repo->nrepodata)
960 data = nextdata; /* no direct hit, use next repodata */
963 map_init(&providedids, pool->ss.nstrings);
964 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
965 for (i = 0; i < cbd->nfiles; i++)
966 if (!MAPTST(&providedids, cbd->ids[i]))
968 map_free(&providedids);
969 dataincludes = i == cbd->nfiles;
973 if (data && p >= data->start && dataincludes)
975 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
980 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
984 struct searchfiles sf, isf, *isfp;
985 struct addfileprovides_cbdata cbd;
988 memset(&sf, 0, sizeof(sf));
989 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
990 memset(&isf, 0, sizeof(isf));
991 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
993 isfp = installed ? &isf : 0;
994 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1000 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1002 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1004 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1006 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1008 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1010 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1012 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1015 map_free(&isf.seen);
1016 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
1017 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
1019 map_init(&cbd.useddirs, 1);
1025 for (i = 0; i < sf.nfiles; i++)
1026 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
1028 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1031 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1032 sf.ids[sf.nfiles] = 0;
1037 for (i = 0; i < sf.nfiles; i++)
1039 sat_free(sf.dirs[i]);
1040 sat_free(sf.names[i]);
1048 for (i = 0; i < isf.nfiles; i++)
1049 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
1052 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1054 for (i = 0; i < isf.nfiles; i++)
1056 sat_free(isf.dirs[i]);
1057 sat_free(isf.names[i]);
1060 sat_free(isf.names);
1062 map_free(&cbd.useddirs);
1064 pool_freewhatprovides(pool); /* as we have added provides */
1068 pool_addfileprovides(Pool *pool)
1070 pool_addfileprovides_ids(pool, pool->installed, 0);
1074 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)
1078 if (pool->solvables[p].repo)
1079 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1082 /* FIXME: obey callback return value! */
1083 for (p = 1; p < pool->nsolvables; p++)
1084 if (pool->solvables[p].repo)
1085 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1089 pool_clear_pos(Pool *pool)
1091 memset(&pool->pos, 0, sizeof(pool->pos));
1096 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1100 pool->languagecache = sat_free(pool->languagecache);
1101 pool->languagecacheother = 0;
1102 if (pool->nlanguages)
1104 for (i = 0; i < pool->nlanguages; i++)
1105 free((char *)pool->languages[i]);
1106 free(pool->languages);
1108 pool->nlanguages = nlanguages;
1111 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1112 for (i = 0; i < pool->nlanguages; i++)
1113 pool->languages[i] = strdup(languages[i]);
1117 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1125 n = id2str(pool, id);
1126 l = strlen(n) + strlen(lang) + 2;
1127 if (l > sizeof(buf))
1128 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1131 sprintf(p, "%s:%s", n, lang);
1132 id = str2id(pool, p, create);
1139 pool_alloctmpspace(Pool *pool, int len)
1141 int n = pool->tmpspacen;
1144 if (len > pool->tmpspacelen[n])
1146 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1147 pool->tmpspacelen[n] = len + 32;
1149 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1150 return pool->tmpspacebuf[n];
1153 /*******************************************************************/
1165 struct mptree *mptree;
1176 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1178 struct ducbdata *cbd = cbdata;
1181 if (data != cbd->olddata)
1183 Id dn, mp, comp, *dirmap, *dirs;
1185 const char *compstr;
1186 struct mptree *mptree;
1188 /* create map from dir to mptree */
1189 cbd->dirmap = sat_free(cbd->dirmap);
1191 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1192 mptree = cbd->mptree;
1194 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1208 if (!mptree[mp].child)
1213 if (data->localpool)
1214 compstr = stringpool_id2str(&data->spool, comp);
1216 compstr = id2str(data->repo->pool, comp);
1217 compl = strlen(compstr);
1218 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1219 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1221 dirmap[dn] = i ? i : -mp;
1223 /* change dirmap to point to mountpoint instead of mptree */
1224 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1227 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1229 cbd->dirmap = dirmap;
1230 cbd->nmap = data->dirpool.ndirs;
1231 cbd->olddata = data;
1234 if (value->id < 0 || value->id >= cbd->nmap)
1236 mp = cbd->dirmap[value->id];
1239 if (cbd->addsub > 0)
1241 cbd->mps[mp].kbytes += value->num;
1242 cbd->mps[mp].files += value->num2;
1246 cbd->mps[mp].kbytes -= value->num;
1247 cbd->mps[mp].files -= value->num2;
1253 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1256 if (mptree[pos].mountpoint == -1)
1257 mptree[pos].mountpoint = mountpoint;
1259 mountpoint = mptree[pos].mountpoint;
1260 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1261 propagate_mountpoints(mptree, i, mountpoint);
1264 #define MPTREE_BLOCK 15
1267 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1270 const char *path, *compstr;
1271 struct mptree *mptree;
1275 struct ducbdata cbd;
1279 Repo *oldinstalled = pool->installed;
1281 memset(&ignoredu, 0, sizeof(ignoredu));
1288 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1291 mptree[0].sibling = 0;
1292 mptree[0].child = 0;
1294 mptree[0].compl = 0;
1295 mptree[0].mountpoint = -1;
1298 /* create component tree */
1299 for (mp = 0; mp < nmps; mp++)
1304 path = mps[mp].path;
1309 if ((p = strchr(path, '/')) == 0)
1312 compl = strlen(compstr);
1323 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1324 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1328 /* create new node */
1329 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1331 mptree[i].sibling = mptree[pos].child;
1332 mptree[i].child = 0;
1333 mptree[i].comp = compstr;
1334 mptree[i].compl = compl;
1335 mptree[i].mountpoint = -1;
1336 mptree[pos].child = i;
1340 mptree[pos].mountpoint = mp;
1343 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1346 for (i = 0; i < nmptree; i++)
1348 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1349 printf("#%d child: %d\n", i, mptree[i].child);
1350 printf("#%d comp: %s\n", i, mptree[i].comp);
1351 printf("#%d compl: %d\n", i, mptree[i].compl);
1352 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1356 cbd.mptree = mptree;
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))
1365 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1366 if (!cbd.hasdu && oldinstalled)
1369 /* no du data available, ignore data of all installed solvables we obsolete */
1371 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1374 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1375 while ((obs = *obsp++) != 0)
1376 FOR_PROVIDES(op, opp, obs)
1377 if (op >= oldinstalled->start && op < oldinstalled->end)
1378 MAPSET(&ignoredu, op - oldinstalled->start);
1380 FOR_PROVIDES(op, opp, s->name)
1381 if (pool->solvables[op].name == s->name)
1382 if (op >= oldinstalled->start && op < oldinstalled->end)
1383 MAPSET(&ignoredu, op - oldinstalled->start);
1389 /* assumes we allways have du data for installed solvables */
1390 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1392 if (MAPTST(installedmap, sp))
1394 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1396 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1400 map_free(&ignoredu);
1401 sat_free(cbd.dirmap);
1406 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1411 Repo *oldinstalled = pool->installed;
1413 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1415 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1417 if (!MAPTST(installedmap, sp))
1419 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1423 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1425 if (MAPTST(installedmap, sp))
1427 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1435 * 2: conflicts with installed
1436 * 8: interesting (only true if installed)
1440 static inline Id dep2name(Pool *pool, Id dep)
1442 while (ISRELDEP(dep))
1444 Reldep *rd = rd = GETRELDEP(pool, dep);
1450 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id dep)
1453 Solvable *sn = pool->solvables + n;
1455 FOR_PROVIDES(p, pp, sn->name)
1457 Solvable *s = pool->solvables + p;
1458 if (s->name != sn->name || s->arch != sn->arch)
1460 if ((map[p] & 9) == 9)
1466 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1470 FOR_PROVIDES(p, pp, dep)
1472 if (p == SYSTEMSOLVABLE)
1473 return 1; /* always boring, as never constraining */
1474 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1476 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1477 if (providedbyinstalled_multiversion(pool, map, p, dep))
1479 if ((map[p] & 9) == 9)
1487 * pool_trivial_installable - calculate if a set of solvables is
1488 * trivial installable without any other installs/deinstalls of
1489 * packages not belonging to the set.
1491 * the state is returned in the result queue:
1492 * 1: solvable is installable without any other package changes
1493 * 0: solvable is not installable
1494 * -1: solvable is installable, but doesn't constrain any installed packages
1498 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1501 Id p, *dp, con, *conp, req, *reqp;
1505 map = sat_calloc(pool->nsolvables, 1);
1506 for (p = 1; p < pool->nsolvables; p++)
1508 if (!MAPTST(installedmap, p))
1511 s = pool->solvables + p;
1514 conp = s->repo->idarraydata + s->conflicts;
1515 while ((con = *conp++) != 0)
1517 dp = pool_whatprovides_ptr(pool, con);
1519 map[p] |= 2; /* XXX: self conflict ? */
1522 for (i = 0; i < pkgs->count; i++)
1523 map[pkgs->elements[i]] = 16;
1525 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1527 if (i == pkgs->count)
1529 p = pkgs->elements[i];
1530 if ((map[p] & 16) == 0)
1532 if ((map[p] & 2) != 0)
1537 s = pool->solvables + p;
1541 reqp = s->repo->idarraydata + s->requires;
1542 while ((req = *reqp++) != 0)
1544 if (req == SOLVABLE_PREREQMARKER)
1546 r = providedbyinstalled(pool, map, req, 0, 0);
1549 /* decided and miss */
1553 m |= r; /* 1 | 9 | 16 | 17 */
1562 int ispatch = 0; /* see solver.c patch handling */
1564 if (!strncmp("patch:", id2str(pool, s->name), 6))
1566 conp = s->repo->idarraydata + s->conflicts;
1567 while ((con = *conp++) != 0)
1569 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1574 if ((m == 1 || m == 17) && ISRELDEP(con))
1576 con = dep2name(pool, con);
1577 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1582 continue; /* found a conflict */
1585 if (s->repo && s->repo != oldinstalled)
1587 Id p2, obs, *obsp, *pp;
1591 obsp = s->repo->idarraydata + s->obsoletes;
1592 while ((obs = *obsp++) != 0)
1594 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1603 FOR_PROVIDES(p2, pp, s->name)
1605 s2 = pool->solvables + p2;
1606 if (s2->name == s->name && (map[p2] & 1) != 0)
1623 queue_init_clone(res, pkgs);
1624 for (i = 0; i < pkgs->count; i++)
1626 m = map[pkgs->elements[i]];
1633 res->elements[i] = r;
1639 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1641 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);