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 *)solv_calloc(1, sizeof(*pool));
45 stringpool_init (&pool->ss, initpool_data);
47 /* alloc space for RelDep 0 */
48 pool->rels = solv_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 = solv_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
55 memset(pool->solvables, 0, 2 * sizeof(Solvable));
57 /* initialize the system solvable */
58 s = pool->solvables + SYSTEMSOLVABLE;
59 s->name = SYSTEM_SYSTEM;
60 s->arch = ARCH_NOARCH;
63 queue_init(&pool->vendormap);
65 pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
67 pool->obsoleteusescolors = 1;
70 pool->allowselfconflicts = 1;
71 # ifdef MULTI_SEMANTICS
72 pool->disttype = DISTTYPE_DEB;
76 pool->obsoleteusesprovides = 1;
77 pool->implicitobsoleteusesprovides = 1;
83 /* free all the resources of our pool */
89 pool_freewhatprovides(pool);
90 pool_freeidhashes(pool);
91 pool_freeallrepos(pool, 1);
92 solv_free(pool->id2arch);
93 solv_free(pool->solvables);
94 stringpool_free(&pool->ss);
95 solv_free(pool->rels);
96 pool_setvendorclasses(pool, 0);
97 queue_free(&pool->vendormap);
98 for (i = 0; i < POOL_TMPSPACEBUF; i++)
99 solv_free(pool->tmpspace.buf[i]);
100 for (i = 0; i < pool->nlanguages; i++)
101 free((char *)pool->languages[i]);
102 solv_free(pool->languages);
103 solv_free(pool->languagecache);
108 pool_freeallrepos(Pool *pool, int reuseids)
112 pool_freewhatprovides(pool);
113 for (i = 1; i < pool->nrepos; i++)
115 repo_freedata(pool->repos[i]);
116 pool->repos = solv_free(pool->repos);
119 /* the first two solvables don't belong to a repo */
120 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
123 #ifdef MULTI_SEMANTICS
125 pool_setdisttype(Pool *pool, int disttype)
127 pool->disttype = disttype;
132 pool_add_solvable(Pool *pool)
134 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
135 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
136 return pool->nsolvables++;
140 pool_add_solvable_block(Pool *pool, int count)
142 Id nsolvables = pool->nsolvables;
145 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
146 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
147 pool->nsolvables += count;
152 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
156 if (reuseids && start + count == pool->nsolvables)
158 /* might want to shrink solvable array */
159 pool->nsolvables = start;
162 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
167 pool_set_installed(Pool *pool, Repo *installed)
169 if (pool->installed == installed)
171 pool->installed = installed;
172 pool_freewhatprovides(pool);
176 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
181 oa = pool->whatprovides[*(Id *)ap];
182 ob = pool->whatprovides[*(Id *)bp];
184 return *(Id *)ap - *(Id *)bp;
189 da = pool->whatprovidesdata + oa;
190 db = pool->whatprovidesdata + ob;
192 if ((r = (*da++ - *db++)) != 0)
196 return *(Id *)ap - *(Id *)bp;
200 * pool_shrink_whatprovides - unify whatprovides data
202 * whatprovides_rel must be empty for this to work!
206 pool_shrink_whatprovides(Pool *pool)
210 Id lastid, *last, *dp, *lp;
214 if (pool->ss.nstrings < 3)
216 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
217 for (id = 0; id < pool->ss.nstrings; id++)
219 solv_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
222 for (i = 1; i < pool->ss.nstrings; i++)
225 o = pool->whatprovides[id];
226 if (o == 0 || o == 1)
228 dp = pool->whatprovidesdata + o;
242 pool->whatprovides[id] = -lastid;
246 last = pool->whatprovidesdata + o;
250 dp = pool->whatprovidesdata + 2;
251 for (id = 1; id < pool->ss.nstrings; id++)
253 o = pool->whatprovides[id];
254 if (o == 0 || o == 1)
261 pool->whatprovides[id] = pool->whatprovides[i];
264 lp = pool->whatprovidesdata + o;
267 pool->whatprovides[id] = dp - pool->whatprovidesdata;
268 while ((*dp++ = *lp++) != 0)
271 o = dp - pool->whatprovidesdata;
272 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
273 if (pool->whatprovidesdataoff == o)
275 r = pool->whatprovidesdataoff - o;
276 pool->whatprovidesdataoff = o;
277 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
278 if (r > pool->whatprovidesdataleft)
279 r = pool->whatprovidesdataleft;
280 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
285 * pool_createwhatprovides()
287 * create hashes over pool of solvables to ease provide lookups
291 pool_createwhatprovides(Pool *pool)
293 int i, num, np, extra;
298 Offset *whatprovides;
299 Id *whatprovidesdata, *d;
300 Repo *installed = pool->installed;
303 now = solv_timems(0);
304 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
305 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
307 pool_freeidhashes(pool); /* XXX: should not be here! */
308 pool_freewhatprovides(pool);
309 num = pool->ss.nstrings;
310 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
311 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
313 /* count providers for each name */
314 for (i = pool->nsolvables - 1; i > 0; i--)
317 s = pool->solvables + i;
318 if (!s->provides || !s->repo || s->repo->disabled)
320 /* we always need the installed solvable in the whatprovides data,
321 otherwise obsoletes/conflicts on them won't work */
322 if (s->repo != installed && !pool_installable(pool, s))
324 pp = s->repo->idarraydata + s->provides;
325 while ((id = *pp++) != 0)
329 Reldep *rd = GETRELDEP(pool, id);
332 whatprovides[id]++; /* inc count of providers */
336 off = 2; /* first entry is undef, second is empty list */
337 np = 0; /* number of names provided */
338 for (i = 0, idp = whatprovides; i < num; i++, idp++)
341 if (!n) /* no providers */
343 off += n; /* make space for all providers */
344 *idp = off++; /* now idp points to terminating zero */
345 np++; /* inc # of provider 'slots' for stats */
348 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
350 /* reserve some space for relation data */
351 extra = 2 * pool->nrels;
355 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
357 /* alloc space for all providers + extra */
358 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
360 /* now fill data for all provides */
361 for (i = pool->nsolvables - 1; i > 0; i--)
364 s = pool->solvables + i;
365 if (!s->provides || !s->repo || s->repo->disabled)
367 if (s->repo != installed && !pool_installable(pool, s))
370 /* for all provides of this solvable */
371 pp = s->repo->idarraydata + s->provides;
372 while ((id = *pp++) != 0)
376 Reldep *rd = GETRELDEP(pool, id);
379 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
380 if (*d != i) /* don't add same solvable twice */
387 pool->whatprovidesdata = whatprovidesdata;
388 pool->whatprovidesdataoff = off;
389 pool->whatprovidesdataleft = extra;
390 pool_shrink_whatprovides(pool);
391 POOL_DEBUG(SOLV_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)));
392 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
396 * free all of our whatprovides data
397 * be careful, everything internalized with pool_queuetowhatprovides is
401 pool_freewhatprovides(Pool *pool)
403 pool->whatprovides = solv_free(pool->whatprovides);
404 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
405 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
406 pool->whatprovidesdataoff = 0;
407 pool->whatprovidesdataleft = 0;
411 /******************************************************************************/
414 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
416 * on-demand filling of provider information
417 * move queue data into whatprovidesdata
419 * returns: Offset into whatprovides
423 pool_queuetowhatprovides(Pool *pool, Queue *q)
426 int count = q->count;
428 if (count == 0) /* queue empty -> 1 */
431 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
432 if (pool->whatprovidesdataleft < count + 1)
434 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
435 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
436 pool->whatprovidesdataleft = count + 4096;
439 /* copy queue to next free slot */
440 off = pool->whatprovidesdataoff;
441 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
443 /* adapt count and ID_NULL-terminate */
444 pool->whatprovidesdataoff += count;
445 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
446 pool->whatprovidesdataleft -= count + 1;
452 /*************************************************************************/
454 #if defined(MULTI_SEMANTICS)
455 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
456 #elif defined(DEBIAN_SEMANTICS)
457 # define EVRCMP_DEPCMP EVRCMP_COMPARE
459 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
462 /* check if a package's nevr matches a dependency */
465 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
467 Reldep *rd = GETRELDEP(pool, d);
470 int flags = rd->flags;
479 return pool_match_nevr(pool, s, name);
481 if (pool_match_nevr(pool, s, name))
483 return pool_match_nevr(pool, s, evr);
486 if (!pool_match_nevr(pool, s, name))
488 return pool_match_nevr(pool, s, evr);
493 if (!pool_match_nevr(pool, s, name))
496 return flags & 2 ? 1 : 0;
501 if (flags != 2 && flags != 5)
503 if ((flags & (1 << (1 + pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
508 /* match (flags, evr) against provider (pflags, pevr) */
510 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
512 if (!pflags || !flags || pflags >= 8 || flags >= 8)
514 if (flags == 7 || pflags == 7)
515 return 1; /* rel provides every version */
516 if ((pflags & flags & 5) != 0)
517 return 1; /* both rels show in the same direction */
520 if ((pflags & flags & 2) != 0)
521 return 1; /* both have '=', match */
525 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
526 if ((f & (1 << (1 + pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
532 /* match two dependencies (d1 = provider) */
535 pool_match_dep(Pool *pool, Id d1, Id d2)
545 rd2 = GETRELDEP(pool, d2);
546 return pool_match_dep(pool, d1, rd2->name);
548 rd1 = GETRELDEP(pool, d1);
551 return pool_match_dep(pool, rd1->name, d2);
553 rd2 = GETRELDEP(pool, d2);
554 /* first match name */
555 if (!pool_match_dep(pool, rd1->name, rd2->name))
557 /* name matches, check flags and evr */
558 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
564 * add packages fulfilling the relation to whatprovides array
565 * no exact providers, do range match
570 pool_addrelproviders(Pool *pool, Id d)
572 Reldep *rd = GETRELDEP(pool, d);
578 int flags = rd->flags;
583 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
587 /* special relation */
595 wp = pool_whatprovides(pool, name);
596 pp2 = pool_whatprovides_ptr(pool, evr);
597 pp = pool->whatprovidesdata + wp;
598 while ((p = *pp++) != 0)
600 for (pp3 = pp2; *pp3; pp3++)
604 queue_push(&plist, p); /* found it */
610 wp = pool_whatprovides(pool, name);
611 pp = pool->whatprovidesdata + wp;
613 wp = pool_whatprovides(pool, evr);
617 while ((p = *pp++) != 0)
618 queue_push(&plist, p);
620 pp = pool_whatprovides_ptr(pool, evr);
621 while ((p = *pp++) != 0)
622 queue_pushunique(&plist, p);
623 if (plist.count != cnt)
628 if (name == NAMESPACE_OTHERPROVIDERS)
630 wp = pool_whatprovides(pool, evr);
633 if (pool->nscallback)
635 /* ask callback which packages provide the dependency
637 * 1: the system (aka SYSTEMSOLVABLE)
638 * >1: set of packages, stored as offset on whatprovidesdata
640 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
644 queue_push(&plist, SYSTEMSOLVABLE);
648 /* small hack: make it possible to match <pkg>.src
649 * we have to iterate over the solvables as src packages do not
650 * provide anything, thus they are not indexed in our
651 * whatprovides hash */
655 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
657 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
659 if (pool_match_nevr(pool, s, name))
660 queue_push(&plist, p);
664 wp = pool_whatprovides(pool, name);
665 pp = pool->whatprovidesdata + wp;
666 while ((p = *pp++) != 0)
668 Solvable *s = pool->solvables + p;
670 queue_push(&plist, p);
675 case REL_FILECONFLICT:
676 pp = pool_whatprovides_ptr(pool, name);
677 while ((p = *pp++) != 0)
679 Id origd = MAKERELDEP(d);
680 Solvable *s = pool->solvables + p;
683 pidp = s->repo->idarraydata + s->provides;
684 while ((pid = *pidp++) != 0)
688 queue_push(&plist, p);
696 /* we can reuse an existing entry */
698 pool->whatprovides_rel[d] = wp;
704 /* simple version comparison relation */
706 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
708 pp = pool_whatprovides_ptr(pool, name);
709 while (ISRELDEP(name))
711 rd = GETRELDEP(pool, name);
714 while ((p = *pp++) != 0)
716 Solvable *s = pool->solvables + p;
719 /* no provides - check nevr */
720 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
721 queue_push(&plist, p);
724 /* solvable p provides name in some rels */
725 pidp = s->repo->idarraydata + s->provides;
726 while ((pid = *pidp++) != 0)
730 #if defined(MULTI_SEMANTICS)
731 if (pool->disttype == DISTTYPE_DEB)
735 #elif defined(DEBIAN_SEMANTICS)
736 continue; /* unversioned provides can
737 * never match versioned deps */
739 break; /* yes, provides all versions */
743 continue; /* wrong provides name */
744 prd = GETRELDEP(pool, pid);
745 if (prd->name != name)
746 continue; /* wrong provides name */
747 /* right package, both deps are rels. check flags/evr */
748 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
752 continue; /* none of the providers matched */
753 queue_push(&plist, p);
755 /* make our system solvable provide all unknown rpmlib() stuff */
756 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
757 queue_push(&plist, SYSTEMSOLVABLE);
759 /* add providers to whatprovides */
761 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
763 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
766 return pool->whatprovides_rel[d];
769 /*************************************************************************/
772 pool_debug(Pool *pool, int type, const char *format, ...)
777 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
779 if ((pool->debugmask & type) == 0)
782 va_start(args, format);
783 if (!pool->debugcallback)
785 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
786 vprintf(format, args);
788 vfprintf(stderr, format, args);
791 vsnprintf(buf, sizeof(buf), format, args);
792 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
796 pool_setdebuglevel(Pool *pool, int level)
798 int mask = SOLV_DEBUG_RESULT;
800 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
802 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
804 mask |= SOLV_DEBUG_PROPAGATE;
806 mask |= SOLV_DEBUG_RULE_CREATION;
807 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
808 pool->debugmask = mask;
811 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
813 pool->debugcallback = debugcallback;
814 pool->debugcallbackdata = debugcallbackdata;
817 void pool_setdebugmask(Pool *pool, int mask)
819 pool->debugmask = mask;
822 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
824 pool->loadcallback = cb;
825 pool->loadcallbackdata = loadcbdata;
828 /*************************************************************************/
838 #define SEARCHFILES_BLOCK 127
841 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
845 struct searchfiles *csf;
847 while ((dep = *ida++) != 0)
850 while (ISRELDEP(dep))
853 sid = pool->ss.nstrings + GETRELID(dep);
854 if (MAPTST(&csf->seen, sid))
859 MAPSET(&csf->seen, sid);
860 rd = GETRELDEP(pool, dep);
863 else if (rd->flags == REL_NAMESPACE)
865 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
868 if (!csf || MAPTST(&csf->seen, sid))
873 MAPSET(&csf->seen, sid);
877 else if (rd->flags == REL_FILECONFLICT)
887 pool_addfileprovides_dep(pool, ids, csf, isf);
893 if (MAPTST(&csf->seen, dep))
895 MAPSET(&csf->seen, dep);
896 s = pool_id2str(pool, dep);
899 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
900 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
901 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
902 csf->ids[csf->nfiles] = dep;
903 sr = strrchr(s, '/');
904 csf->names[csf->nfiles] = solv_strdup(sr + 1);
905 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
907 strncpy(csf->dirs[csf->nfiles], s, sr - s);
908 csf->dirs[csf->nfiles][sr - s] = 0;
913 struct addfileprovides_cbdata {
927 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
929 struct addfileprovides_cbdata *cbd = cbdata;
932 if (!cbd->useddirs.size)
934 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
935 for (i = 0; i < cbd->nfiles; i++)
938 if (MAPTST(&cbd->providedids, cbd->ids[i]))
943 did = repodata_str2dir(data, cbd->dirs[i], 0);
946 MAPSET(&cbd->useddirs, did);
949 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
951 for (i = 0; i < cbd->nfiles; i++)
953 if (cbd->dids[i] != value->id)
955 if (!strcmp(cbd->names[i], value->str))
958 if (i == cbd->nfiles)
960 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
965 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
971 int i, j, repoid, repodataid;
972 int provstart, provend;
974 int ndone, incomplete;
979 cbd->nfiles = sf->nfiles;
981 cbd->dirs = sf->dirs;
982 cbd->names = sf->names;
983 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
984 map_init(&cbd->providedids, pool->ss.nstrings);
987 repo = repoonly ? repoonly : pool->repos[repoid];
988 map_init(&donemap, pool->nsolvables);
989 queue_init(&fileprovidesq);
990 provstart = provend = 0;
993 if (!repo || repo->disabled)
995 if (repoonly || ++repoid == pool->nrepos)
997 repo = pool->repos[repoid];
1001 FOR_REPODATAS(repo, repodataid, data)
1003 if (ndone >= repo->nsolvables)
1006 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1008 map_empty(&cbd->providedids);
1009 for (i = 0; i < fileprovidesq.count; i++)
1010 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1011 provstart = data->start;
1012 provend = data->end;
1013 for (i = 0; i < cbd->nfiles; i++)
1014 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1016 if (i == cbd->nfiles)
1018 /* great! no need to search files */
1019 for (p = data->start; p < data->end; p++)
1020 if (pool->solvables[p].repo == repo)
1022 if (MAPTST(&donemap, p))
1024 MAPSET(&donemap, p);
1031 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1034 if (data->start < provstart || data->end > provend)
1036 map_empty(&cbd->providedids);
1037 provstart = provend = 0;
1040 /* check if the data is incomplete */
1042 if (data->state == REPODATA_AVAILABLE)
1044 for (j = 1; j < data->nkeys; j++)
1045 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1047 if (j < data->nkeys)
1050 for (i = 0; i < cbd->nfiles; i++)
1051 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1052 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1054 for (i = 0; i < cbd->nfiles; i++)
1055 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1057 if (i < cbd->nfiles)
1063 map_init(&cbd->useddirs, 0);
1064 for (p = data->start; p < data->end; p++)
1065 if (pool->solvables[p].repo == repo)
1067 if (MAPTST(&donemap, p))
1069 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1072 MAPSET(&donemap, p);
1076 map_free(&cbd->useddirs);
1079 if (repoonly || ++repoid == pool->nrepos)
1081 repo = pool->repos[repoid];
1084 queue_free(&fileprovidesq);
1085 map_free(&cbd->providedids);
1089 pool_addfileprovides_queue(Pool *pool, Queue *idq)
1092 Repo *installed, *repo;
1093 struct searchfiles sf, isf, *isfp;
1094 struct addfileprovides_cbdata cbd;
1098 installed = pool->installed;
1099 now = solv_timems(0);
1100 memset(&sf, 0, sizeof(sf));
1101 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1102 memset(&isf, 0, sizeof(isf));
1103 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1107 isfp = installed ? &isf : 0;
1108 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1114 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1116 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1118 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1120 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1122 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1124 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1126 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1129 map_free(&isf.seen);
1130 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1135 for (i = 0; i < sf.nfiles; i++)
1136 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1138 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1140 for (i = 0; i < sf.nfiles; i++)
1141 queue_push(idq, sf.ids[i]);
1143 for (i = 0; i < sf.nfiles; i++)
1145 solv_free(sf.dirs[i]);
1146 solv_free(sf.names[i]);
1149 solv_free(sf.names);
1154 for (i = 0; i < isf.nfiles; i++)
1155 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1158 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1160 for (i = 0; i < isf.nfiles; i++)
1162 solv_free(isf.dirs[i]);
1163 solv_free(isf.names[i]);
1165 solv_free(isf.dirs);
1166 solv_free(isf.names);
1168 solv_free(cbd.dids);
1169 pool_freewhatprovides(pool); /* as we have added provides */
1170 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1174 pool_addfileprovides(Pool *pool)
1176 pool_addfileprovides_queue(pool, 0);
1180 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)
1184 if (pool->solvables[p].repo)
1185 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1188 /* FIXME: obey callback return value! */
1189 for (p = 1; p < pool->nsolvables; p++)
1190 if (pool->solvables[p].repo)
1191 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1195 pool_clear_pos(Pool *pool)
1197 memset(&pool->pos, 0, sizeof(pool->pos));
1202 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1206 pool->languagecache = solv_free(pool->languagecache);
1207 pool->languagecacheother = 0;
1208 if (pool->nlanguages)
1210 for (i = 0; i < pool->nlanguages; i++)
1211 free((char *)pool->languages[i]);
1212 free(pool->languages);
1214 pool->nlanguages = nlanguages;
1217 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1218 for (i = 0; i < pool->nlanguages; i++)
1219 pool->languages[i] = solv_strdup(languages[i]);
1223 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1231 n = pool_id2str(pool, id);
1232 l = strlen(n) + strlen(lang) + 2;
1233 if (l > sizeof(buf))
1234 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1237 sprintf(p, "%s:%s", n, lang);
1238 id = pool_str2id(pool, p, create);
1245 pool_alloctmpspace(Pool *pool, int len)
1247 int n = pool->tmpspace.n;
1250 if (len > pool->tmpspace.len[n])
1252 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1253 pool->tmpspace.len[n] = len + 32;
1255 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1256 return pool->tmpspace.buf[n];
1260 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1265 n = oldn = pool->tmpspace.n;
1269 n = POOL_TMPSPACEBUF - 1;
1272 if (pool->tmpspace.buf[n] != space)
1274 if (len > pool->tmpspace.len[n])
1276 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1277 pool->tmpspace.len[n] = len + 32;
1279 return pool->tmpspace.buf[n];
1286 pool_freetmpspace(Pool *pool, const char *space)
1288 int n = pool->tmpspace.n;
1291 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1292 if (pool->tmpspace.buf[n] == space)
1293 pool->tmpspace.n = n;
1297 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1301 l1 = str1 ? strlen(str1) : 0;
1302 l2 = str2 ? strlen(str2) : 0;
1303 l3 = str3 ? strlen(str3) : 0;
1304 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1325 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1330 l1 = str1 ? strlen(str1) : 0;
1331 l2 = str2 ? strlen(str2) : 0;
1332 l3 = str3 ? strlen(str3) : 0;
1333 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1337 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1360 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1365 s = pool_alloctmpspace(pool, 2 * len + 1);
1366 solv_bin2hex(buf, len, s);
1370 /*******************************************************************/
1382 struct mptree *mptree;
1393 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1395 struct ducbdata *cbd = cbdata;
1398 if (data != cbd->olddata)
1400 Id dn, mp, comp, *dirmap, *dirs;
1402 const char *compstr;
1403 struct mptree *mptree;
1405 /* create map from dir to mptree */
1406 cbd->dirmap = solv_free(cbd->dirmap);
1408 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1409 mptree = cbd->mptree;
1411 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1425 if (!mptree[mp].child)
1430 if (data->localpool)
1431 compstr = stringpool_id2str(&data->spool, comp);
1433 compstr = pool_id2str(data->repo->pool, comp);
1434 compl = strlen(compstr);
1435 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1436 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1438 dirmap[dn] = i ? i : -mp;
1440 /* change dirmap to point to mountpoint instead of mptree */
1441 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1444 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1446 cbd->dirmap = dirmap;
1447 cbd->nmap = data->dirpool.ndirs;
1448 cbd->olddata = data;
1451 if (value->id < 0 || value->id >= cbd->nmap)
1453 mp = cbd->dirmap[value->id];
1456 if (cbd->addsub > 0)
1458 cbd->mps[mp].kbytes += value->num;
1459 cbd->mps[mp].files += value->num2;
1463 cbd->mps[mp].kbytes -= value->num;
1464 cbd->mps[mp].files -= value->num2;
1470 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1473 if (mptree[pos].mountpoint == -1)
1474 mptree[pos].mountpoint = mountpoint;
1476 mountpoint = mptree[pos].mountpoint;
1477 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1478 propagate_mountpoints(mptree, i, mountpoint);
1481 #define MPTREE_BLOCK 15
1484 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1487 const char *path, *compstr;
1488 struct mptree *mptree;
1492 struct ducbdata cbd;
1496 Repo *oldinstalled = pool->installed;
1498 memset(&ignoredu, 0, sizeof(ignoredu));
1505 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1508 mptree[0].sibling = 0;
1509 mptree[0].child = 0;
1511 mptree[0].compl = 0;
1512 mptree[0].mountpoint = -1;
1515 /* create component tree */
1516 for (mp = 0; mp < nmps; mp++)
1521 path = mps[mp].path;
1526 if ((p = strchr(path, '/')) == 0)
1529 compl = strlen(compstr);
1540 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1541 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1545 /* create new node */
1546 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1548 mptree[i].sibling = mptree[pos].child;
1549 mptree[i].child = 0;
1550 mptree[i].comp = compstr;
1551 mptree[i].compl = compl;
1552 mptree[i].mountpoint = -1;
1553 mptree[pos].child = i;
1557 mptree[pos].mountpoint = mp;
1560 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1563 for (i = 0; i < nmptree; i++)
1565 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1566 printf("#%d child: %d\n", i, mptree[i].child);
1567 printf("#%d comp: %s\n", i, mptree[i].comp);
1568 printf("#%d compl: %d\n", i, mptree[i].compl);
1569 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1573 cbd.mptree = mptree;
1575 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1577 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1579 if (!MAPTST(installedmap, sp))
1582 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1583 if (!cbd.hasdu && oldinstalled)
1586 /* no du data available, ignore data of all installed solvables we obsolete */
1588 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1591 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1592 while ((obs = *obsp++) != 0)
1593 FOR_PROVIDES(op, opp, obs)
1594 if (op >= oldinstalled->start && op < oldinstalled->end)
1595 MAPSET(&ignoredu, op - oldinstalled->start);
1597 FOR_PROVIDES(op, opp, s->name)
1598 if (pool->solvables[op].name == s->name)
1599 if (op >= oldinstalled->start && op < oldinstalled->end)
1600 MAPSET(&ignoredu, op - oldinstalled->start);
1606 /* assumes we allways have du data for installed solvables */
1607 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1609 if (MAPTST(installedmap, sp))
1611 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1613 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1617 map_free(&ignoredu);
1618 solv_free(cbd.dirmap);
1623 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1628 Repo *oldinstalled = pool->installed;
1630 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1632 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1634 if (!MAPTST(installedmap, sp))
1636 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1640 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1642 if (MAPTST(installedmap, sp))
1644 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1652 * 2: conflicts with installed
1653 * 8: interesting (only true if installed)
1657 static inline Id dep2name(Pool *pool, Id dep)
1659 while (ISRELDEP(dep))
1661 Reldep *rd = rd = GETRELDEP(pool, dep);
1667 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1670 Solvable *sn = pool->solvables + n;
1672 FOR_PROVIDES(p, pp, sn->name)
1674 Solvable *s = pool->solvables + p;
1675 if (s->name != sn->name || s->arch != sn->arch)
1677 if ((map[p] & 9) != 9)
1679 if (pool_match_nevr(pool, pool->solvables + p, con))
1681 return 1; /* found installed package that doesn't conflict */
1686 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1690 FOR_PROVIDES(p, pp, dep)
1692 if (p == SYSTEMSOLVABLE)
1693 return 1; /* always boring, as never constraining */
1694 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1696 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1697 if (providedbyinstalled_multiversion(pool, map, p, dep))
1699 if ((map[p] & 9) == 9)
1707 * pool_trivial_installable - calculate if a set of solvables is
1708 * trivial installable without any other installs/deinstalls of
1709 * packages not belonging to the set.
1711 * the state is returned in the result queue:
1712 * 1: solvable is installable without any other package changes
1713 * 0: solvable is not installable
1714 * -1: solvable is installable, but doesn't constrain any installed packages
1718 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1721 Id p, *dp, con, *conp, req, *reqp;
1725 map = solv_calloc(pool->nsolvables, 1);
1726 for (p = 1; p < pool->nsolvables; p++)
1728 if (!MAPTST(installedmap, p))
1731 s = pool->solvables + p;
1734 conp = s->repo->idarraydata + s->conflicts;
1735 while ((con = *conp++) != 0)
1737 dp = pool_whatprovides_ptr(pool, con);
1739 map[p] |= 2; /* XXX: self conflict ? */
1742 for (i = 0; i < pkgs->count; i++)
1743 map[pkgs->elements[i]] = 16;
1745 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1747 if (i == pkgs->count)
1749 p = pkgs->elements[i];
1750 if ((map[p] & 16) == 0)
1752 if ((map[p] & 2) != 0)
1757 s = pool->solvables + p;
1761 reqp = s->repo->idarraydata + s->requires;
1762 while ((req = *reqp++) != 0)
1764 if (req == SOLVABLE_PREREQMARKER)
1766 r = providedbyinstalled(pool, map, req, 0, 0);
1769 /* decided and miss */
1773 m |= r; /* 1 | 9 | 16 | 17 */
1782 int ispatch = 0; /* see solver.c patch handling */
1784 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1786 conp = s->repo->idarraydata + s->conflicts;
1787 while ((con = *conp++) != 0)
1789 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1794 if ((m == 1 || m == 17) && ISRELDEP(con))
1796 con = dep2name(pool, con);
1797 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1802 continue; /* found a conflict */
1805 if (s->repo && s->repo != oldinstalled)
1807 Id p2, obs, *obsp, *pp;
1811 obsp = s->repo->idarraydata + s->obsoletes;
1812 while ((obs = *obsp++) != 0)
1814 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1823 FOR_PROVIDES(p2, pp, s->name)
1825 s2 = pool->solvables + p2;
1826 if (s2->name == s->name && (map[p2] & 1) != 0)
1843 queue_init_clone(res, pkgs);
1844 for (i = 0; i < pkgs->count; i++)
1846 m = map[pkgs->elements[i]];
1853 res->elements[i] = r;
1859 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1861 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1865 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1867 if (entry == SOLVID_POS && pool->pos.repo)
1868 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1871 return solvable_lookup_str(pool->solvables + entry, keyname);
1875 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1877 if (entry == SOLVID_POS && pool->pos.repo)
1879 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1880 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1881 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1885 return solvable_lookup_id(pool->solvables + entry, keyname);
1889 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1891 if (entry == SOLVID_POS && pool->pos.repo)
1894 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1900 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1904 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1906 if (entry == SOLVID_POS && pool->pos.repo)
1907 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1910 return solvable_lookup_void(pool->solvables + entry, keyname);
1913 const unsigned char *
1914 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1916 if (entry == SOLVID_POS && pool->pos.repo)
1917 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1920 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1924 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1926 if (entry == SOLVID_POS && pool->pos.repo)
1928 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1929 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1933 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1937 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1939 int hadhashes = pool->relhashtbl ? 1 : 0;
1945 if (!conflicts->count)
1947 pool_freewhatprovides(pool);
1948 for (i = 0; i < conflicts->count; i += 5)
1950 fn = conflicts->elements[i];
1951 p = conflicts->elements[i + 1];
1952 md5 = conflicts->elements[i + 2];
1953 q = conflicts->elements[i + 3];
1954 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1955 s = pool->solvables + p;
1958 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1959 s = pool->solvables + q;
1962 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1965 pool_freeidhashes(pool);