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 pool->disttype = DISTTYPE_DEB;
74 pool->obsoleteusesprovides = 1;
75 pool->implicitobsoleteusesprovides = 1;
81 /* free all the resources of our pool */
87 pool_freewhatprovides(pool);
88 pool_freeidhashes(pool);
89 pool_freeallrepos(pool, 1);
90 solv_free(pool->id2arch);
91 solv_free(pool->solvables);
92 stringpool_free(&pool->ss);
93 solv_free(pool->rels);
94 pool_setvendorclasses(pool, 0);
95 queue_free(&pool->vendormap);
96 for (i = 0; i < POOL_TMPSPACEBUF; i++)
97 solv_free(pool->tmpspace.buf[i]);
98 for (i = 0; i < pool->nlanguages; i++)
99 free((char *)pool->languages[i]);
100 solv_free(pool->languages);
101 solv_free(pool->languagecache);
106 pool_freeallrepos(Pool *pool, int reuseids)
110 pool_freewhatprovides(pool);
111 for (i = 1; i < pool->nrepos; i++)
113 repo_freedata(pool->repos[i]);
114 pool->repos = solv_free(pool->repos);
117 /* the first two solvables don't belong to a repo */
118 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
121 #ifdef MULTI_SEMANTICS
123 pool_setdisttype(Pool *pool, int disttype)
125 pool->disttype = disttype;
130 pool_add_solvable(Pool *pool)
132 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
133 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
134 return pool->nsolvables++;
138 pool_add_solvable_block(Pool *pool, int count)
140 Id nsolvables = pool->nsolvables;
143 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
144 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
145 pool->nsolvables += count;
150 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
154 if (reuseids && start + count == pool->nsolvables)
156 /* might want to shrink solvable array */
157 pool->nsolvables = start;
160 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
165 pool_set_installed(Pool *pool, Repo *installed)
167 if (pool->installed == installed)
169 pool->installed = installed;
170 pool_freewhatprovides(pool);
174 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
179 oa = pool->whatprovides[*(Id *)ap];
180 ob = pool->whatprovides[*(Id *)bp];
182 return *(Id *)ap - *(Id *)bp;
187 da = pool->whatprovidesdata + oa;
188 db = pool->whatprovidesdata + ob;
190 if ((r = (*da++ - *db++)) != 0)
194 return *(Id *)ap - *(Id *)bp;
198 * pool_shrink_whatprovides - unify whatprovides data
200 * whatprovides_rel must be empty for this to work!
204 pool_shrink_whatprovides(Pool *pool)
208 Id lastid, *last, *dp, *lp;
212 if (pool->ss.nstrings < 3)
214 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
215 for (id = 0; id < pool->ss.nstrings; id++)
217 solv_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
220 for (i = 1; i < pool->ss.nstrings; i++)
223 o = pool->whatprovides[id];
224 if (o == 0 || o == 1)
226 dp = pool->whatprovidesdata + o;
240 pool->whatprovides[id] = -lastid;
244 last = pool->whatprovidesdata + o;
248 dp = pool->whatprovidesdata + 2;
249 for (id = 1; id < pool->ss.nstrings; id++)
251 o = pool->whatprovides[id];
252 if (o == 0 || o == 1)
259 pool->whatprovides[id] = pool->whatprovides[i];
262 lp = pool->whatprovidesdata + o;
265 pool->whatprovides[id] = dp - pool->whatprovidesdata;
266 while ((*dp++ = *lp++) != 0)
269 o = dp - pool->whatprovidesdata;
270 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
271 if (pool->whatprovidesdataoff == o)
273 r = pool->whatprovidesdataoff - o;
274 pool->whatprovidesdataoff = o;
275 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
276 if (r > pool->whatprovidesdataleft)
277 r = pool->whatprovidesdataleft;
278 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
283 * pool_createwhatprovides()
285 * create hashes over pool of solvables to ease provide lookups
289 pool_createwhatprovides(Pool *pool)
291 int i, num, np, extra;
296 Offset *whatprovides;
297 Id *whatprovidesdata, *d;
298 Repo *installed = pool->installed;
301 now = solv_timems(0);
302 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
303 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
305 pool_freeidhashes(pool); /* XXX: should not be here! */
306 pool_freewhatprovides(pool);
307 num = pool->ss.nstrings;
308 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
309 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
311 /* count providers for each name */
312 for (i = pool->nsolvables - 1; i > 0; i--)
315 s = pool->solvables + i;
316 if (!s->provides || !s->repo || s->repo->disabled)
318 /* we always need the installed solvable in the whatprovides data,
319 otherwise obsoletes/conflicts on them won't work */
320 if (s->repo != installed && !pool_installable(pool, s))
322 pp = s->repo->idarraydata + s->provides;
323 while ((id = *pp++) != 0)
327 Reldep *rd = GETRELDEP(pool, id);
330 whatprovides[id]++; /* inc count of providers */
334 off = 2; /* first entry is undef, second is empty list */
335 np = 0; /* number of names provided */
336 for (i = 0, idp = whatprovides; i < num; i++, idp++)
339 if (!n) /* no providers */
341 off += n; /* make space for all providers */
342 *idp = off++; /* now idp points to terminating zero */
343 np++; /* inc # of provider 'slots' for stats */
346 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
348 /* reserve some space for relation data */
349 extra = 2 * pool->nrels;
353 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
355 /* alloc space for all providers + extra */
356 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
358 /* now fill data for all provides */
359 for (i = pool->nsolvables - 1; i > 0; i--)
362 s = pool->solvables + i;
363 if (!s->provides || !s->repo || s->repo->disabled)
365 if (s->repo != installed && !pool_installable(pool, s))
368 /* for all provides of this solvable */
369 pp = s->repo->idarraydata + s->provides;
370 while ((id = *pp++) != 0)
374 Reldep *rd = GETRELDEP(pool, id);
377 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
378 if (*d != i) /* don't add same solvable twice */
385 pool->whatprovidesdata = whatprovidesdata;
386 pool->whatprovidesdataoff = off;
387 pool->whatprovidesdataleft = extra;
388 pool_shrink_whatprovides(pool);
389 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)));
390 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
394 * free all of our whatprovides data
395 * be careful, everything internalized with pool_queuetowhatprovides is
399 pool_freewhatprovides(Pool *pool)
401 pool->whatprovides = solv_free(pool->whatprovides);
402 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
403 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
404 pool->whatprovidesdataoff = 0;
405 pool->whatprovidesdataleft = 0;
409 /******************************************************************************/
412 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
414 * on-demand filling of provider information
415 * move queue data into whatprovidesdata
417 * returns: Offset into whatprovides
421 pool_queuetowhatprovides(Pool *pool, Queue *q)
424 int count = q->count;
426 if (count == 0) /* queue empty -> 1 */
429 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
430 if (pool->whatprovidesdataleft < count + 1)
432 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
433 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
434 pool->whatprovidesdataleft = count + 4096;
437 /* copy queue to next free slot */
438 off = pool->whatprovidesdataoff;
439 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
441 /* adapt count and ID_NULL-terminate */
442 pool->whatprovidesdataoff += count;
443 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
444 pool->whatprovidesdataleft -= count + 1;
450 /*************************************************************************/
452 #if defined(MULTI_SEMANTICS)
453 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
454 #elif defined(DEBIAN_SEMANTICS)
455 # define EVRCMP_DEPCMP EVRCMP_COMPARE
457 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
460 /* check if a package's nevr matches a dependency */
463 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
465 Reldep *rd = GETRELDEP(pool, d);
468 int flags = rd->flags;
477 return pool_match_nevr(pool, s, name);
479 if (pool_match_nevr(pool, s, name))
481 return pool_match_nevr(pool, s, evr);
484 if (!pool_match_nevr(pool, s, name))
486 return pool_match_nevr(pool, s, evr);
491 if (!pool_match_nevr(pool, s, name))
494 return flags & 2 ? 1 : 0;
499 if (flags != 2 && flags != 5)
501 if ((flags & (1 << (1 + pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
506 /* match (flags, evr) against provider (pflags, pevr) */
508 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
510 if (!pflags || !flags || pflags >= 8 || flags >= 8)
512 if (flags == 7 || pflags == 7)
513 return 1; /* rel provides every version */
514 if ((pflags & flags & 5) != 0)
515 return 1; /* both rels show in the same direction */
518 if ((pflags & flags & 2) != 0)
519 return 1; /* both have '=', match */
523 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
524 if ((f & (1 << (1 + pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
530 /* match two dependencies (d1 = provider) */
533 pool_match_dep(Pool *pool, Id d1, Id d2)
543 rd2 = GETRELDEP(pool, d2);
544 return pool_match_dep(pool, d1, rd2->name);
546 rd1 = GETRELDEP(pool, d1);
549 return pool_match_dep(pool, rd1->name, d2);
551 rd2 = GETRELDEP(pool, d2);
552 /* first match name */
553 if (!pool_match_dep(pool, rd1->name, rd2->name))
555 /* name matches, check flags and evr */
556 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
562 * add packages fulfilling the relation to whatprovides array
563 * no exact providers, do range match
568 pool_addrelproviders(Pool *pool, Id d)
570 Reldep *rd = GETRELDEP(pool, d);
576 int flags = rd->flags;
581 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
585 /* special relation */
593 wp = pool_whatprovides(pool, name);
594 pp2 = pool_whatprovides_ptr(pool, evr);
595 pp = pool->whatprovidesdata + wp;
596 while ((p = *pp++) != 0)
598 for (pp3 = pp2; *pp3; pp3++)
602 queue_push(&plist, p); /* found it */
608 wp = pool_whatprovides(pool, name);
609 pp = pool->whatprovidesdata + wp;
611 wp = pool_whatprovides(pool, evr);
615 while ((p = *pp++) != 0)
616 queue_push(&plist, p);
618 pp = pool_whatprovides_ptr(pool, evr);
619 while ((p = *pp++) != 0)
620 queue_pushunique(&plist, p);
621 if (plist.count != cnt)
626 if (name == NAMESPACE_OTHERPROVIDERS)
628 wp = pool_whatprovides(pool, evr);
631 if (pool->nscallback)
633 /* ask callback which packages provide the dependency
635 * 1: the system (aka SYSTEMSOLVABLE)
636 * >1: set of packages, stored as offset on whatprovidesdata
638 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
642 queue_push(&plist, SYSTEMSOLVABLE);
646 /* small hack: make it possible to match <pkg>.src
647 * we have to iterate over the solvables as src packages do not
648 * provide anything, thus they are not indexed in our
649 * whatprovides hash */
653 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
655 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
657 if (pool_match_nevr(pool, s, name))
658 queue_push(&plist, p);
662 wp = pool_whatprovides(pool, name);
663 pp = pool->whatprovidesdata + wp;
664 while ((p = *pp++) != 0)
666 Solvable *s = pool->solvables + p;
668 queue_push(&plist, p);
673 case REL_FILECONFLICT:
674 pp = pool_whatprovides_ptr(pool, name);
675 while ((p = *pp++) != 0)
677 Id origd = MAKERELDEP(d);
678 Solvable *s = pool->solvables + p;
681 pidp = s->repo->idarraydata + s->provides;
682 while ((pid = *pidp++) != 0)
686 queue_push(&plist, p);
694 /* we can reuse an existing entry */
696 pool->whatprovides_rel[d] = wp;
702 /* simple version comparison relation */
704 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
706 pp = pool_whatprovides_ptr(pool, name);
707 while (ISRELDEP(name))
709 rd = GETRELDEP(pool, name);
712 while ((p = *pp++) != 0)
714 Solvable *s = pool->solvables + p;
717 /* no provides - check nevr */
718 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
719 queue_push(&plist, p);
722 /* solvable p provides name in some rels */
723 pidp = s->repo->idarraydata + s->provides;
724 while ((pid = *pidp++) != 0)
728 if (pool->disttype == DISTTYPE_DEB)
729 continue; /* unversioned provides can never match versioned deps */
733 continue; /* wrong provides name */
734 prd = GETRELDEP(pool, pid);
735 if (prd->name != name)
736 continue; /* wrong provides name */
737 /* right package, both deps are rels. check flags/evr */
738 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
742 continue; /* none of the providers matched */
743 queue_push(&plist, p);
745 /* make our system solvable provide all unknown rpmlib() stuff */
746 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
747 queue_push(&plist, SYSTEMSOLVABLE);
749 /* add providers to whatprovides */
751 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
753 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
756 return pool->whatprovides_rel[d];
759 /*************************************************************************/
762 pool_debug(Pool *pool, int type, const char *format, ...)
767 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
769 if ((pool->debugmask & type) == 0)
772 va_start(args, format);
773 if (!pool->debugcallback)
775 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
776 vprintf(format, args);
778 vfprintf(stderr, format, args);
781 vsnprintf(buf, sizeof(buf), format, args);
782 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
786 pool_setdebuglevel(Pool *pool, int level)
788 int mask = SOLV_DEBUG_RESULT;
790 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
792 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
794 mask |= SOLV_DEBUG_PROPAGATE;
796 mask |= SOLV_DEBUG_RULE_CREATION;
797 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
798 pool->debugmask = mask;
801 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
803 pool->debugcallback = debugcallback;
804 pool->debugcallbackdata = debugcallbackdata;
807 void pool_setdebugmask(Pool *pool, int mask)
809 pool->debugmask = mask;
812 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
814 pool->loadcallback = cb;
815 pool->loadcallbackdata = loadcbdata;
818 /*************************************************************************/
828 #define SEARCHFILES_BLOCK 127
831 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
835 struct searchfiles *csf;
837 while ((dep = *ida++) != 0)
840 while (ISRELDEP(dep))
843 sid = pool->ss.nstrings + GETRELID(dep);
844 if (MAPTST(&csf->seen, sid))
849 MAPSET(&csf->seen, sid);
850 rd = GETRELDEP(pool, dep);
853 else if (rd->flags == REL_NAMESPACE)
855 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
858 if (!csf || MAPTST(&csf->seen, sid))
863 MAPSET(&csf->seen, sid);
867 else if (rd->flags == REL_FILECONFLICT)
877 pool_addfileprovides_dep(pool, ids, csf, isf);
883 if (MAPTST(&csf->seen, dep))
885 MAPSET(&csf->seen, dep);
886 s = pool_id2str(pool, dep);
889 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
890 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
891 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
892 csf->ids[csf->nfiles] = dep;
893 sr = strrchr(s, '/');
894 csf->names[csf->nfiles] = solv_strdup(sr + 1);
895 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
897 strncpy(csf->dirs[csf->nfiles], s, sr - s);
898 csf->dirs[csf->nfiles][sr - s] = 0;
903 struct addfileprovides_cbdata {
917 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
919 struct addfileprovides_cbdata *cbd = cbdata;
922 if (!cbd->useddirs.size)
924 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
925 for (i = 0; i < cbd->nfiles; i++)
928 if (MAPTST(&cbd->providedids, cbd->ids[i]))
933 did = repodata_str2dir(data, cbd->dirs[i], 0);
936 MAPSET(&cbd->useddirs, did);
939 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
941 for (i = 0; i < cbd->nfiles; i++)
943 if (cbd->dids[i] != value->id)
945 if (!strcmp(cbd->names[i], value->str))
948 if (i == cbd->nfiles)
950 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
955 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
961 int i, j, repoid, repodataid;
962 int provstart, provend;
964 int ndone, incomplete;
969 cbd->nfiles = sf->nfiles;
971 cbd->dirs = sf->dirs;
972 cbd->names = sf->names;
973 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
974 map_init(&cbd->providedids, pool->ss.nstrings);
977 repo = repoonly ? repoonly : pool->repos[repoid];
978 map_init(&donemap, pool->nsolvables);
979 queue_init(&fileprovidesq);
980 provstart = provend = 0;
983 if (!repo || repo->disabled)
985 if (repoonly || ++repoid == pool->nrepos)
987 repo = pool->repos[repoid];
991 FOR_REPODATAS(repo, repodataid, data)
993 if (ndone >= repo->nsolvables)
996 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
998 map_empty(&cbd->providedids);
999 for (i = 0; i < fileprovidesq.count; i++)
1000 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1001 provstart = data->start;
1002 provend = data->end;
1003 for (i = 0; i < cbd->nfiles; i++)
1004 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1006 if (i == cbd->nfiles)
1008 /* great! no need to search files */
1009 for (p = data->start; p < data->end; p++)
1010 if (pool->solvables[p].repo == repo)
1012 if (MAPTST(&donemap, p))
1014 MAPSET(&donemap, p);
1021 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1024 if (data->start < provstart || data->end > provend)
1026 map_empty(&cbd->providedids);
1027 provstart = provend = 0;
1030 /* check if the data is incomplete */
1032 if (data->state == REPODATA_AVAILABLE)
1034 for (j = 1; j < data->nkeys; j++)
1035 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1037 if (j < data->nkeys)
1040 for (i = 0; i < cbd->nfiles; i++)
1041 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1042 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1044 for (i = 0; i < cbd->nfiles; i++)
1045 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1047 if (i < cbd->nfiles)
1053 map_init(&cbd->useddirs, 0);
1054 for (p = data->start; p < data->end; p++)
1055 if (pool->solvables[p].repo == repo)
1057 if (MAPTST(&donemap, p))
1059 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1062 MAPSET(&donemap, p);
1066 map_free(&cbd->useddirs);
1069 if (repoonly || ++repoid == pool->nrepos)
1071 repo = pool->repos[repoid];
1074 queue_free(&fileprovidesq);
1075 map_free(&cbd->providedids);
1079 pool_addfileprovides_queue(Pool *pool, Queue *idq)
1082 Repo *installed, *repo;
1083 struct searchfiles sf, isf, *isfp;
1084 struct addfileprovides_cbdata cbd;
1088 installed = pool->installed;
1089 now = solv_timems(0);
1090 memset(&sf, 0, sizeof(sf));
1091 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1092 memset(&isf, 0, sizeof(isf));
1093 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1097 isfp = installed ? &isf : 0;
1098 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1104 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1106 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1108 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1110 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1112 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1114 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1116 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1119 map_free(&isf.seen);
1120 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1125 for (i = 0; i < sf.nfiles; i++)
1126 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1128 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1130 for (i = 0; i < sf.nfiles; i++)
1131 queue_push(idq, sf.ids[i]);
1133 for (i = 0; i < sf.nfiles; i++)
1135 solv_free(sf.dirs[i]);
1136 solv_free(sf.names[i]);
1139 solv_free(sf.names);
1144 for (i = 0; i < isf.nfiles; i++)
1145 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1148 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1150 for (i = 0; i < isf.nfiles; i++)
1152 solv_free(isf.dirs[i]);
1153 solv_free(isf.names[i]);
1155 solv_free(isf.dirs);
1156 solv_free(isf.names);
1158 solv_free(cbd.dids);
1159 pool_freewhatprovides(pool); /* as we have added provides */
1160 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1164 pool_addfileprovides(Pool *pool)
1166 pool_addfileprovides_queue(pool, 0);
1170 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)
1174 if (pool->solvables[p].repo)
1175 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1178 /* FIXME: obey callback return value! */
1179 for (p = 1; p < pool->nsolvables; p++)
1180 if (pool->solvables[p].repo)
1181 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1185 pool_clear_pos(Pool *pool)
1187 memset(&pool->pos, 0, sizeof(pool->pos));
1192 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1196 pool->languagecache = solv_free(pool->languagecache);
1197 pool->languagecacheother = 0;
1198 if (pool->nlanguages)
1200 for (i = 0; i < pool->nlanguages; i++)
1201 free((char *)pool->languages[i]);
1202 free(pool->languages);
1204 pool->nlanguages = nlanguages;
1207 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1208 for (i = 0; i < pool->nlanguages; i++)
1209 pool->languages[i] = solv_strdup(languages[i]);
1213 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1219 if (!lang || !*lang)
1221 n = pool_id2str(pool, id);
1222 l = strlen(n) + strlen(lang) + 2;
1223 if (l > sizeof(buf))
1224 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1227 sprintf(p, "%s:%s", n, lang);
1228 id = pool_str2id(pool, p, create);
1235 pool_alloctmpspace(Pool *pool, int len)
1237 int n = pool->tmpspace.n;
1240 if (len > pool->tmpspace.len[n])
1242 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1243 pool->tmpspace.len[n] = len + 32;
1245 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1246 return pool->tmpspace.buf[n];
1250 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1255 n = oldn = pool->tmpspace.n;
1259 n = POOL_TMPSPACEBUF - 1;
1262 if (pool->tmpspace.buf[n] != space)
1264 if (len > pool->tmpspace.len[n])
1266 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1267 pool->tmpspace.len[n] = len + 32;
1269 return pool->tmpspace.buf[n];
1276 pool_freetmpspace(Pool *pool, const char *space)
1278 int n = pool->tmpspace.n;
1281 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1282 if (pool->tmpspace.buf[n] == space)
1283 pool->tmpspace.n = n;
1287 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1291 l1 = str1 ? strlen(str1) : 0;
1292 l2 = str2 ? strlen(str2) : 0;
1293 l3 = str3 ? strlen(str3) : 0;
1294 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1315 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1320 l1 = str1 ? strlen(str1) : 0;
1321 l2 = str2 ? strlen(str2) : 0;
1322 l3 = str3 ? strlen(str3) : 0;
1323 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1327 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1350 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1355 s = pool_alloctmpspace(pool, 2 * len + 1);
1356 solv_bin2hex(buf, len, s);
1360 /*******************************************************************/
1372 struct mptree *mptree;
1383 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1385 struct ducbdata *cbd = cbdata;
1388 if (data != cbd->olddata)
1390 Id dn, mp, comp, *dirmap, *dirs;
1392 const char *compstr;
1393 struct mptree *mptree;
1395 /* create map from dir to mptree */
1396 cbd->dirmap = solv_free(cbd->dirmap);
1398 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1399 mptree = cbd->mptree;
1401 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1415 if (!mptree[mp].child)
1420 if (data->localpool)
1421 compstr = stringpool_id2str(&data->spool, comp);
1423 compstr = pool_id2str(data->repo->pool, comp);
1424 compl = strlen(compstr);
1425 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1426 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1428 dirmap[dn] = i ? i : -mp;
1430 /* change dirmap to point to mountpoint instead of mptree */
1431 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1434 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1436 cbd->dirmap = dirmap;
1437 cbd->nmap = data->dirpool.ndirs;
1438 cbd->olddata = data;
1441 if (value->id < 0 || value->id >= cbd->nmap)
1443 mp = cbd->dirmap[value->id];
1446 if (cbd->addsub > 0)
1448 cbd->mps[mp].kbytes += value->num;
1449 cbd->mps[mp].files += value->num2;
1453 cbd->mps[mp].kbytes -= value->num;
1454 cbd->mps[mp].files -= value->num2;
1460 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1463 if (mptree[pos].mountpoint == -1)
1464 mptree[pos].mountpoint = mountpoint;
1466 mountpoint = mptree[pos].mountpoint;
1467 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1468 propagate_mountpoints(mptree, i, mountpoint);
1471 #define MPTREE_BLOCK 15
1474 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1477 const char *path, *compstr;
1478 struct mptree *mptree;
1482 struct ducbdata cbd;
1486 Repo *oldinstalled = pool->installed;
1488 memset(&ignoredu, 0, sizeof(ignoredu));
1495 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1498 mptree[0].sibling = 0;
1499 mptree[0].child = 0;
1501 mptree[0].compl = 0;
1502 mptree[0].mountpoint = -1;
1505 /* create component tree */
1506 for (mp = 0; mp < nmps; mp++)
1511 path = mps[mp].path;
1516 if ((p = strchr(path, '/')) == 0)
1519 compl = strlen(compstr);
1530 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1531 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1535 /* create new node */
1536 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1538 mptree[i].sibling = mptree[pos].child;
1539 mptree[i].child = 0;
1540 mptree[i].comp = compstr;
1541 mptree[i].compl = compl;
1542 mptree[i].mountpoint = -1;
1543 mptree[pos].child = i;
1547 mptree[pos].mountpoint = mp;
1550 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1553 for (i = 0; i < nmptree; i++)
1555 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1556 printf("#%d child: %d\n", i, mptree[i].child);
1557 printf("#%d comp: %s\n", i, mptree[i].comp);
1558 printf("#%d compl: %d\n", i, mptree[i].compl);
1559 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1563 cbd.mptree = mptree;
1565 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1567 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1569 if (!MAPTST(installedmap, sp))
1572 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1573 if (!cbd.hasdu && oldinstalled)
1576 /* no du data available, ignore data of all installed solvables we obsolete */
1578 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1581 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1582 while ((obs = *obsp++) != 0)
1583 FOR_PROVIDES(op, opp, obs)
1584 if (op >= oldinstalled->start && op < oldinstalled->end)
1585 MAPSET(&ignoredu, op - oldinstalled->start);
1587 FOR_PROVIDES(op, opp, s->name)
1588 if (pool->solvables[op].name == s->name)
1589 if (op >= oldinstalled->start && op < oldinstalled->end)
1590 MAPSET(&ignoredu, op - oldinstalled->start);
1596 /* assumes we allways have du data for installed solvables */
1597 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1599 if (MAPTST(installedmap, sp))
1601 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1603 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1607 map_free(&ignoredu);
1608 solv_free(cbd.dirmap);
1613 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1618 Repo *oldinstalled = pool->installed;
1620 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1622 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1624 if (!MAPTST(installedmap, sp))
1626 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1630 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1632 if (MAPTST(installedmap, sp))
1634 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1642 * 2: conflicts with installed
1643 * 8: interesting (only true if installed)
1647 static inline Id dep2name(Pool *pool, Id dep)
1649 while (ISRELDEP(dep))
1651 Reldep *rd = rd = GETRELDEP(pool, dep);
1657 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1660 Solvable *sn = pool->solvables + n;
1662 FOR_PROVIDES(p, pp, sn->name)
1664 Solvable *s = pool->solvables + p;
1665 if (s->name != sn->name || s->arch != sn->arch)
1667 if ((map[p] & 9) != 9)
1669 if (pool_match_nevr(pool, pool->solvables + p, con))
1671 return 1; /* found installed package that doesn't conflict */
1676 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1680 FOR_PROVIDES(p, pp, dep)
1682 if (p == SYSTEMSOLVABLE)
1683 return 1; /* always boring, as never constraining */
1684 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1686 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1687 if (providedbyinstalled_multiversion(pool, map, p, dep))
1689 if ((map[p] & 9) == 9)
1697 * pool_trivial_installable - calculate if a set of solvables is
1698 * trivial installable without any other installs/deinstalls of
1699 * packages not belonging to the set.
1701 * the state is returned in the result queue:
1702 * 1: solvable is installable without any other package changes
1703 * 0: solvable is not installable
1704 * -1: solvable is installable, but doesn't constrain any installed packages
1708 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1711 Id p, *dp, con, *conp, req, *reqp;
1715 map = solv_calloc(pool->nsolvables, 1);
1716 for (p = 1; p < pool->nsolvables; p++)
1718 if (!MAPTST(installedmap, p))
1721 s = pool->solvables + p;
1724 conp = s->repo->idarraydata + s->conflicts;
1725 while ((con = *conp++) != 0)
1727 dp = pool_whatprovides_ptr(pool, con);
1729 map[p] |= 2; /* XXX: self conflict ? */
1732 for (i = 0; i < pkgs->count; i++)
1733 map[pkgs->elements[i]] = 16;
1735 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1737 if (i == pkgs->count)
1739 p = pkgs->elements[i];
1740 if ((map[p] & 16) == 0)
1742 if ((map[p] & 2) != 0)
1747 s = pool->solvables + p;
1751 reqp = s->repo->idarraydata + s->requires;
1752 while ((req = *reqp++) != 0)
1754 if (req == SOLVABLE_PREREQMARKER)
1756 r = providedbyinstalled(pool, map, req, 0, 0);
1759 /* decided and miss */
1763 m |= r; /* 1 | 9 | 16 | 17 */
1772 int ispatch = 0; /* see solver.c patch handling */
1774 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1776 conp = s->repo->idarraydata + s->conflicts;
1777 while ((con = *conp++) != 0)
1779 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1784 if ((m == 1 || m == 17) && ISRELDEP(con))
1786 con = dep2name(pool, con);
1787 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1792 continue; /* found a conflict */
1795 if (s->repo && s->repo != oldinstalled)
1797 Id p2, obs, *obsp, *pp;
1801 obsp = s->repo->idarraydata + s->obsoletes;
1802 while ((obs = *obsp++) != 0)
1804 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1813 FOR_PROVIDES(p2, pp, s->name)
1815 s2 = pool->solvables + p2;
1816 if (s2->name == s->name && (map[p2] & 1) != 0)
1833 queue_init_clone(res, pkgs);
1834 for (i = 0; i < pkgs->count; i++)
1836 m = map[pkgs->elements[i]];
1843 res->elements[i] = r;
1849 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1851 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1855 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1857 if (entry == SOLVID_POS && pool->pos.repo)
1858 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1861 return solvable_lookup_str(pool->solvables + entry, keyname);
1865 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1867 if (entry == SOLVID_POS && pool->pos.repo)
1869 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1870 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1871 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1875 return solvable_lookup_id(pool->solvables + entry, keyname);
1879 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1881 if (entry == SOLVID_POS && pool->pos.repo)
1884 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1890 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1894 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1896 if (entry == SOLVID_POS && pool->pos.repo)
1897 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1900 return solvable_lookup_void(pool->solvables + entry, keyname);
1903 const unsigned char *
1904 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1906 if (entry == SOLVID_POS && pool->pos.repo)
1907 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1910 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1914 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1916 if (entry == SOLVID_POS && pool->pos.repo)
1918 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1919 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1923 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1927 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1929 int hadhashes = pool->relhashtbl ? 1 : 0;
1935 if (!conflicts->count)
1937 pool_freewhatprovides(pool);
1938 for (i = 0; i < conflicts->count; i += 5)
1940 fn = conflicts->elements[i];
1941 p = conflicts->elements[i + 1];
1942 md5 = conflicts->elements[i + 2];
1943 q = conflicts->elements[i + 3];
1944 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1945 s = pool->solvables + p;
1948 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1949 s = pool->solvables + q;
1952 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1955 pool_freeidhashes(pool);