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));
56 s = pool->solvables + SYSTEMSOLVABLE;
57 s->name = SYSTEM_SYSTEM;
58 s->arch = ARCH_NOARCH;
61 queue_init(&pool->vendormap);
63 pool->debugmask = SOLV_DEBUG_RESULT; /* FIXME */
65 pool->obsoleteusescolors = 1;
68 pool->allowselfconflicts = 1;
69 # ifdef MULTI_SEMANTICS
70 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 = 0; i < pool->nrepos; i++)
112 repo_freedata(pool->repos[i]);
113 pool->repos = solv_free(pool->repos);
115 /* the first two solvables don't belong to a repo */
116 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
119 #ifdef MULTI_SEMANTICS
121 pool_setdisttype(Pool *pool, int disttype)
123 pool->disttype = disttype;
128 pool_add_solvable(Pool *pool)
130 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
131 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
132 return pool->nsolvables++;
136 pool_add_solvable_block(Pool *pool, int count)
138 Id nsolvables = pool->nsolvables;
141 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
142 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
143 pool->nsolvables += count;
148 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
152 if (reuseids && start + count == pool->nsolvables)
154 /* might want to shrink solvable array */
155 pool->nsolvables = start;
158 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
163 pool_set_installed(Pool *pool, Repo *installed)
165 if (pool->installed == installed)
167 pool->installed = installed;
168 pool_freewhatprovides(pool);
172 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
177 oa = pool->whatprovides[*(Id *)ap];
178 ob = pool->whatprovides[*(Id *)bp];
180 return *(Id *)ap - *(Id *)bp;
185 da = pool->whatprovidesdata + oa;
186 db = pool->whatprovidesdata + ob;
188 if ((r = (*da++ - *db++)) != 0)
192 return *(Id *)ap - *(Id *)bp;
196 * pool_shrink_whatprovides - unify whatprovides data
198 * whatprovides_rel must be empty for this to work!
202 pool_shrink_whatprovides(Pool *pool)
206 Id lastid, *last, *dp, *lp;
210 if (pool->ss.nstrings < 3)
212 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
213 for (id = 0; id < pool->ss.nstrings; id++)
215 solv_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
218 for (i = 1; i < pool->ss.nstrings; i++)
221 o = pool->whatprovides[id];
222 if (o == 0 || o == 1)
224 dp = pool->whatprovidesdata + o;
238 pool->whatprovides[id] = -lastid;
242 last = pool->whatprovidesdata + o;
246 dp = pool->whatprovidesdata + 2;
247 for (id = 1; id < pool->ss.nstrings; id++)
249 o = pool->whatprovides[id];
250 if (o == 0 || o == 1)
257 pool->whatprovides[id] = pool->whatprovides[i];
260 lp = pool->whatprovidesdata + o;
263 pool->whatprovides[id] = dp - pool->whatprovidesdata;
264 while ((*dp++ = *lp++) != 0)
267 o = dp - pool->whatprovidesdata;
268 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
269 if (pool->whatprovidesdataoff == o)
271 r = pool->whatprovidesdataoff - o;
272 pool->whatprovidesdataoff = o;
273 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
274 if (r > pool->whatprovidesdataleft)
275 r = pool->whatprovidesdataleft;
276 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
281 * pool_createwhatprovides()
283 * create hashes over pool of solvables to ease provide lookups
287 pool_createwhatprovides(Pool *pool)
289 int i, num, np, extra;
294 Offset *whatprovides;
295 Id *whatprovidesdata, *d;
296 Repo *installed = pool->installed;
299 now = solv_timems(0);
300 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
301 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
303 pool_freeidhashes(pool); /* XXX: should not be here! */
304 pool_freewhatprovides(pool);
305 num = pool->ss.nstrings;
306 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
307 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
309 /* count providers for each name */
310 for (i = pool->nsolvables - 1; i > 0; i--)
313 s = pool->solvables + i;
314 if (!s->provides || !s->repo || s->repo->disabled)
316 /* we always need the installed solvable in the whatprovides data,
317 otherwise obsoletes/conflicts on them won't work */
318 if (s->repo != installed && !pool_installable(pool, s))
320 pp = s->repo->idarraydata + s->provides;
321 while ((id = *pp++) != 0)
325 Reldep *rd = GETRELDEP(pool, id);
328 whatprovides[id]++; /* inc count of providers */
332 off = 2; /* first entry is undef, second is empty list */
333 np = 0; /* number of names provided */
334 for (i = 0, idp = whatprovides; i < num; i++, idp++)
337 if (!n) /* no providers */
339 off += n; /* make space for all providers */
340 *idp = off++; /* now idp points to terminating zero */
341 np++; /* inc # of provider 'slots' for stats */
344 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
346 /* reserve some space for relation data */
347 extra = 2 * pool->nrels;
351 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
353 /* alloc space for all providers + extra */
354 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
356 /* now fill data for all provides */
357 for (i = pool->nsolvables - 1; i > 0; i--)
360 s = pool->solvables + i;
361 if (!s->provides || !s->repo || s->repo->disabled)
363 if (s->repo != installed && !pool_installable(pool, s))
366 /* for all provides of this solvable */
367 pp = s->repo->idarraydata + s->provides;
368 while ((id = *pp++) != 0)
372 Reldep *rd = GETRELDEP(pool, id);
375 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
376 if (*d != i) /* don't add same solvable twice */
383 pool->whatprovidesdata = whatprovidesdata;
384 pool->whatprovidesdataoff = off;
385 pool->whatprovidesdataleft = extra;
386 pool_shrink_whatprovides(pool);
387 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)));
388 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
392 * free all of our whatprovides data
393 * be careful, everything internalized with pool_queuetowhatprovides is
397 pool_freewhatprovides(Pool *pool)
399 pool->whatprovides = solv_free(pool->whatprovides);
400 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
401 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
402 pool->whatprovidesdataoff = 0;
403 pool->whatprovidesdataleft = 0;
407 /******************************************************************************/
410 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
412 * on-demand filling of provider information
413 * move queue data into whatprovidesdata
415 * returns: Offset into whatprovides
419 pool_queuetowhatprovides(Pool *pool, Queue *q)
422 int count = q->count;
424 if (count == 0) /* queue empty -> 1 */
427 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
428 if (pool->whatprovidesdataleft < count + 1)
430 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
431 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
432 pool->whatprovidesdataleft = count + 4096;
435 /* copy queue to next free slot */
436 off = pool->whatprovidesdataoff;
437 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
439 /* adapt count and ID_NULL-terminate */
440 pool->whatprovidesdataoff += count;
441 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
442 pool->whatprovidesdataleft -= count + 1;
448 /*************************************************************************/
450 #if defined(MULTI_SEMANTICS)
451 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
452 #elif defined(DEBIAN_SEMANTICS)
453 # define EVRCMP_DEPCMP EVRCMP_COMPARE
455 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
458 /* check if a package's nevr matches a dependency */
461 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
463 Reldep *rd = GETRELDEP(pool, d);
466 int flags = rd->flags;
475 return pool_match_nevr(pool, s, name);
477 if (pool_match_nevr(pool, s, name))
479 return pool_match_nevr(pool, s, evr);
482 if (!pool_match_nevr(pool, s, name))
484 return pool_match_nevr(pool, s, evr);
489 if (!pool_match_nevr(pool, s, name))
492 return flags & 2 ? 1 : 0;
497 if (flags != 2 && flags != 5)
499 if ((flags & (1 << (1 + pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
504 /* match (flags, evr) against provider (pflags, pevr) */
506 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
508 if (!pflags || !flags || pflags >= 8 || flags >= 8)
510 if (flags == 7 || pflags == 7)
511 return 1; /* rel provides every version */
512 if ((pflags & flags & 5) != 0)
513 return 1; /* both rels show in the same direction */
516 if ((pflags & flags & 2) != 0)
517 return 1; /* both have '=', match */
521 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
522 if ((f & (1 << (1 + pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
528 /* match two dependencies (d1 = provider) */
531 pool_match_dep(Pool *pool, Id d1, Id d2)
541 rd2 = GETRELDEP(pool, d2);
542 return pool_match_dep(pool, d1, rd2->name);
544 rd1 = GETRELDEP(pool, d1);
547 return pool_match_dep(pool, rd1->name, d2);
549 rd2 = GETRELDEP(pool, d2);
550 /* first match name */
551 if (!pool_match_dep(pool, rd1->name, rd2->name))
553 /* name matches, check flags and evr */
554 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
560 * add packages fulfilling the relation to whatprovides array
561 * no exact providers, do range match
566 pool_addrelproviders(Pool *pool, Id d)
568 Reldep *rd = GETRELDEP(pool, d);
574 int flags = rd->flags;
579 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
583 /* special relation */
591 wp = pool_whatprovides(pool, name);
592 pp2 = pool_whatprovides_ptr(pool, evr);
593 pp = pool->whatprovidesdata + wp;
594 while ((p = *pp++) != 0)
596 for (pp3 = pp2; *pp3; pp3++)
600 queue_push(&plist, p); /* found it */
606 wp = pool_whatprovides(pool, name);
607 pp = pool->whatprovidesdata + wp;
609 wp = pool_whatprovides(pool, evr);
613 while ((p = *pp++) != 0)
614 queue_push(&plist, p);
616 pp = pool_whatprovides_ptr(pool, evr);
617 while ((p = *pp++) != 0)
618 queue_pushunique(&plist, p);
619 if (plist.count != cnt)
624 if (name == NAMESPACE_OTHERPROVIDERS)
626 wp = pool_whatprovides(pool, evr);
629 if (pool->nscallback)
631 /* ask callback which packages provide the dependency
633 * 1: the system (aka SYSTEMSOLVABLE)
634 * >1: set of packages, stored as offset on whatprovidesdata
636 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
640 queue_push(&plist, SYSTEMSOLVABLE);
644 /* small hack: make it possible to match <pkg>.src
645 * we have to iterate over the solvables as src packages do not
646 * provide anything, thus they are not indexed in our
647 * whatprovides hash */
651 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
653 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
655 if (pool_match_nevr(pool, s, name))
656 queue_push(&plist, p);
660 wp = pool_whatprovides(pool, name);
661 pp = pool->whatprovidesdata + wp;
662 while ((p = *pp++) != 0)
664 Solvable *s = pool->solvables + p;
666 queue_push(&plist, p);
671 case REL_FILECONFLICT:
672 pp = pool_whatprovides_ptr(pool, name);
673 while ((p = *pp++) != 0)
675 Id origd = MAKERELDEP(d);
676 Solvable *s = pool->solvables + p;
679 pidp = s->repo->idarraydata + s->provides;
680 while ((pid = *pidp++) != 0)
684 queue_push(&plist, p);
692 /* we can reuse an existing entry */
694 pool->whatprovides_rel[d] = wp;
700 /* simple version comparison relation */
702 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
704 pp = pool_whatprovides_ptr(pool, name);
705 while (ISRELDEP(name))
707 rd = GETRELDEP(pool, name);
710 while ((p = *pp++) != 0)
712 Solvable *s = pool->solvables + p;
715 /* no provides - check nevr */
716 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
717 queue_push(&plist, p);
720 /* solvable p provides name in some rels */
721 pidp = s->repo->idarraydata + s->provides;
722 while ((pid = *pidp++) != 0)
726 #if defined(MULTI_SEMANTICS)
727 if (pool->disttype == DISTTYPE_DEB)
731 #elif defined(DEBIAN_SEMANTICS)
732 continue; /* unversioned provides can
733 * never match versioned deps */
735 break; /* yes, provides all versions */
739 continue; /* wrong provides name */
740 prd = GETRELDEP(pool, pid);
741 if (prd->name != name)
742 continue; /* wrong provides name */
743 /* right package, both deps are rels. check flags/evr */
744 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
748 continue; /* none of the providers matched */
749 queue_push(&plist, p);
751 /* make our system solvable provide all unknown rpmlib() stuff */
752 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
753 queue_push(&plist, SYSTEMSOLVABLE);
755 /* add providers to whatprovides */
757 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
759 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
762 return pool->whatprovides_rel[d];
765 /*************************************************************************/
768 pool_debug(Pool *pool, int type, const char *format, ...)
773 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
775 if ((pool->debugmask & type) == 0)
778 va_start(args, format);
779 if (!pool->debugcallback)
781 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
782 vprintf(format, args);
784 vfprintf(stderr, format, args);
787 vsnprintf(buf, sizeof(buf), format, args);
788 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
792 pool_setdebuglevel(Pool *pool, int level)
794 int mask = SOLV_DEBUG_RESULT;
796 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
798 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
800 mask |= SOLV_DEBUG_PROPAGATE;
802 mask |= SOLV_DEBUG_RULE_CREATION;
803 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
804 pool->debugmask = mask;
807 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
809 pool->debugcallback = debugcallback;
810 pool->debugcallbackdata = debugcallbackdata;
813 void pool_setdebugmask(Pool *pool, int mask)
815 pool->debugmask = mask;
818 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
820 pool->loadcallback = cb;
821 pool->loadcallbackdata = loadcbdata;
824 /*************************************************************************/
834 #define SEARCHFILES_BLOCK 127
837 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
841 struct searchfiles *csf;
843 while ((dep = *ida++) != 0)
846 while (ISRELDEP(dep))
849 sid = pool->ss.nstrings + GETRELID(dep);
850 if (MAPTST(&csf->seen, sid))
855 MAPSET(&csf->seen, sid);
856 rd = GETRELDEP(pool, dep);
859 else if (rd->flags == REL_NAMESPACE)
861 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
864 if (!csf || MAPTST(&csf->seen, sid))
869 MAPSET(&csf->seen, sid);
873 else if (rd->flags == REL_FILECONFLICT)
883 pool_addfileprovides_dep(pool, ids, csf, isf);
889 if (MAPTST(&csf->seen, dep))
891 MAPSET(&csf->seen, dep);
892 s = pool_id2str(pool, dep);
895 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
896 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
897 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
898 csf->ids[csf->nfiles] = dep;
899 sr = strrchr(s, '/');
900 csf->names[csf->nfiles] = solv_strdup(sr + 1);
901 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
903 strncpy(csf->dirs[csf->nfiles], s, sr - s);
904 csf->dirs[csf->nfiles][sr - s] = 0;
909 struct addfileprovides_cbdata {
923 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
925 struct addfileprovides_cbdata *cbd = cbdata;
928 if (!cbd->useddirs.size)
930 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
931 for (i = 0; i < cbd->nfiles; i++)
934 if (MAPTST(&cbd->providedids, cbd->ids[i]))
939 did = repodata_str2dir(data, cbd->dirs[i], 0);
942 MAPSET(&cbd->useddirs, did);
945 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
947 for (i = 0; i < cbd->nfiles; i++)
949 if (cbd->dids[i] != value->id)
951 if (!strcmp(cbd->names[i], value->str))
954 if (i == cbd->nfiles)
956 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
961 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
967 int i, j, repoid, repodataid;
968 int provstart, provend;
970 int ndone, incomplete;
975 cbd->nfiles = sf->nfiles;
977 cbd->dirs = sf->dirs;
978 cbd->names = sf->names;
979 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
980 map_init(&cbd->providedids, pool->ss.nstrings);
983 repo = repoonly ? repoonly : pool->repos[0];
984 map_init(&donemap, pool->nsolvables);
985 queue_init(&fileprovidesq);
986 provstart = provend = 0;
991 if (repoonly || ++repoid == pool->nrepos)
993 repo = pool->repos[repoid];
997 FOR_REPODATAS(repo, repodataid, data)
999 if (ndone >= repo->nsolvables)
1002 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1004 map_empty(&cbd->providedids);
1005 for (i = 0; i < fileprovidesq.count; i++)
1006 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1007 provstart = data->start;
1008 provend = data->end;
1009 for (i = 0; i < cbd->nfiles; i++)
1010 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1012 if (i == cbd->nfiles)
1014 /* great! no need to search files */
1015 for (p = data->start; p < data->end; p++)
1016 if (pool->solvables[p].repo == repo)
1018 if (MAPTST(&donemap, p))
1020 MAPSET(&donemap, p);
1027 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1030 if (data->start < provstart || data->end > provend)
1032 map_empty(&cbd->providedids);
1033 provstart = provend = 0;
1036 /* check if the data is incomplete */
1038 if (data->state == REPODATA_AVAILABLE)
1040 for (j = 1; j < data->nkeys; j++)
1041 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1043 if (j < data->nkeys)
1046 for (i = 0; i < cbd->nfiles; i++)
1047 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1048 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
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])))
1053 if (i < cbd->nfiles)
1059 map_init(&cbd->useddirs, 0);
1060 for (p = data->start; p < data->end; p++)
1061 if (pool->solvables[p].repo == repo)
1063 if (MAPTST(&donemap, p))
1065 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1068 MAPSET(&donemap, p);
1072 map_free(&cbd->useddirs);
1075 if (repoonly || ++repoid == pool->nrepos)
1077 repo = pool->repos[repoid];
1080 queue_free(&fileprovidesq);
1081 map_free(&cbd->providedids);
1085 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1089 struct searchfiles sf, isf, *isfp;
1090 struct addfileprovides_cbdata cbd;
1094 now = solv_timems(0);
1095 memset(&sf, 0, sizeof(sf));
1096 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1097 memset(&isf, 0, sizeof(isf));
1098 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1100 isfp = installed ? &isf : 0;
1101 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1107 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1109 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1111 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1113 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1115 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1117 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1119 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1122 map_free(&isf.seen);
1123 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1130 for (i = 0; i < sf.nfiles; i++)
1131 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1133 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1136 sf.ids = solv_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1137 sf.ids[sf.nfiles] = 0;
1142 for (i = 0; i < sf.nfiles; i++)
1144 solv_free(sf.dirs[i]);
1145 solv_free(sf.names[i]);
1148 solv_free(sf.names);
1153 for (i = 0; i < isf.nfiles; i++)
1154 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1157 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1159 for (i = 0; i < isf.nfiles; i++)
1161 solv_free(isf.dirs[i]);
1162 solv_free(isf.names[i]);
1164 solv_free(isf.dirs);
1165 solv_free(isf.names);
1167 solv_free(cbd.dids);
1168 pool_freewhatprovides(pool); /* as we have added provides */
1169 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1173 pool_addfileprovides(Pool *pool)
1175 pool_addfileprovides_ids(pool, pool->installed, 0);
1179 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)
1183 if (pool->solvables[p].repo)
1184 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1187 /* FIXME: obey callback return value! */
1188 for (p = 1; p < pool->nsolvables; p++)
1189 if (pool->solvables[p].repo)
1190 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1194 pool_clear_pos(Pool *pool)
1196 memset(&pool->pos, 0, sizeof(pool->pos));
1201 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1205 pool->languagecache = solv_free(pool->languagecache);
1206 pool->languagecacheother = 0;
1207 if (pool->nlanguages)
1209 for (i = 0; i < pool->nlanguages; i++)
1210 free((char *)pool->languages[i]);
1211 free(pool->languages);
1213 pool->nlanguages = nlanguages;
1216 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1217 for (i = 0; i < pool->nlanguages; i++)
1218 pool->languages[i] = solv_strdup(languages[i]);
1222 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1230 n = pool_id2str(pool, id);
1231 l = strlen(n) + strlen(lang) + 2;
1232 if (l > sizeof(buf))
1233 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1236 sprintf(p, "%s:%s", n, lang);
1237 id = pool_str2id(pool, p, create);
1244 pool_alloctmpspace(Pool *pool, int len)
1246 int n = pool->tmpspace.n;
1249 if (len > pool->tmpspace.len[n])
1251 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1252 pool->tmpspace.len[n] = len + 32;
1254 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1255 return pool->tmpspace.buf[n];
1259 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1264 n = oldn = pool->tmpspace.n;
1268 n = POOL_TMPSPACEBUF - 1;
1271 if (pool->tmpspace.buf[n] != space)
1273 if (len > pool->tmpspace.len[n])
1275 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1276 pool->tmpspace.len[n] = len + 32;
1278 return pool->tmpspace.buf[n];
1285 pool_freetmpspace(Pool *pool, const char *space)
1287 int n = pool->tmpspace.n;
1290 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1291 if (pool->tmpspace.buf[n] == space)
1292 pool->tmpspace.n = n;
1296 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1300 l1 = str1 ? strlen(str1) : 0;
1301 l2 = str2 ? strlen(str2) : 0;
1302 l3 = str3 ? strlen(str3) : 0;
1303 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1324 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1329 l1 = str1 ? strlen(str1) : 0;
1330 l2 = str2 ? strlen(str2) : 0;
1331 l3 = str3 ? strlen(str3) : 0;
1332 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1336 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1359 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1364 s = pool_alloctmpspace(pool, 2 * len + 1);
1365 solv_bin2hex(buf, len, s);
1369 /*******************************************************************/
1381 struct mptree *mptree;
1392 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1394 struct ducbdata *cbd = cbdata;
1397 if (data != cbd->olddata)
1399 Id dn, mp, comp, *dirmap, *dirs;
1401 const char *compstr;
1402 struct mptree *mptree;
1404 /* create map from dir to mptree */
1405 cbd->dirmap = solv_free(cbd->dirmap);
1407 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1408 mptree = cbd->mptree;
1410 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1424 if (!mptree[mp].child)
1429 if (data->localpool)
1430 compstr = stringpool_id2str(&data->spool, comp);
1432 compstr = pool_id2str(data->repo->pool, comp);
1433 compl = strlen(compstr);
1434 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1435 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1437 dirmap[dn] = i ? i : -mp;
1439 /* change dirmap to point to mountpoint instead of mptree */
1440 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1443 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1445 cbd->dirmap = dirmap;
1446 cbd->nmap = data->dirpool.ndirs;
1447 cbd->olddata = data;
1450 if (value->id < 0 || value->id >= cbd->nmap)
1452 mp = cbd->dirmap[value->id];
1455 if (cbd->addsub > 0)
1457 cbd->mps[mp].kbytes += value->num;
1458 cbd->mps[mp].files += value->num2;
1462 cbd->mps[mp].kbytes -= value->num;
1463 cbd->mps[mp].files -= value->num2;
1469 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1472 if (mptree[pos].mountpoint == -1)
1473 mptree[pos].mountpoint = mountpoint;
1475 mountpoint = mptree[pos].mountpoint;
1476 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1477 propagate_mountpoints(mptree, i, mountpoint);
1480 #define MPTREE_BLOCK 15
1483 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1486 const char *path, *compstr;
1487 struct mptree *mptree;
1491 struct ducbdata cbd;
1495 Repo *oldinstalled = pool->installed;
1497 memset(&ignoredu, 0, sizeof(ignoredu));
1504 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1507 mptree[0].sibling = 0;
1508 mptree[0].child = 0;
1510 mptree[0].compl = 0;
1511 mptree[0].mountpoint = -1;
1514 /* create component tree */
1515 for (mp = 0; mp < nmps; mp++)
1520 path = mps[mp].path;
1525 if ((p = strchr(path, '/')) == 0)
1528 compl = strlen(compstr);
1539 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1540 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1544 /* create new node */
1545 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1547 mptree[i].sibling = mptree[pos].child;
1548 mptree[i].child = 0;
1549 mptree[i].comp = compstr;
1550 mptree[i].compl = compl;
1551 mptree[i].mountpoint = -1;
1552 mptree[pos].child = i;
1556 mptree[pos].mountpoint = mp;
1559 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1562 for (i = 0; i < nmptree; i++)
1564 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1565 printf("#%d child: %d\n", i, mptree[i].child);
1566 printf("#%d comp: %s\n", i, mptree[i].comp);
1567 printf("#%d compl: %d\n", i, mptree[i].compl);
1568 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1572 cbd.mptree = mptree;
1574 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1576 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1578 if (!MAPTST(installedmap, sp))
1581 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1582 if (!cbd.hasdu && oldinstalled)
1585 /* no du data available, ignore data of all installed solvables we obsolete */
1587 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1590 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1591 while ((obs = *obsp++) != 0)
1592 FOR_PROVIDES(op, opp, obs)
1593 if (op >= oldinstalled->start && op < oldinstalled->end)
1594 MAPSET(&ignoredu, op - oldinstalled->start);
1596 FOR_PROVIDES(op, opp, s->name)
1597 if (pool->solvables[op].name == s->name)
1598 if (op >= oldinstalled->start && op < oldinstalled->end)
1599 MAPSET(&ignoredu, op - oldinstalled->start);
1605 /* assumes we allways have du data for installed solvables */
1606 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1608 if (MAPTST(installedmap, sp))
1610 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1612 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1616 map_free(&ignoredu);
1617 solv_free(cbd.dirmap);
1622 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1627 Repo *oldinstalled = pool->installed;
1629 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1631 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1633 if (!MAPTST(installedmap, sp))
1635 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1639 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1641 if (MAPTST(installedmap, sp))
1643 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1651 * 2: conflicts with installed
1652 * 8: interesting (only true if installed)
1656 static inline Id dep2name(Pool *pool, Id dep)
1658 while (ISRELDEP(dep))
1660 Reldep *rd = rd = GETRELDEP(pool, dep);
1666 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1669 Solvable *sn = pool->solvables + n;
1671 FOR_PROVIDES(p, pp, sn->name)
1673 Solvable *s = pool->solvables + p;
1674 if (s->name != sn->name || s->arch != sn->arch)
1676 if ((map[p] & 9) != 9)
1678 if (pool_match_nevr(pool, pool->solvables + p, con))
1680 return 1; /* found installed package that doesn't conflict */
1685 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1689 FOR_PROVIDES(p, pp, dep)
1691 if (p == SYSTEMSOLVABLE)
1692 return 1; /* always boring, as never constraining */
1693 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1695 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1696 if (providedbyinstalled_multiversion(pool, map, p, dep))
1698 if ((map[p] & 9) == 9)
1706 * pool_trivial_installable - calculate if a set of solvables is
1707 * trivial installable without any other installs/deinstalls of
1708 * packages not belonging to the set.
1710 * the state is returned in the result queue:
1711 * 1: solvable is installable without any other package changes
1712 * 0: solvable is not installable
1713 * -1: solvable is installable, but doesn't constrain any installed packages
1717 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1720 Id p, *dp, con, *conp, req, *reqp;
1724 map = solv_calloc(pool->nsolvables, 1);
1725 for (p = 1; p < pool->nsolvables; p++)
1727 if (!MAPTST(installedmap, p))
1730 s = pool->solvables + p;
1733 conp = s->repo->idarraydata + s->conflicts;
1734 while ((con = *conp++) != 0)
1736 dp = pool_whatprovides_ptr(pool, con);
1738 map[p] |= 2; /* XXX: self conflict ? */
1741 for (i = 0; i < pkgs->count; i++)
1742 map[pkgs->elements[i]] = 16;
1744 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1746 if (i == pkgs->count)
1748 p = pkgs->elements[i];
1749 if ((map[p] & 16) == 0)
1751 if ((map[p] & 2) != 0)
1756 s = pool->solvables + p;
1760 reqp = s->repo->idarraydata + s->requires;
1761 while ((req = *reqp++) != 0)
1763 if (req == SOLVABLE_PREREQMARKER)
1765 r = providedbyinstalled(pool, map, req, 0, 0);
1768 /* decided and miss */
1772 m |= r; /* 1 | 9 | 16 | 17 */
1781 int ispatch = 0; /* see solver.c patch handling */
1783 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1785 conp = s->repo->idarraydata + s->conflicts;
1786 while ((con = *conp++) != 0)
1788 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1793 if ((m == 1 || m == 17) && ISRELDEP(con))
1795 con = dep2name(pool, con);
1796 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1801 continue; /* found a conflict */
1804 if (s->repo && s->repo != oldinstalled)
1806 Id p2, obs, *obsp, *pp;
1810 obsp = s->repo->idarraydata + s->obsoletes;
1811 while ((obs = *obsp++) != 0)
1813 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1822 FOR_PROVIDES(p2, pp, s->name)
1824 s2 = pool->solvables + p2;
1825 if (s2->name == s->name && (map[p2] & 1) != 0)
1842 queue_init_clone(res, pkgs);
1843 for (i = 0; i < pkgs->count; i++)
1845 m = map[pkgs->elements[i]];
1852 res->elements[i] = r;
1858 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1860 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1864 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1866 if (entry == SOLVID_POS && pool->pos.repo)
1867 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1870 return solvable_lookup_str(pool->solvables + entry, keyname);
1874 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1876 if (entry == SOLVID_POS && pool->pos.repo)
1878 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1879 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1880 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1884 return solvable_lookup_id(pool->solvables + entry, keyname);
1888 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1890 if (entry == SOLVID_POS && pool->pos.repo)
1893 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1899 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1903 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1905 if (entry == SOLVID_POS && pool->pos.repo)
1906 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1909 return solvable_lookup_void(pool->solvables + entry, keyname);
1912 const unsigned char *
1913 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1915 if (entry == SOLVID_POS && pool->pos.repo)
1916 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1919 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1923 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1925 if (entry == SOLVID_POS && pool->pos.repo)
1927 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1928 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1932 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1936 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1938 int hadhashes = pool->relhashtbl ? 1 : 0;
1944 if (!conflicts->count)
1946 pool_freewhatprovides(pool);
1947 for (i = 0; i < conflicts->count; i += 5)
1949 fn = conflicts->elements[i];
1950 p = conflicts->elements[i + 1];
1951 md5 = conflicts->elements[i + 2];
1952 q = conflicts->elements[i + 3];
1953 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1954 s = pool->solvables + p;
1957 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1958 s = pool->solvables + q;
1961 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1964 pool_freeidhashes(pool);