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++)
114 repo_freedata(pool->repos[i]);
115 pool->repos = solv_free(pool->repos);
118 /* the first two solvables don't belong to a repo */
119 pool_free_solvable_block(pool, 2, pool->nsolvables - 2, reuseids);
122 #ifdef MULTI_SEMANTICS
124 pool_setdisttype(Pool *pool, int disttype)
126 pool->disttype = disttype;
131 pool_add_solvable(Pool *pool)
133 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
134 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
135 return pool->nsolvables++;
139 pool_add_solvable_block(Pool *pool, int count)
141 Id nsolvables = pool->nsolvables;
144 pool->solvables = solv_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
145 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
146 pool->nsolvables += count;
151 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
155 if (reuseids && start + count == pool->nsolvables)
157 /* might want to shrink solvable array */
158 pool->nsolvables = start;
161 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
166 pool_set_installed(Pool *pool, Repo *installed)
168 if (pool->installed == installed)
170 pool->installed = installed;
171 pool_freewhatprovides(pool);
175 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
180 oa = pool->whatprovides[*(Id *)ap];
181 ob = pool->whatprovides[*(Id *)bp];
183 return *(Id *)ap - *(Id *)bp;
188 da = pool->whatprovidesdata + oa;
189 db = pool->whatprovidesdata + ob;
191 if ((r = (*da++ - *db++)) != 0)
195 return *(Id *)ap - *(Id *)bp;
199 * pool_shrink_whatprovides - unify whatprovides data
201 * whatprovides_rel must be empty for this to work!
205 pool_shrink_whatprovides(Pool *pool)
209 Id lastid, *last, *dp, *lp;
213 if (pool->ss.nstrings < 3)
215 sorted = solv_malloc2(pool->ss.nstrings, sizeof(Id));
216 for (id = 0; id < pool->ss.nstrings; id++)
218 solv_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
221 for (i = 1; i < pool->ss.nstrings; i++)
224 o = pool->whatprovides[id];
225 if (o == 0 || o == 1)
227 dp = pool->whatprovidesdata + o;
241 pool->whatprovides[id] = -lastid;
245 last = pool->whatprovidesdata + o;
249 dp = pool->whatprovidesdata + 2;
250 for (id = 1; id < pool->ss.nstrings; id++)
252 o = pool->whatprovides[id];
253 if (o == 0 || o == 1)
260 pool->whatprovides[id] = pool->whatprovides[i];
263 lp = pool->whatprovidesdata + o;
266 pool->whatprovides[id] = dp - pool->whatprovidesdata;
267 while ((*dp++ = *lp++) != 0)
270 o = dp - pool->whatprovidesdata;
271 POOL_DEBUG(SOLV_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
272 if (pool->whatprovidesdataoff == o)
274 r = pool->whatprovidesdataoff - o;
275 pool->whatprovidesdataoff = o;
276 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
277 if (r > pool->whatprovidesdataleft)
278 r = pool->whatprovidesdataleft;
279 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
284 * pool_createwhatprovides()
286 * create hashes over pool of solvables to ease provide lookups
290 pool_createwhatprovides(Pool *pool)
292 int i, num, np, extra;
297 Offset *whatprovides;
298 Id *whatprovidesdata, *d;
299 Repo *installed = pool->installed;
302 now = solv_timems(0);
303 POOL_DEBUG(SOLV_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
304 POOL_DEBUG(SOLV_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
306 pool_freeidhashes(pool); /* XXX: should not be here! */
307 pool_freewhatprovides(pool);
308 num = pool->ss.nstrings;
309 pool->whatprovides = whatprovides = solv_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
310 pool->whatprovides_rel = solv_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
312 /* count providers for each name */
313 for (i = pool->nsolvables - 1; i > 0; i--)
316 s = pool->solvables + i;
317 if (!s->provides || !s->repo || s->repo->disabled)
319 /* we always need the installed solvable in the whatprovides data,
320 otherwise obsoletes/conflicts on them won't work */
321 if (s->repo != installed && !pool_installable(pool, s))
323 pp = s->repo->idarraydata + s->provides;
324 while ((id = *pp++) != 0)
328 Reldep *rd = GETRELDEP(pool, id);
331 whatprovides[id]++; /* inc count of providers */
335 off = 2; /* first entry is undef, second is empty list */
336 np = 0; /* number of names provided */
337 for (i = 0, idp = whatprovides; i < num; i++, idp++)
340 if (!n) /* no providers */
342 off += n; /* make space for all providers */
343 *idp = off++; /* now idp points to terminating zero */
344 np++; /* inc # of provider 'slots' for stats */
347 POOL_DEBUG(SOLV_DEBUG_STATS, "provide ids: %d\n", np);
349 /* reserve some space for relation data */
350 extra = 2 * pool->nrels;
354 POOL_DEBUG(SOLV_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
356 /* alloc space for all providers + extra */
357 whatprovidesdata = solv_calloc(off + extra, sizeof(Id));
359 /* now fill data for all provides */
360 for (i = pool->nsolvables - 1; i > 0; i--)
363 s = pool->solvables + i;
364 if (!s->provides || !s->repo || s->repo->disabled)
366 if (s->repo != installed && !pool_installable(pool, s))
369 /* for all provides of this solvable */
370 pp = s->repo->idarraydata + s->provides;
371 while ((id = *pp++) != 0)
375 Reldep *rd = GETRELDEP(pool, id);
378 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
379 if (*d != i) /* don't add same solvable twice */
386 pool->whatprovidesdata = whatprovidesdata;
387 pool->whatprovidesdataoff = off;
388 pool->whatprovidesdataleft = extra;
389 pool_shrink_whatprovides(pool);
390 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)));
391 POOL_DEBUG(SOLV_DEBUG_STATS, "createwhatprovides took %d ms\n", solv_timems(now));
395 * free all of our whatprovides data
396 * be careful, everything internalized with pool_queuetowhatprovides is
400 pool_freewhatprovides(Pool *pool)
402 pool->whatprovides = solv_free(pool->whatprovides);
403 pool->whatprovides_rel = solv_free(pool->whatprovides_rel);
404 pool->whatprovidesdata = solv_free(pool->whatprovidesdata);
405 pool->whatprovidesdataoff = 0;
406 pool->whatprovidesdataleft = 0;
410 /******************************************************************************/
413 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
415 * on-demand filling of provider information
416 * move queue data into whatprovidesdata
418 * returns: Offset into whatprovides
422 pool_queuetowhatprovides(Pool *pool, Queue *q)
425 int count = q->count;
427 if (count == 0) /* queue empty -> 1 */
430 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
431 if (pool->whatprovidesdataleft < count + 1)
433 POOL_DEBUG(SOLV_DEBUG_STATS, "growing provides hash data...\n");
434 pool->whatprovidesdata = solv_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
435 pool->whatprovidesdataleft = count + 4096;
438 /* copy queue to next free slot */
439 off = pool->whatprovidesdataoff;
440 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
442 /* adapt count and ID_NULL-terminate */
443 pool->whatprovidesdataoff += count;
444 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
445 pool->whatprovidesdataleft -= count + 1;
451 /*************************************************************************/
453 #if defined(MULTI_SEMANTICS)
454 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
455 #elif defined(DEBIAN_SEMANTICS)
456 # define EVRCMP_DEPCMP EVRCMP_COMPARE
458 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
461 /* check if a package's nevr matches a dependency */
464 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
466 Reldep *rd = GETRELDEP(pool, d);
469 int flags = rd->flags;
478 return pool_match_nevr(pool, s, name);
480 if (pool_match_nevr(pool, s, name))
482 return pool_match_nevr(pool, s, evr);
485 if (!pool_match_nevr(pool, s, name))
487 return pool_match_nevr(pool, s, evr);
492 if (!pool_match_nevr(pool, s, name))
495 return flags & 2 ? 1 : 0;
500 if (flags != 2 && flags != 5)
502 if ((flags & (1 << (1 + pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
507 /* match (flags, evr) against provider (pflags, pevr) */
509 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
511 if (!pflags || !flags || pflags >= 8 || flags >= 8)
513 if (flags == 7 || pflags == 7)
514 return 1; /* rel provides every version */
515 if ((pflags & flags & 5) != 0)
516 return 1; /* both rels show in the same direction */
519 if ((pflags & flags & 2) != 0)
520 return 1; /* both have '=', match */
524 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
525 if ((f & (1 << (1 + pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
531 /* match two dependencies (d1 = provider) */
534 pool_match_dep(Pool *pool, Id d1, Id d2)
544 rd2 = GETRELDEP(pool, d2);
545 return pool_match_dep(pool, d1, rd2->name);
547 rd1 = GETRELDEP(pool, d1);
550 return pool_match_dep(pool, rd1->name, d2);
552 rd2 = GETRELDEP(pool, d2);
553 /* first match name */
554 if (!pool_match_dep(pool, rd1->name, rd2->name))
556 /* name matches, check flags and evr */
557 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
563 * add packages fulfilling the relation to whatprovides array
564 * no exact providers, do range match
569 pool_addrelproviders(Pool *pool, Id d)
571 Reldep *rd = GETRELDEP(pool, d);
577 int flags = rd->flags;
582 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
586 /* special relation */
594 wp = pool_whatprovides(pool, name);
595 pp2 = pool_whatprovides_ptr(pool, evr);
596 pp = pool->whatprovidesdata + wp;
597 while ((p = *pp++) != 0)
599 for (pp3 = pp2; *pp3; pp3++)
603 queue_push(&plist, p); /* found it */
609 wp = pool_whatprovides(pool, name);
610 pp = pool->whatprovidesdata + wp;
612 wp = pool_whatprovides(pool, evr);
616 while ((p = *pp++) != 0)
617 queue_push(&plist, p);
619 pp = pool_whatprovides_ptr(pool, evr);
620 while ((p = *pp++) != 0)
621 queue_pushunique(&plist, p);
622 if (plist.count != cnt)
627 if (name == NAMESPACE_OTHERPROVIDERS)
629 wp = pool_whatprovides(pool, evr);
632 if (pool->nscallback)
634 /* ask callback which packages provide the dependency
636 * 1: the system (aka SYSTEMSOLVABLE)
637 * >1: set of packages, stored as offset on whatprovidesdata
639 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
643 queue_push(&plist, SYSTEMSOLVABLE);
647 /* small hack: make it possible to match <pkg>.src
648 * we have to iterate over the solvables as src packages do not
649 * provide anything, thus they are not indexed in our
650 * whatprovides hash */
654 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
656 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
658 if (pool_match_nevr(pool, s, name))
659 queue_push(&plist, p);
663 wp = pool_whatprovides(pool, name);
664 pp = pool->whatprovidesdata + wp;
665 while ((p = *pp++) != 0)
667 Solvable *s = pool->solvables + p;
669 queue_push(&plist, p);
674 case REL_FILECONFLICT:
675 pp = pool_whatprovides_ptr(pool, name);
676 while ((p = *pp++) != 0)
678 Id origd = MAKERELDEP(d);
679 Solvable *s = pool->solvables + p;
682 pidp = s->repo->idarraydata + s->provides;
683 while ((pid = *pidp++) != 0)
687 queue_push(&plist, p);
695 /* we can reuse an existing entry */
697 pool->whatprovides_rel[d] = wp;
703 /* simple version comparison relation */
705 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
707 pp = pool_whatprovides_ptr(pool, name);
708 while (ISRELDEP(name))
710 rd = GETRELDEP(pool, name);
713 while ((p = *pp++) != 0)
715 Solvable *s = pool->solvables + p;
718 /* no provides - check nevr */
719 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
720 queue_push(&plist, p);
723 /* solvable p provides name in some rels */
724 pidp = s->repo->idarraydata + s->provides;
725 while ((pid = *pidp++) != 0)
729 #if defined(MULTI_SEMANTICS)
730 if (pool->disttype == DISTTYPE_DEB)
734 #elif defined(DEBIAN_SEMANTICS)
735 continue; /* unversioned provides can
736 * never match versioned deps */
738 break; /* yes, provides all versions */
742 continue; /* wrong provides name */
743 prd = GETRELDEP(pool, pid);
744 if (prd->name != name)
745 continue; /* wrong provides name */
746 /* right package, both deps are rels. check flags/evr */
747 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
751 continue; /* none of the providers matched */
752 queue_push(&plist, p);
754 /* make our system solvable provide all unknown rpmlib() stuff */
755 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
756 queue_push(&plist, SYSTEMSOLVABLE);
758 /* add providers to whatprovides */
760 POOL_DEBUG(SOLV_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
762 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
765 return pool->whatprovides_rel[d];
768 /*************************************************************************/
771 pool_debug(Pool *pool, int type, const char *format, ...)
776 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0)
778 if ((pool->debugmask & type) == 0)
781 va_start(args, format);
782 if (!pool->debugcallback)
784 if ((type & (SOLV_FATAL|SOLV_ERROR)) == 0 && !(pool->debugmask & SOLV_DEBUG_TO_STDERR))
785 vprintf(format, args);
787 vfprintf(stderr, format, args);
790 vsnprintf(buf, sizeof(buf), format, args);
791 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
795 pool_setdebuglevel(Pool *pool, int level)
797 int mask = SOLV_DEBUG_RESULT;
799 mask |= SOLV_DEBUG_STATS|SOLV_DEBUG_ANALYZE|SOLV_DEBUG_UNSOLVABLE|SOLV_DEBUG_SOLVER|SOLV_DEBUG_TRANSACTION;
801 mask |= SOLV_DEBUG_JOB|SOLV_DEBUG_SOLUTIONS|SOLV_DEBUG_POLICY;
803 mask |= SOLV_DEBUG_PROPAGATE;
805 mask |= SOLV_DEBUG_RULE_CREATION;
806 mask |= pool->debugmask & SOLV_DEBUG_TO_STDERR; /* keep bit */
807 pool->debugmask = mask;
810 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
812 pool->debugcallback = debugcallback;
813 pool->debugcallbackdata = debugcallbackdata;
816 void pool_setdebugmask(Pool *pool, int mask)
818 pool->debugmask = mask;
821 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
823 pool->loadcallback = cb;
824 pool->loadcallbackdata = loadcbdata;
827 /*************************************************************************/
837 #define SEARCHFILES_BLOCK 127
840 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
844 struct searchfiles *csf;
846 while ((dep = *ida++) != 0)
849 while (ISRELDEP(dep))
852 sid = pool->ss.nstrings + GETRELID(dep);
853 if (MAPTST(&csf->seen, sid))
858 MAPSET(&csf->seen, sid);
859 rd = GETRELDEP(pool, dep);
862 else if (rd->flags == REL_NAMESPACE)
864 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
867 if (!csf || MAPTST(&csf->seen, sid))
872 MAPSET(&csf->seen, sid);
876 else if (rd->flags == REL_FILECONFLICT)
886 pool_addfileprovides_dep(pool, ids, csf, isf);
892 if (MAPTST(&csf->seen, dep))
894 MAPSET(&csf->seen, dep);
895 s = pool_id2str(pool, dep);
898 csf->ids = solv_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
899 csf->dirs = solv_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
900 csf->names = solv_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
901 csf->ids[csf->nfiles] = dep;
902 sr = strrchr(s, '/');
903 csf->names[csf->nfiles] = solv_strdup(sr + 1);
904 csf->dirs[csf->nfiles] = solv_malloc(sr - s + 1);
906 strncpy(csf->dirs[csf->nfiles], s, sr - s);
907 csf->dirs[csf->nfiles][sr - s] = 0;
912 struct addfileprovides_cbdata {
926 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
928 struct addfileprovides_cbdata *cbd = cbdata;
931 if (!cbd->useddirs.size)
933 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
934 for (i = 0; i < cbd->nfiles; i++)
937 if (MAPTST(&cbd->providedids, cbd->ids[i]))
942 did = repodata_str2dir(data, cbd->dirs[i], 0);
945 MAPSET(&cbd->useddirs, did);
948 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
950 for (i = 0; i < cbd->nfiles; i++)
952 if (cbd->dids[i] != value->id)
954 if (!strcmp(cbd->names[i], value->str))
957 if (i == cbd->nfiles)
959 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
964 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
970 int i, j, repoid, repodataid;
971 int provstart, provend;
973 int ndone, incomplete;
978 cbd->nfiles = sf->nfiles;
980 cbd->dirs = sf->dirs;
981 cbd->names = sf->names;
982 cbd->dids = solv_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
983 map_init(&cbd->providedids, pool->ss.nstrings);
986 repo = repoonly ? repoonly : pool->repos[repoid];
987 map_init(&donemap, pool->nsolvables);
988 queue_init(&fileprovidesq);
989 provstart = provend = 0;
992 if (!repo || repo->disabled)
994 if (repoonly || ++repoid == pool->nrepos)
996 repo = pool->repos[repoid];
1000 FOR_REPODATAS(repo, repodataid, data)
1002 if (ndone >= repo->nsolvables)
1005 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
1007 map_empty(&cbd->providedids);
1008 for (i = 0; i < fileprovidesq.count; i++)
1009 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
1010 provstart = data->start;
1011 provend = data->end;
1012 for (i = 0; i < cbd->nfiles; i++)
1013 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
1015 if (i == cbd->nfiles)
1017 /* great! no need to search files */
1018 for (p = data->start; p < data->end; p++)
1019 if (pool->solvables[p].repo == repo)
1021 if (MAPTST(&donemap, p))
1023 MAPSET(&donemap, p);
1030 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1033 if (data->start < provstart || data->end > provend)
1035 map_empty(&cbd->providedids);
1036 provstart = provend = 0;
1039 /* check if the data is incomplete */
1041 if (data->state == REPODATA_AVAILABLE)
1043 for (j = 1; j < data->nkeys; j++)
1044 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1046 if (j < data->nkeys)
1049 for (i = 0; i < cbd->nfiles; i++)
1050 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1051 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1053 for (i = 0; i < cbd->nfiles; i++)
1054 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1056 if (i < cbd->nfiles)
1062 map_init(&cbd->useddirs, 0);
1063 for (p = data->start; p < data->end; p++)
1064 if (pool->solvables[p].repo == repo)
1066 if (MAPTST(&donemap, p))
1068 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1071 MAPSET(&donemap, p);
1075 map_free(&cbd->useddirs);
1078 if (repoonly || ++repoid == pool->nrepos)
1080 repo = pool->repos[repoid];
1083 queue_free(&fileprovidesq);
1084 map_free(&cbd->providedids);
1088 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1092 struct searchfiles sf, isf, *isfp;
1093 struct addfileprovides_cbdata cbd;
1097 now = solv_timems(0);
1098 memset(&sf, 0, sizeof(sf));
1099 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1100 memset(&isf, 0, sizeof(isf));
1101 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1103 isfp = installed ? &isf : 0;
1104 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1110 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1112 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1114 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1116 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1118 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1120 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1122 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1125 map_free(&isf.seen);
1126 POOL_DEBUG(SOLV_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1133 for (i = 0; i < sf.nfiles; i++)
1134 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1136 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1139 sf.ids = solv_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1140 sf.ids[sf.nfiles] = 0;
1145 for (i = 0; i < sf.nfiles; i++)
1147 solv_free(sf.dirs[i]);
1148 solv_free(sf.names[i]);
1151 solv_free(sf.names);
1156 for (i = 0; i < isf.nfiles; i++)
1157 POOL_DEBUG(SOLV_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1160 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1162 for (i = 0; i < isf.nfiles; i++)
1164 solv_free(isf.dirs[i]);
1165 solv_free(isf.names[i]);
1167 solv_free(isf.dirs);
1168 solv_free(isf.names);
1170 solv_free(cbd.dids);
1171 pool_freewhatprovides(pool); /* as we have added provides */
1172 POOL_DEBUG(SOLV_DEBUG_STATS, "addfileprovides took %d ms\n", solv_timems(now));
1176 pool_addfileprovides(Pool *pool)
1178 pool_addfileprovides_ids(pool, pool->installed, 0);
1182 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)
1186 if (pool->solvables[p].repo)
1187 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1190 /* FIXME: obey callback return value! */
1191 for (p = 1; p < pool->nsolvables; p++)
1192 if (pool->solvables[p].repo)
1193 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1197 pool_clear_pos(Pool *pool)
1199 memset(&pool->pos, 0, sizeof(pool->pos));
1204 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1208 pool->languagecache = solv_free(pool->languagecache);
1209 pool->languagecacheother = 0;
1210 if (pool->nlanguages)
1212 for (i = 0; i < pool->nlanguages; i++)
1213 free((char *)pool->languages[i]);
1214 free(pool->languages);
1216 pool->nlanguages = nlanguages;
1219 pool->languages = solv_calloc(nlanguages, sizeof(const char **));
1220 for (i = 0; i < pool->nlanguages; i++)
1221 pool->languages[i] = solv_strdup(languages[i]);
1225 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1233 n = pool_id2str(pool, id);
1234 l = strlen(n) + strlen(lang) + 2;
1235 if (l > sizeof(buf))
1236 p = solv_malloc(strlen(n) + strlen(lang) + 2);
1239 sprintf(p, "%s:%s", n, lang);
1240 id = pool_str2id(pool, p, create);
1247 pool_alloctmpspace(Pool *pool, int len)
1249 int n = pool->tmpspace.n;
1252 if (len > pool->tmpspace.len[n])
1254 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1255 pool->tmpspace.len[n] = len + 32;
1257 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1258 return pool->tmpspace.buf[n];
1262 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1267 n = oldn = pool->tmpspace.n;
1271 n = POOL_TMPSPACEBUF - 1;
1274 if (pool->tmpspace.buf[n] != space)
1276 if (len > pool->tmpspace.len[n])
1278 pool->tmpspace.buf[n] = solv_realloc(pool->tmpspace.buf[n], len + 32);
1279 pool->tmpspace.len[n] = len + 32;
1281 return pool->tmpspace.buf[n];
1288 pool_freetmpspace(Pool *pool, const char *space)
1290 int n = pool->tmpspace.n;
1293 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1294 if (pool->tmpspace.buf[n] == space)
1295 pool->tmpspace.n = n;
1299 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1303 l1 = str1 ? strlen(str1) : 0;
1304 l2 = str2 ? strlen(str2) : 0;
1305 l3 = str3 ? strlen(str3) : 0;
1306 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1327 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1332 l1 = str1 ? strlen(str1) : 0;
1333 l2 = str2 ? strlen(str2) : 0;
1334 l3 = str3 ? strlen(str3) : 0;
1335 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1339 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1362 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1367 s = pool_alloctmpspace(pool, 2 * len + 1);
1368 solv_bin2hex(buf, len, s);
1372 /*******************************************************************/
1384 struct mptree *mptree;
1395 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1397 struct ducbdata *cbd = cbdata;
1400 if (data != cbd->olddata)
1402 Id dn, mp, comp, *dirmap, *dirs;
1404 const char *compstr;
1405 struct mptree *mptree;
1407 /* create map from dir to mptree */
1408 cbd->dirmap = solv_free(cbd->dirmap);
1410 dirmap = solv_calloc(data->dirpool.ndirs, sizeof(Id));
1411 mptree = cbd->mptree;
1413 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1427 if (!mptree[mp].child)
1432 if (data->localpool)
1433 compstr = stringpool_id2str(&data->spool, comp);
1435 compstr = pool_id2str(data->repo->pool, comp);
1436 compl = strlen(compstr);
1437 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1438 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1440 dirmap[dn] = i ? i : -mp;
1442 /* change dirmap to point to mountpoint instead of mptree */
1443 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1446 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1448 cbd->dirmap = dirmap;
1449 cbd->nmap = data->dirpool.ndirs;
1450 cbd->olddata = data;
1453 if (value->id < 0 || value->id >= cbd->nmap)
1455 mp = cbd->dirmap[value->id];
1458 if (cbd->addsub > 0)
1460 cbd->mps[mp].kbytes += value->num;
1461 cbd->mps[mp].files += value->num2;
1465 cbd->mps[mp].kbytes -= value->num;
1466 cbd->mps[mp].files -= value->num2;
1472 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1475 if (mptree[pos].mountpoint == -1)
1476 mptree[pos].mountpoint = mountpoint;
1478 mountpoint = mptree[pos].mountpoint;
1479 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1480 propagate_mountpoints(mptree, i, mountpoint);
1483 #define MPTREE_BLOCK 15
1486 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1489 const char *path, *compstr;
1490 struct mptree *mptree;
1494 struct ducbdata cbd;
1498 Repo *oldinstalled = pool->installed;
1500 memset(&ignoredu, 0, sizeof(ignoredu));
1507 mptree = solv_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1510 mptree[0].sibling = 0;
1511 mptree[0].child = 0;
1513 mptree[0].compl = 0;
1514 mptree[0].mountpoint = -1;
1517 /* create component tree */
1518 for (mp = 0; mp < nmps; mp++)
1523 path = mps[mp].path;
1528 if ((p = strchr(path, '/')) == 0)
1531 compl = strlen(compstr);
1542 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1543 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1547 /* create new node */
1548 mptree = solv_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1550 mptree[i].sibling = mptree[pos].child;
1551 mptree[i].child = 0;
1552 mptree[i].comp = compstr;
1553 mptree[i].compl = compl;
1554 mptree[i].mountpoint = -1;
1555 mptree[pos].child = i;
1559 mptree[pos].mountpoint = mp;
1562 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1565 for (i = 0; i < nmptree; i++)
1567 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1568 printf("#%d child: %d\n", i, mptree[i].child);
1569 printf("#%d comp: %s\n", i, mptree[i].comp);
1570 printf("#%d compl: %d\n", i, mptree[i].compl);
1571 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1575 cbd.mptree = mptree;
1577 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1579 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1581 if (!MAPTST(installedmap, sp))
1584 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1585 if (!cbd.hasdu && oldinstalled)
1588 /* no du data available, ignore data of all installed solvables we obsolete */
1590 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1593 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1594 while ((obs = *obsp++) != 0)
1595 FOR_PROVIDES(op, opp, obs)
1596 if (op >= oldinstalled->start && op < oldinstalled->end)
1597 MAPSET(&ignoredu, op - oldinstalled->start);
1599 FOR_PROVIDES(op, opp, s->name)
1600 if (pool->solvables[op].name == s->name)
1601 if (op >= oldinstalled->start && op < oldinstalled->end)
1602 MAPSET(&ignoredu, op - oldinstalled->start);
1608 /* assumes we allways have du data for installed solvables */
1609 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1611 if (MAPTST(installedmap, sp))
1613 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1615 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1619 map_free(&ignoredu);
1620 solv_free(cbd.dirmap);
1625 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1630 Repo *oldinstalled = pool->installed;
1632 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1634 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1636 if (!MAPTST(installedmap, sp))
1638 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1642 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1644 if (MAPTST(installedmap, sp))
1646 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1654 * 2: conflicts with installed
1655 * 8: interesting (only true if installed)
1659 static inline Id dep2name(Pool *pool, Id dep)
1661 while (ISRELDEP(dep))
1663 Reldep *rd = rd = GETRELDEP(pool, dep);
1669 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1672 Solvable *sn = pool->solvables + n;
1674 FOR_PROVIDES(p, pp, sn->name)
1676 Solvable *s = pool->solvables + p;
1677 if (s->name != sn->name || s->arch != sn->arch)
1679 if ((map[p] & 9) != 9)
1681 if (pool_match_nevr(pool, pool->solvables + p, con))
1683 return 1; /* found installed package that doesn't conflict */
1688 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1692 FOR_PROVIDES(p, pp, dep)
1694 if (p == SYSTEMSOLVABLE)
1695 return 1; /* always boring, as never constraining */
1696 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1698 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1699 if (providedbyinstalled_multiversion(pool, map, p, dep))
1701 if ((map[p] & 9) == 9)
1709 * pool_trivial_installable - calculate if a set of solvables is
1710 * trivial installable without any other installs/deinstalls of
1711 * packages not belonging to the set.
1713 * the state is returned in the result queue:
1714 * 1: solvable is installable without any other package changes
1715 * 0: solvable is not installable
1716 * -1: solvable is installable, but doesn't constrain any installed packages
1720 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1723 Id p, *dp, con, *conp, req, *reqp;
1727 map = solv_calloc(pool->nsolvables, 1);
1728 for (p = 1; p < pool->nsolvables; p++)
1730 if (!MAPTST(installedmap, p))
1733 s = pool->solvables + p;
1736 conp = s->repo->idarraydata + s->conflicts;
1737 while ((con = *conp++) != 0)
1739 dp = pool_whatprovides_ptr(pool, con);
1741 map[p] |= 2; /* XXX: self conflict ? */
1744 for (i = 0; i < pkgs->count; i++)
1745 map[pkgs->elements[i]] = 16;
1747 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1749 if (i == pkgs->count)
1751 p = pkgs->elements[i];
1752 if ((map[p] & 16) == 0)
1754 if ((map[p] & 2) != 0)
1759 s = pool->solvables + p;
1763 reqp = s->repo->idarraydata + s->requires;
1764 while ((req = *reqp++) != 0)
1766 if (req == SOLVABLE_PREREQMARKER)
1768 r = providedbyinstalled(pool, map, req, 0, 0);
1771 /* decided and miss */
1775 m |= r; /* 1 | 9 | 16 | 17 */
1784 int ispatch = 0; /* see solver.c patch handling */
1786 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1788 conp = s->repo->idarraydata + s->conflicts;
1789 while ((con = *conp++) != 0)
1791 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1796 if ((m == 1 || m == 17) && ISRELDEP(con))
1798 con = dep2name(pool, con);
1799 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1804 continue; /* found a conflict */
1807 if (s->repo && s->repo != oldinstalled)
1809 Id p2, obs, *obsp, *pp;
1813 obsp = s->repo->idarraydata + s->obsoletes;
1814 while ((obs = *obsp++) != 0)
1816 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1825 FOR_PROVIDES(p2, pp, s->name)
1827 s2 = pool->solvables + p2;
1828 if (s2->name == s->name && (map[p2] & 1) != 0)
1845 queue_init_clone(res, pkgs);
1846 for (i = 0; i < pkgs->count; i++)
1848 m = map[pkgs->elements[i]];
1855 res->elements[i] = r;
1861 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1863 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1867 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1869 if (entry == SOLVID_POS && pool->pos.repo)
1870 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1873 return solvable_lookup_str(pool->solvables + entry, keyname);
1877 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1879 if (entry == SOLVID_POS && pool->pos.repo)
1881 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1882 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1883 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1887 return solvable_lookup_id(pool->solvables + entry, keyname);
1891 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1893 if (entry == SOLVID_POS && pool->pos.repo)
1896 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1902 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1906 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1908 if (entry == SOLVID_POS && pool->pos.repo)
1909 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1912 return solvable_lookup_void(pool->solvables + entry, keyname);
1915 const unsigned char *
1916 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1918 if (entry == SOLVID_POS && pool->pos.repo)
1919 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1922 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1926 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1928 if (entry == SOLVID_POS && pool->pos.repo)
1930 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1931 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1935 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1939 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1941 int hadhashes = pool->relhashtbl ? 1 : 0;
1947 if (!conflicts->count)
1949 pool_freewhatprovides(pool);
1950 for (i = 0; i < conflicts->count; i += 5)
1952 fn = conflicts->elements[i];
1953 p = conflicts->elements[i + 1];
1954 md5 = conflicts->elements[i + 2];
1955 q = conflicts->elements[i + 3];
1956 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1957 s = pool->solvables + p;
1960 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1961 s = pool->solvables + q;
1964 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1967 pool_freeidhashes(pool);