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 */
65 pool->obsoleteusescolors = 1;
68 pool->allowselfconflicts = 1;
69 # ifdef MULTI_SEMANTICS
70 pool->disttype = DISTTYPE_DEB;
77 /* free all the resources of our pool */
83 pool_freewhatprovides(pool);
84 pool_freeidhashes(pool);
85 repo_freeallrepos(pool, 1);
86 sat_free(pool->id2arch);
87 sat_free(pool->solvables);
88 stringpool_free(&pool->ss);
90 queue_free(&pool->vendormap);
91 for (i = 0; i < POOL_TMPSPACEBUF; i++)
92 sat_free(pool->tmpspacebuf[i]);
93 for (i = 0; i < pool->nlanguages; i++)
94 free((char *)pool->languages[i]);
95 sat_free(pool->languages);
96 sat_free(pool->languagecache);
100 #ifdef MULTI_SEMANTICS
102 pool_setdisttype(Pool *pool, int disttype)
104 pool->disttype = disttype;
109 pool_add_solvable(Pool *pool)
111 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
112 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
113 return pool->nsolvables++;
117 pool_add_solvable_block(Pool *pool, int count)
119 Id nsolvables = pool->nsolvables;
122 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
123 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
124 pool->nsolvables += count;
129 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
133 if (reuseids && start + count == pool->nsolvables)
135 /* might want to shrink solvable array */
136 pool->nsolvables = start;
139 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
144 pool_set_installed(Pool *pool, Repo *installed)
146 if (pool->installed == installed)
148 pool->installed = installed;
149 pool_freewhatprovides(pool);
153 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
158 oa = pool->whatprovides[*(Id *)ap];
159 ob = pool->whatprovides[*(Id *)bp];
161 return *(Id *)ap - *(Id *)bp;
166 da = pool->whatprovidesdata + oa;
167 db = pool->whatprovidesdata + ob;
169 if ((r = (*da++ - *db++)) != 0)
173 return *(Id *)ap - *(Id *)bp;
177 * pool_shrink_whatprovides - unify whatprovides data
179 * whatprovides_rel must be empty for this to work!
183 pool_shrink_whatprovides(Pool *pool)
187 Id lastid, *last, *dp, *lp;
191 if (pool->ss.nstrings < 3)
193 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
194 for (id = 0; id < pool->ss.nstrings; id++)
196 sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
199 for (i = 1; i < pool->ss.nstrings; i++)
202 o = pool->whatprovides[id];
203 if (o == 0 || o == 1)
205 dp = pool->whatprovidesdata + o;
219 pool->whatprovides[id] = -lastid;
223 last = pool->whatprovidesdata + o;
227 dp = pool->whatprovidesdata + 2;
228 for (id = 1; id < pool->ss.nstrings; id++)
230 o = pool->whatprovides[id];
231 if (o == 0 || o == 1)
238 pool->whatprovides[id] = pool->whatprovides[i];
241 lp = pool->whatprovidesdata + o;
244 pool->whatprovides[id] = dp - pool->whatprovidesdata;
245 while ((*dp++ = *lp++) != 0)
248 o = dp - pool->whatprovidesdata;
249 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
250 if (pool->whatprovidesdataoff == o)
252 r = pool->whatprovidesdataoff - o;
253 pool->whatprovidesdataoff = o;
254 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
255 if (r > pool->whatprovidesdataleft)
256 r = pool->whatprovidesdataleft;
257 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
262 * pool_createwhatprovides()
264 * create hashes over pool of solvables to ease provide lookups
268 pool_createwhatprovides(Pool *pool)
270 int i, num, np, extra;
275 Offset *whatprovides;
276 Id *whatprovidesdata, *d;
277 Repo *installed = pool->installed;
281 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
282 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
284 pool_freeidhashes(pool); /* XXX: should not be here! */
285 pool_freewhatprovides(pool);
286 num = pool->ss.nstrings;
287 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
288 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
290 /* count providers for each name */
291 for (i = pool->nsolvables - 1; i > 0; i--)
294 s = pool->solvables + i;
295 if (!s->provides || !s->repo || s->repo->disabled)
297 /* we always need the installed solvable in the whatprovides data,
298 otherwise obsoletes/conflicts on them won't work */
299 if (s->repo != installed && !pool_installable(pool, s))
301 pp = s->repo->idarraydata + s->provides;
302 while ((id = *pp++) != 0)
306 Reldep *rd = GETRELDEP(pool, id);
309 whatprovides[id]++; /* inc count of providers */
313 off = 2; /* first entry is undef, second is empty list */
314 np = 0; /* number of names provided */
315 for (i = 0, idp = whatprovides; i < num; i++, idp++)
318 if (!n) /* no providers */
320 off += n; /* make space for all providers */
321 *idp = off++; /* now idp points to terminating zero */
322 np++; /* inc # of provider 'slots' for stats */
325 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
327 /* reserve some space for relation data */
328 extra = 2 * pool->nrels;
332 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
334 /* alloc space for all providers + extra */
335 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
337 /* now fill data for all provides */
338 for (i = pool->nsolvables - 1; i > 0; i--)
341 s = pool->solvables + i;
342 if (!s->provides || !s->repo || s->repo->disabled)
344 if (s->repo != installed && !pool_installable(pool, s))
347 /* for all provides of this solvable */
348 pp = s->repo->idarraydata + s->provides;
349 while ((id = *pp++) != 0)
353 Reldep *rd = GETRELDEP(pool, id);
356 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
357 if (*d != i) /* don't add same solvable twice */
364 pool->whatprovidesdata = whatprovidesdata;
365 pool->whatprovidesdataoff = off;
366 pool->whatprovidesdataleft = extra;
367 pool_shrink_whatprovides(pool);
368 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)));
369 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
373 * free all of our whatprovides data
374 * be careful, everything internalized with pool_queuetowhatprovides is
378 pool_freewhatprovides(Pool *pool)
380 pool->whatprovides = sat_free(pool->whatprovides);
381 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
382 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
383 pool->whatprovidesdataoff = 0;
384 pool->whatprovidesdataleft = 0;
388 /******************************************************************************/
391 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
393 * on-demand filling of provider information
394 * move queue data into whatprovidesdata
396 * returns: Offset into whatprovides
400 pool_queuetowhatprovides(Pool *pool, Queue *q)
403 int count = q->count;
405 if (count == 0) /* queue empty -> 1 */
408 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
409 if (pool->whatprovidesdataleft < count + 1)
411 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
412 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
413 pool->whatprovidesdataleft = count + 4096;
416 /* copy queue to next free slot */
417 off = pool->whatprovidesdataoff;
418 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
420 /* adapt count and ID_NULL-terminate */
421 pool->whatprovidesdataoff += count;
422 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
423 pool->whatprovidesdataleft -= count + 1;
429 /*************************************************************************/
431 #if defined(MULTI_SEMANTICS)
432 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
433 #elif defined(DEBIAN_SEMANTICS)
434 # define EVRCMP_DEPCMP EVRCMP_COMPARE
436 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
439 /* check if a package's nevr matches a dependency */
442 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
444 Reldep *rd = GETRELDEP(pool, d);
447 int flags = rd->flags;
456 return pool_match_nevr(pool, s, name);
458 if (pool_match_nevr(pool, s, name))
460 return pool_match_nevr(pool, s, evr);
463 if (!pool_match_nevr(pool, s, name))
465 return pool_match_nevr(pool, s, evr);
470 if (!pool_match_nevr(pool, s, name))
473 return flags & 2 ? 1 : 0;
478 if (flags != 2 && flags != 5)
480 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
485 /* match (flags, evr) against provider (pflags, pevr) */
487 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
489 if (!pflags || !flags || pflags >= 8 || flags >= 8)
491 if (flags == 7 || pflags == 7)
492 return 1; /* rel provides every version */
493 if ((pflags & flags & 5) != 0)
494 return 1; /* both rels show in the same direction */
497 if ((pflags & flags & 2) != 0)
498 return 1; /* both have '=', match */
502 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
503 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
509 /* match two dependencies (d1 = provider) */
512 pool_match_dep(Pool *pool, Id d1, Id d2)
522 rd2 = GETRELDEP(pool, d2);
523 return pool_match_dep(pool, d1, rd2->name);
525 rd1 = GETRELDEP(pool, d1);
528 return pool_match_dep(pool, rd1->name, d2);
530 rd2 = GETRELDEP(pool, d2);
531 /* first match name */
532 if (!pool_match_dep(pool, rd1->name, rd2->name))
534 /* name matches, check flags and evr */
535 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
541 * add packages fulfilling the relation to whatprovides array
542 * no exact providers, do range match
547 pool_addrelproviders(Pool *pool, Id d)
549 Reldep *rd = GETRELDEP(pool, d);
555 int flags = rd->flags;
560 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
564 /* special relation */
572 wp = pool_whatprovides(pool, name);
573 pp2 = pool_whatprovides_ptr(pool, evr);
574 pp = pool->whatprovidesdata + wp;
575 while ((p = *pp++) != 0)
577 for (pp3 = pp2; *pp3; pp3++)
581 queue_push(&plist, p); /* found it */
587 wp = pool_whatprovides(pool, name);
588 pp = pool->whatprovidesdata + wp;
590 wp = pool_whatprovides(pool, evr);
594 while ((p = *pp++) != 0)
595 queue_push(&plist, p);
597 pp = pool_whatprovides_ptr(pool, evr);
598 while ((p = *pp++) != 0)
599 queue_pushunique(&plist, p);
600 if (plist.count != cnt)
605 if (name == NAMESPACE_OTHERPROVIDERS)
607 wp = pool_whatprovides(pool, evr);
610 if (pool->nscallback)
612 /* ask callback which packages provide the dependency
614 * 1: the system (aka SYSTEMSOLVABLE)
615 * >1: set of packages, stored as offset on whatprovidesdata
617 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
621 queue_push(&plist, SYSTEMSOLVABLE);
625 /* small hack: make it possible to match <pkg>.src
626 * we have to iterate over the solvables as src packages do not
627 * provide anything, thus they are not indexed in our
628 * whatprovides hash */
632 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
634 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
636 if (pool_match_nevr(pool, s, name))
637 queue_push(&plist, p);
641 wp = pool_whatprovides(pool, name);
642 pp = pool->whatprovidesdata + wp;
643 while ((p = *pp++) != 0)
645 Solvable *s = pool->solvables + p;
647 queue_push(&plist, p);
652 case REL_FILECONFLICT:
653 pp = pool_whatprovides_ptr(pool, name);
654 while ((p = *pp++) != 0)
656 Id origd = MAKERELDEP(d);
657 Solvable *s = pool->solvables + p;
660 pidp = s->repo->idarraydata + s->provides;
661 while ((pid = *pidp++) != 0)
665 queue_push(&plist, p);
673 /* we can reuse an existing entry */
675 pool->whatprovides_rel[d] = wp;
681 /* simple version comparison relation */
683 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
685 pp = pool_whatprovides_ptr(pool, name);
686 while (ISRELDEP(name))
688 rd = GETRELDEP(pool, name);
691 while ((p = *pp++) != 0)
693 Solvable *s = pool->solvables + p;
696 /* no provides - check nevr */
697 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
698 queue_push(&plist, p);
701 /* solvable p provides name in some rels */
702 pidp = s->repo->idarraydata + s->provides;
703 while ((pid = *pidp++) != 0)
707 #if defined(MULTI_SEMANTICS)
708 if (pool->disttype == DISTTYPE_DEB)
712 #elif defined(DEBIAN_SEMANTICS)
713 continue; /* unversioned provides can
714 * never match versioned deps */
716 break; /* yes, provides all versions */
720 continue; /* wrong provides name */
721 prd = GETRELDEP(pool, pid);
722 if (prd->name != name)
723 continue; /* wrong provides name */
724 /* right package, both deps are rels. check flags/evr */
725 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
729 continue; /* none of the providers matched */
730 queue_push(&plist, p);
732 /* make our system solvable provide all unknown rpmlib() stuff */
733 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
734 queue_push(&plist, SYSTEMSOLVABLE);
736 /* add providers to whatprovides */
738 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
740 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
743 return pool->whatprovides_rel[d];
746 /*************************************************************************/
749 pool_debug(Pool *pool, int type, const char *format, ...)
754 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
756 if ((pool->debugmask & type) == 0)
759 va_start(args, format);
760 if (!pool->debugcallback)
762 if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
763 vprintf(format, args);
765 vfprintf(stderr, format, args);
768 vsnprintf(buf, sizeof(buf), format, args);
769 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
773 pool_setdebuglevel(Pool *pool, int level)
775 int mask = SAT_DEBUG_RESULT;
777 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
779 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
781 mask |= SAT_DEBUG_PROPAGATE;
783 mask |= SAT_DEBUG_RULE_CREATION;
785 mask |= SAT_DEBUG_SCHUBI;
786 mask |= pool->debugmask & SAT_DEBUG_TO_STDERR; /* keep bit */
787 pool->debugmask = mask;
790 /*************************************************************************/
800 #define SEARCHFILES_BLOCK 127
803 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
807 struct searchfiles *csf;
809 while ((dep = *ida++) != 0)
812 while (ISRELDEP(dep))
815 sid = pool->ss.nstrings + GETRELID(dep);
816 if (MAPTST(&csf->seen, sid))
821 MAPSET(&csf->seen, sid);
822 rd = GETRELDEP(pool, dep);
825 else if (rd->flags == REL_NAMESPACE)
827 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
830 if (!csf || MAPTST(&csf->seen, sid))
835 MAPSET(&csf->seen, sid);
839 else if (rd->flags == REL_FILECONFLICT)
849 pool_addfileprovides_dep(pool, ids, csf, isf);
855 if (MAPTST(&csf->seen, dep))
857 MAPSET(&csf->seen, dep);
858 s = id2str(pool, dep);
861 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
862 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
863 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
864 csf->ids[csf->nfiles] = dep;
865 sr = strrchr(s, '/');
866 csf->names[csf->nfiles] = strdup(sr + 1);
867 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
869 strncpy(csf->dirs[csf->nfiles], s, sr - s);
870 csf->dirs[csf->nfiles][sr - s] = 0;
875 struct addfileprovides_cbdata {
889 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
891 struct addfileprovides_cbdata *cbd = cbdata;
894 if (!cbd->useddirs.size)
896 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
897 for (i = 0; i < cbd->nfiles; i++)
900 if (MAPTST(&cbd->providedids, cbd->ids[i]))
905 did = repodata_str2dir(data, cbd->dirs[i], 0);
908 MAPSET(&cbd->useddirs, did);
911 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
913 for (i = 0; i < cbd->nfiles; i++)
915 if (cbd->dids[i] != value->id)
917 if (!strcmp(cbd->names[i], value->str))
920 if (i == cbd->nfiles)
922 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
927 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
933 int i, j, repoid, repodataid;
934 int provstart, provend;
936 int ndone, incomplete;
941 cbd->nfiles = sf->nfiles;
943 cbd->dirs = sf->dirs;
944 cbd->names = sf->names;
945 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
946 map_init(&cbd->providedids, pool->ss.nstrings);
949 repo = repoonly ? repoonly : pool->repos[0];
950 map_init(&donemap, pool->nsolvables);
951 queue_init(&fileprovidesq);
952 provstart = provend = 0;
957 if (repoonly || ++repoid == pool->nrepos)
959 repo = pool->repos[repoid];
963 for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
965 if (ndone >= repo->nsolvables)
968 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
970 map_empty(&cbd->providedids);
971 for (i = 0; i < fileprovidesq.count; i++)
972 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
973 provstart = data->start;
975 for (i = 0; i < cbd->nfiles; i++)
976 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
978 if (i == cbd->nfiles)
980 /* great! no need to search files */
981 for (p = data->start; p < data->end; p++)
982 if (pool->solvables[p].repo == repo)
984 if (MAPTST(&donemap, p))
993 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
996 if (data->start < provstart || data->end > provend)
998 map_empty(&cbd->providedids);
999 provstart = provend = 0;
1002 /* check if the data is incomplete */
1004 if (data->state == REPODATA_AVAILABLE)
1006 for (j = 1; j < data->nkeys; j++)
1007 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1009 if (j < data->nkeys)
1012 for (i = 0; i < cbd->nfiles; i++)
1013 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
1014 printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
1016 for (i = 0; i < cbd->nfiles; i++)
1017 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
1019 if (i < cbd->nfiles)
1025 map_init(&cbd->useddirs, 0);
1026 for (p = data->start; p < data->end; p++)
1027 if (pool->solvables[p].repo == repo)
1029 if (MAPTST(&donemap, p))
1031 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1034 MAPSET(&donemap, p);
1038 map_free(&cbd->useddirs);
1041 if (repoonly || ++repoid == pool->nrepos)
1043 repo = pool->repos[repoid];
1046 queue_free(&fileprovidesq);
1047 map_free(&cbd->providedids);
1051 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1055 struct searchfiles sf, isf, *isfp;
1056 struct addfileprovides_cbdata cbd;
1060 now = sat_timems(0);
1061 memset(&sf, 0, sizeof(sf));
1062 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1063 memset(&isf, 0, sizeof(isf));
1064 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1066 isfp = installed ? &isf : 0;
1067 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1073 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1075 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1077 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1079 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1081 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1083 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1085 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1088 map_free(&isf.seen);
1089 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1096 for (i = 0; i < sf.nfiles; i++)
1097 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
1099 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1102 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1103 sf.ids[sf.nfiles] = 0;
1108 for (i = 0; i < sf.nfiles; i++)
1110 sat_free(sf.dirs[i]);
1111 sat_free(sf.names[i]);
1119 for (i = 0; i < isf.nfiles; i++)
1120 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
1123 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1125 for (i = 0; i < isf.nfiles; i++)
1127 sat_free(isf.dirs[i]);
1128 sat_free(isf.names[i]);
1131 sat_free(isf.names);
1134 pool_freewhatprovides(pool); /* as we have added provides */
1135 POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
1139 pool_addfileprovides(Pool *pool)
1141 pool_addfileprovides_ids(pool, pool->installed, 0);
1145 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)
1149 if (pool->solvables[p].repo)
1150 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1153 /* FIXME: obey callback return value! */
1154 for (p = 1; p < pool->nsolvables; p++)
1155 if (pool->solvables[p].repo)
1156 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1160 pool_clear_pos(Pool *pool)
1162 memset(&pool->pos, 0, sizeof(pool->pos));
1167 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1171 pool->languagecache = sat_free(pool->languagecache);
1172 pool->languagecacheother = 0;
1173 if (pool->nlanguages)
1175 for (i = 0; i < pool->nlanguages; i++)
1176 free((char *)pool->languages[i]);
1177 free(pool->languages);
1179 pool->nlanguages = nlanguages;
1182 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1183 for (i = 0; i < pool->nlanguages; i++)
1184 pool->languages[i] = strdup(languages[i]);
1188 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1196 n = id2str(pool, id);
1197 l = strlen(n) + strlen(lang) + 2;
1198 if (l > sizeof(buf))
1199 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1202 sprintf(p, "%s:%s", n, lang);
1203 id = str2id(pool, p, create);
1210 pool_alloctmpspace(Pool *pool, int len)
1212 int n = pool->tmpspacen;
1215 if (len > pool->tmpspacelen[n])
1217 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1218 pool->tmpspacelen[n] = len + 32;
1220 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1221 return pool->tmpspacebuf[n];
1225 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1229 l1 = str1 ? strlen(str1) : 0;
1230 l2 = str2 ? strlen(str2) : 0;
1231 l3 = str3 ? strlen(str3) : 0;
1232 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1253 /*******************************************************************/
1265 struct mptree *mptree;
1276 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1278 struct ducbdata *cbd = cbdata;
1281 if (data != cbd->olddata)
1283 Id dn, mp, comp, *dirmap, *dirs;
1285 const char *compstr;
1286 struct mptree *mptree;
1288 /* create map from dir to mptree */
1289 cbd->dirmap = sat_free(cbd->dirmap);
1291 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1292 mptree = cbd->mptree;
1294 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1308 if (!mptree[mp].child)
1313 if (data->localpool)
1314 compstr = stringpool_id2str(&data->spool, comp);
1316 compstr = id2str(data->repo->pool, comp);
1317 compl = strlen(compstr);
1318 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1319 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1321 dirmap[dn] = i ? i : -mp;
1323 /* change dirmap to point to mountpoint instead of mptree */
1324 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1327 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1329 cbd->dirmap = dirmap;
1330 cbd->nmap = data->dirpool.ndirs;
1331 cbd->olddata = data;
1334 if (value->id < 0 || value->id >= cbd->nmap)
1336 mp = cbd->dirmap[value->id];
1339 if (cbd->addsub > 0)
1341 cbd->mps[mp].kbytes += value->num;
1342 cbd->mps[mp].files += value->num2;
1346 cbd->mps[mp].kbytes -= value->num;
1347 cbd->mps[mp].files -= value->num2;
1353 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1356 if (mptree[pos].mountpoint == -1)
1357 mptree[pos].mountpoint = mountpoint;
1359 mountpoint = mptree[pos].mountpoint;
1360 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1361 propagate_mountpoints(mptree, i, mountpoint);
1364 #define MPTREE_BLOCK 15
1367 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1370 const char *path, *compstr;
1371 struct mptree *mptree;
1375 struct ducbdata cbd;
1379 Repo *oldinstalled = pool->installed;
1381 memset(&ignoredu, 0, sizeof(ignoredu));
1388 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1391 mptree[0].sibling = 0;
1392 mptree[0].child = 0;
1394 mptree[0].compl = 0;
1395 mptree[0].mountpoint = -1;
1398 /* create component tree */
1399 for (mp = 0; mp < nmps; mp++)
1404 path = mps[mp].path;
1409 if ((p = strchr(path, '/')) == 0)
1412 compl = strlen(compstr);
1423 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1424 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1428 /* create new node */
1429 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1431 mptree[i].sibling = mptree[pos].child;
1432 mptree[i].child = 0;
1433 mptree[i].comp = compstr;
1434 mptree[i].compl = compl;
1435 mptree[i].mountpoint = -1;
1436 mptree[pos].child = i;
1440 mptree[pos].mountpoint = mp;
1443 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1446 for (i = 0; i < nmptree; i++)
1448 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1449 printf("#%d child: %d\n", i, mptree[i].child);
1450 printf("#%d comp: %s\n", i, mptree[i].comp);
1451 printf("#%d compl: %d\n", i, mptree[i].compl);
1452 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1456 cbd.mptree = mptree;
1458 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1460 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1462 if (!MAPTST(installedmap, sp))
1465 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1466 if (!cbd.hasdu && oldinstalled)
1469 /* no du data available, ignore data of all installed solvables we obsolete */
1471 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1474 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1475 while ((obs = *obsp++) != 0)
1476 FOR_PROVIDES(op, opp, obs)
1477 if (op >= oldinstalled->start && op < oldinstalled->end)
1478 MAPSET(&ignoredu, op - oldinstalled->start);
1480 FOR_PROVIDES(op, opp, s->name)
1481 if (pool->solvables[op].name == s->name)
1482 if (op >= oldinstalled->start && op < oldinstalled->end)
1483 MAPSET(&ignoredu, op - oldinstalled->start);
1489 /* assumes we allways have du data for installed solvables */
1490 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1492 if (MAPTST(installedmap, sp))
1494 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1496 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1500 map_free(&ignoredu);
1501 sat_free(cbd.dirmap);
1506 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1511 Repo *oldinstalled = pool->installed;
1513 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1515 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1517 if (!MAPTST(installedmap, sp))
1519 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1523 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1525 if (MAPTST(installedmap, sp))
1527 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1535 * 2: conflicts with installed
1536 * 8: interesting (only true if installed)
1540 static inline Id dep2name(Pool *pool, Id dep)
1542 while (ISRELDEP(dep))
1544 Reldep *rd = rd = GETRELDEP(pool, dep);
1550 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1553 Solvable *sn = pool->solvables + n;
1555 FOR_PROVIDES(p, pp, sn->name)
1557 Solvable *s = pool->solvables + p;
1558 if (s->name != sn->name || s->arch != sn->arch)
1560 if ((map[p] & 9) != 9)
1562 if (pool_match_nevr(pool, pool->solvables + p, con))
1564 return 1; /* found installed package that doesn't conflict */
1569 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1573 FOR_PROVIDES(p, pp, dep)
1575 if (p == SYSTEMSOLVABLE)
1576 return 1; /* always boring, as never constraining */
1577 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1579 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1580 if (providedbyinstalled_multiversion(pool, map, p, dep))
1582 if ((map[p] & 9) == 9)
1590 * pool_trivial_installable - calculate if a set of solvables is
1591 * trivial installable without any other installs/deinstalls of
1592 * packages not belonging to the set.
1594 * the state is returned in the result queue:
1595 * 1: solvable is installable without any other package changes
1596 * 0: solvable is not installable
1597 * -1: solvable is installable, but doesn't constrain any installed packages
1601 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1604 Id p, *dp, con, *conp, req, *reqp;
1608 map = sat_calloc(pool->nsolvables, 1);
1609 for (p = 1; p < pool->nsolvables; p++)
1611 if (!MAPTST(installedmap, p))
1614 s = pool->solvables + p;
1617 conp = s->repo->idarraydata + s->conflicts;
1618 while ((con = *conp++) != 0)
1620 dp = pool_whatprovides_ptr(pool, con);
1622 map[p] |= 2; /* XXX: self conflict ? */
1625 for (i = 0; i < pkgs->count; i++)
1626 map[pkgs->elements[i]] = 16;
1628 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1630 if (i == pkgs->count)
1632 p = pkgs->elements[i];
1633 if ((map[p] & 16) == 0)
1635 if ((map[p] & 2) != 0)
1640 s = pool->solvables + p;
1644 reqp = s->repo->idarraydata + s->requires;
1645 while ((req = *reqp++) != 0)
1647 if (req == SOLVABLE_PREREQMARKER)
1649 r = providedbyinstalled(pool, map, req, 0, 0);
1652 /* decided and miss */
1656 m |= r; /* 1 | 9 | 16 | 17 */
1665 int ispatch = 0; /* see solver.c patch handling */
1667 if (!strncmp("patch:", id2str(pool, s->name), 6))
1669 conp = s->repo->idarraydata + s->conflicts;
1670 while ((con = *conp++) != 0)
1672 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1677 if ((m == 1 || m == 17) && ISRELDEP(con))
1679 con = dep2name(pool, con);
1680 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1685 continue; /* found a conflict */
1688 if (s->repo && s->repo != oldinstalled)
1690 Id p2, obs, *obsp, *pp;
1694 obsp = s->repo->idarraydata + s->obsoletes;
1695 while ((obs = *obsp++) != 0)
1697 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1706 FOR_PROVIDES(p2, pp, s->name)
1708 s2 = pool->solvables + p2;
1709 if (s2->name == s->name && (map[p2] & 1) != 0)
1726 queue_init_clone(res, pkgs);
1727 for (i = 0; i < pkgs->count; i++)
1729 m = map[pkgs->elements[i]];
1736 res->elements[i] = r;
1742 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1744 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1748 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1750 if (entry == SOLVID_POS && pool->pos.repo)
1751 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1754 return solvable_lookup_str(pool->solvables + entry, keyname);
1758 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1760 if (entry == SOLVID_POS && pool->pos.repo)
1762 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1763 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1764 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1768 return solvable_lookup_id(pool->solvables + entry, keyname);
1772 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1774 if (entry == SOLVID_POS && pool->pos.repo)
1777 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1783 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1787 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1789 if (entry == SOLVID_POS && pool->pos.repo)
1790 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1793 return solvable_lookup_void(pool->solvables + entry, keyname);
1796 const unsigned char *
1797 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1799 if (entry == SOLVID_POS && pool->pos.repo)
1800 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1803 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1807 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1809 if (entry == SOLVID_POS && pool->pos.repo)
1811 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1812 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1816 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1820 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1822 int hadhashes = pool->relhashtbl ? 1 : 0;
1828 if (!conflicts->count)
1830 pool_freewhatprovides(pool);
1831 for (i = 0; i < conflicts->count; i += 5)
1833 fn = conflicts->elements[i];
1834 p = conflicts->elements[i + 1];
1835 md5 = conflicts->elements[i + 2];
1836 q = conflicts->elements[i + 3];
1837 id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1838 s = pool->solvables + p;
1841 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1842 s = pool->solvables + q;
1845 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1848 pool_freeidhashes(pool);