2 * Copyright (c) 2007-2009, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * The pool contains information about solvables
12 * stored optimized for memory consumption and fast retrieval.
24 #include "poolid_private.h"
30 #define SOLVABLE_BLOCK 255
32 #define KNOWNID_INITIALIZE
34 #undef KNOWNID_INITIALIZE
43 pool = (Pool *)sat_calloc(1, sizeof(*pool));
45 stringpool_init (&pool->ss, initpool_data);
47 /* alloc space for RelDep 0 */
48 pool->rels = sat_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
50 memset(pool->rels, 0, sizeof(Reldep));
52 /* alloc space for Solvable 0 and system solvable */
53 pool->solvables = sat_extend_resize(0, 2, sizeof(Solvable), SOLVABLE_BLOCK);
55 memset(pool->solvables, 0, 2 * sizeof(Solvable));
56 s = pool->solvables + SYSTEMSOLVABLE;
57 s->name = SYSTEM_SYSTEM;
58 s->arch = ARCH_NOARCH;
61 queue_init(&pool->vendormap);
63 pool->debugmask = SAT_DEBUG_RESULT; /* FIXME */
65 pool->obsoleteusescolors = 1;
71 /* free all the resources of our pool */
77 pool_freewhatprovides(pool);
78 pool_freeidhashes(pool);
79 repo_freeallrepos(pool, 1);
80 sat_free(pool->id2arch);
81 sat_free(pool->solvables);
82 stringpool_free(&pool->ss);
84 queue_free(&pool->vendormap);
85 for (i = 0; i < POOL_TMPSPACEBUF; i++)
86 sat_free(pool->tmpspacebuf[i]);
87 for (i = 0; i < pool->nlanguages; i++)
88 free((char *)pool->languages[i]);
89 sat_free(pool->languages);
90 sat_free(pool->languagecache);
94 #ifdef MULTI_SEMANTICS
96 pool_setdisttype(Pool *pool, int disttype)
98 pool->disttype = disttype;
103 pool_add_solvable(Pool *pool)
105 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
106 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
107 return pool->nsolvables++;
111 pool_add_solvable_block(Pool *pool, int count)
113 Id nsolvables = pool->nsolvables;
116 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
117 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
118 pool->nsolvables += count;
123 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
127 if (reuseids && start + count == pool->nsolvables)
129 /* might want to shrink solvable array */
130 pool->nsolvables = start;
133 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
138 pool_set_installed(Pool *pool, Repo *installed)
140 if (pool->installed == installed)
142 pool->installed = installed;
143 pool_freewhatprovides(pool);
147 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
152 oa = pool->whatprovides[*(Id *)ap];
153 ob = pool->whatprovides[*(Id *)bp];
155 return *(Id *)ap - *(Id *)bp;
160 da = pool->whatprovidesdata + oa;
161 db = pool->whatprovidesdata + ob;
163 if ((r = (*da++ - *db++)) != 0)
167 return *(Id *)ap - *(Id *)bp;
171 * pool_shrink_whatprovides - unify whatprovides data
173 * whatprovides_rel must be empty for this to work!
177 pool_shrink_whatprovides(Pool *pool)
181 Id lastid, *last, *dp, *lp;
185 if (pool->ss.nstrings < 3)
187 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
188 for (id = 0; id < pool->ss.nstrings; id++)
190 sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
193 for (i = 1; i < pool->ss.nstrings; i++)
196 o = pool->whatprovides[id];
197 if (o == 0 || o == 1)
199 dp = pool->whatprovidesdata + o;
213 pool->whatprovides[id] = -lastid;
217 last = pool->whatprovidesdata + o;
221 dp = pool->whatprovidesdata + 2;
222 for (id = 1; id < pool->ss.nstrings; id++)
224 o = pool->whatprovides[id];
225 if (o == 0 || o == 1)
232 pool->whatprovides[id] = pool->whatprovides[i];
235 lp = pool->whatprovidesdata + o;
238 pool->whatprovides[id] = dp - pool->whatprovidesdata;
239 while ((*dp++ = *lp++) != 0)
242 o = dp - pool->whatprovidesdata;
243 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
244 if (pool->whatprovidesdataoff == o)
246 r = pool->whatprovidesdataoff - o;
247 pool->whatprovidesdataoff = o;
248 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
249 if (r > pool->whatprovidesdataleft)
250 r = pool->whatprovidesdataleft;
251 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
256 * pool_createwhatprovides()
258 * create hashes over pool of solvables to ease provide lookups
262 pool_createwhatprovides(Pool *pool)
264 int i, num, np, extra;
269 Offset *whatprovides;
270 Id *whatprovidesdata, *d;
271 Repo *installed = pool->installed;
275 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
276 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
278 pool_freeidhashes(pool); /* XXX: should not be here! */
279 pool_freewhatprovides(pool);
280 num = pool->ss.nstrings;
281 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
282 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
284 /* count providers for each name */
285 for (i = pool->nsolvables - 1; i > 0; i--)
288 s = pool->solvables + i;
289 if (!s->provides || !s->repo || s->repo->disabled)
291 /* we always need the installed solvable in the whatprovides data,
292 otherwise obsoletes/conflicts on them won't work */
293 if (s->repo != installed && !pool_installable(pool, s))
295 pp = s->repo->idarraydata + s->provides;
296 while ((id = *pp++) != 0)
300 Reldep *rd = GETRELDEP(pool, id);
303 whatprovides[id]++; /* inc count of providers */
307 off = 2; /* first entry is undef, second is empty list */
308 np = 0; /* number of names provided */
309 for (i = 0, idp = whatprovides; i < num; i++, idp++)
312 if (!n) /* no providers */
314 off += n; /* make space for all providers */
315 *idp = off++; /* now idp points to terminating zero */
316 np++; /* inc # of provider 'slots' for stats */
319 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
321 /* reserve some space for relation data */
322 extra = 2 * pool->nrels;
326 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
328 /* alloc space for all providers + extra */
329 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
331 /* now fill data for all provides */
332 for (i = pool->nsolvables - 1; i > 0; i--)
335 s = pool->solvables + i;
336 if (!s->provides || !s->repo || s->repo->disabled)
338 if (s->repo != installed && !pool_installable(pool, s))
341 /* for all provides of this solvable */
342 pp = s->repo->idarraydata + s->provides;
343 while ((id = *pp++) != 0)
347 Reldep *rd = GETRELDEP(pool, id);
350 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
351 if (*d != i) /* don't add same solvable twice */
358 pool->whatprovidesdata = whatprovidesdata;
359 pool->whatprovidesdataoff = off;
360 pool->whatprovidesdataleft = extra;
361 pool_shrink_whatprovides(pool);
362 POOL_DEBUG(SAT_DEBUG_STATS, "whatprovides memory used: %d K id array, %d K data\n", (pool->ss.nstrings + pool->nrels + WHATPROVIDES_BLOCK) / (int)(1024/sizeof(Id)), (pool->whatprovidesdataoff + pool->whatprovidesdataleft) / (int)(1024/sizeof(Id)));
363 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
367 * free all of our whatprovides data
368 * be careful, everything internalized with pool_queuetowhatprovides is
372 pool_freewhatprovides(Pool *pool)
374 pool->whatprovides = sat_free(pool->whatprovides);
375 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
376 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
377 pool->whatprovidesdataoff = 0;
378 pool->whatprovidesdataleft = 0;
382 /******************************************************************************/
385 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
387 * on-demand filling of provider information
388 * move queue data into whatprovidesdata
390 * returns: Offset into whatprovides
394 pool_queuetowhatprovides(Pool *pool, Queue *q)
397 int count = q->count;
399 if (count == 0) /* queue empty -> 1 */
402 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
403 if (pool->whatprovidesdataleft < count + 1)
405 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
406 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
407 pool->whatprovidesdataleft = count + 4096;
410 /* copy queue to next free slot */
411 off = pool->whatprovidesdataoff;
412 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
414 /* adapt count and ID_NULL-terminate */
415 pool->whatprovidesdataoff += count;
416 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
417 pool->whatprovidesdataleft -= count + 1;
423 /*************************************************************************/
425 #if defined(MULTI_SEMANTICS)
426 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
427 #elif defined(DEBIAN_SEMANTICS)
428 # define EVRCMP_DEPCMP EVRCMP_COMPARE
430 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
433 /* check if a package's nevr matches a dependency */
436 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
438 Reldep *rd = GETRELDEP(pool, d);
441 int flags = rd->flags;
450 return pool_match_nevr(pool, s, name);
452 if (pool_match_nevr(pool, s, name))
454 return pool_match_nevr(pool, s, evr);
457 if (!pool_match_nevr(pool, s, name))
459 return pool_match_nevr(pool, s, evr);
464 if (!pool_match_nevr(pool, s, name))
467 return flags & 2 ? 1 : 0;
472 if (flags != 2 && flags != 5)
474 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
479 /* match (flags, evr) against provider (pflags, pevr) */
481 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
483 if (!pflags || !flags || pflags >= 8 || flags >= 8)
485 if (flags == 7 || pflags == 7)
486 return 1; /* rel provides every version */
487 if ((pflags & flags & 5) != 0)
488 return 1; /* both rels show in the same direction */
491 if ((pflags & flags & 2) != 0)
492 return 1; /* both have '=', match */
496 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
497 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
503 /* match two dependencies (d1 = provider) */
506 pool_match_dep(Pool *pool, Id d1, Id d2)
516 rd2 = GETRELDEP(pool, d2);
517 return pool_match_dep(pool, d1, rd2->name);
519 rd1 = GETRELDEP(pool, d1);
522 return pool_match_dep(pool, rd1->name, d2);
524 rd2 = GETRELDEP(pool, d2);
525 /* first match name */
526 if (!pool_match_dep(pool, rd1->name, rd2->name))
528 /* name matches, check flags and evr */
529 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
535 * add packages fulfilling the relation to whatprovides array
536 * no exact providers, do range match
541 pool_addrelproviders(Pool *pool, Id d)
543 Reldep *rd = GETRELDEP(pool, d);
549 int flags = rd->flags;
551 Id p, wp, *pp, *pp2, *pp3;
554 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
559 pp = pool_whatprovides_ptr(pool, name);
560 pp2 = pool_whatprovides_ptr(pool, evr);
561 while ((p = *pp++) != 0)
563 for (pp3 = pp2; *pp3;)
566 queue_push(&plist, p);
572 pp = pool_whatprovides_ptr(pool, name);
573 while ((p = *pp++) != 0)
574 queue_push(&plist, p);
575 pp = pool_whatprovides_ptr(pool, evr);
576 while ((p = *pp++) != 0)
577 queue_pushunique(&plist, p);
580 if (name == NAMESPACE_OTHERPROVIDERS)
582 wp = pool_whatprovides(pool, evr);
583 pool->whatprovides_rel[d] = wp;
586 if (pool->nscallback)
588 /* ask callback which packages provide the dependency
590 * 1: the system (aka SYSTEMSOLVABLE)
591 * >1: a set of packages, stored as offset on whatprovidesdata
593 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
597 pool->whatprovides_rel[d] = p;
601 queue_push(&plist, SYSTEMSOLVABLE);
605 /* small hack: make it possible to match <pkg>.src
606 * we have to iterate over the solvables as src packages do not
607 * provide anything, thus they are not indexed in our
608 * whatprovides hash */
612 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
614 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
616 if (pool_match_nevr(pool, s, name))
617 queue_push(&plist, p);
621 wp = pool_whatprovides(pool, name);
622 pp = pool->whatprovidesdata + wp;
623 while ((p = *pp++) != 0)
625 Solvable *s = pool->solvables + p;
627 queue_push(&plist, p);
633 /* all solvables match, no need to create a new list */
634 pool->whatprovides_rel[d] = wp;
638 case REL_FILECONFLICT:
639 pp = pool_whatprovides_ptr(pool, name);
640 while ((p = *pp++) != 0)
642 Id origd = MAKERELDEP(d);
643 Solvable *s = pool->solvables + p;
646 pidp = s->repo->idarraydata + s->provides;
647 while ((pid = *pidp++) != 0)
651 queue_push(&plist, p);
658 /* convert to whatprovides id */
660 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
662 if (flags && flags < 8)
664 pp = pool_whatprovides_ptr(pool, name);
665 while (ISRELDEP(name))
667 rd = GETRELDEP(pool, name);
670 while ((p = *pp++) != 0)
672 Solvable *s = pool->solvables + p;
674 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
678 /* no provides - check nevr */
679 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
680 queue_push(&plist, p);
683 /* solvable p provides name in some rels */
684 pidp = s->repo->idarraydata + s->provides;
685 while ((pid = *pidp++) != 0)
689 #if defined(MULTI_SEMANTICS)
690 if (pool->disttype == DISTTYPE_DEB)
694 #elif defined(DEBIAN_SEMANTICS)
695 continue; /* unversioned provides can
696 * never match versioned deps */
698 break; /* yes, provides all versions */
702 continue; /* wrong provides name */
703 prd = GETRELDEP(pool, pid);
704 if (prd->name != name)
705 continue; /* wrong provides name */
706 /* right package, both deps are rels. check flags/evr */
707 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
711 continue; /* none of the providers matched */
712 queue_push(&plist, p);
714 /* make our system solvable provide all unknown rpmlib() stuff */
715 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
716 queue_push(&plist, SYSTEMSOLVABLE);
718 /* add providers to whatprovides */
720 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
722 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
725 return pool->whatprovides_rel[d];
728 /*************************************************************************/
731 pool_debug(Pool *pool, int type, const char *format, ...)
736 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
738 if ((pool->debugmask & type) == 0)
741 va_start(args, format);
742 if (!pool->debugcallback)
744 if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
745 vprintf(format, args);
747 vfprintf(stderr, format, args);
750 vsnprintf(buf, sizeof(buf), format, args);
751 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
755 pool_setdebuglevel(Pool *pool, int level)
757 int mask = SAT_DEBUG_RESULT;
759 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
761 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
763 mask |= SAT_DEBUG_PROPAGATE;
765 mask |= SAT_DEBUG_RULE_CREATION;
767 mask |= SAT_DEBUG_SCHUBI;
768 mask |= pool->debugmask & SAT_DEBUG_TO_STDERR; /* keep bit */
769 pool->debugmask = mask;
772 /*************************************************************************/
782 #define SEARCHFILES_BLOCK 127
785 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
789 struct searchfiles *csf;
791 while ((dep = *ida++) != 0)
794 while (ISRELDEP(dep))
797 sid = pool->ss.nstrings + GETRELID(dep);
798 if (MAPTST(&csf->seen, sid))
803 MAPSET(&csf->seen, sid);
804 rd = GETRELDEP(pool, dep);
807 else if (rd->flags == REL_NAMESPACE)
809 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
812 if (!csf || MAPTST(&csf->seen, sid))
817 MAPSET(&csf->seen, sid);
821 else if (rd->flags == REL_FILECONFLICT)
831 pool_addfileprovides_dep(pool, ids, csf, isf);
837 if (MAPTST(&csf->seen, dep))
839 MAPSET(&csf->seen, dep);
840 s = id2str(pool, dep);
843 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
844 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
845 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
846 csf->ids[csf->nfiles] = dep;
847 sr = strrchr(s, '/');
848 csf->names[csf->nfiles] = strdup(sr + 1);
849 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
851 strncpy(csf->dirs[csf->nfiles], s, sr - s);
852 csf->dirs[csf->nfiles][sr - s] = 0;
857 struct addfileprovides_cbdata {
871 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
873 struct addfileprovides_cbdata *cbd = cbdata;
876 if (!cbd->useddirs.size)
878 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
879 for (i = 0; i < cbd->nfiles; i++)
882 if (MAPTST(&cbd->providedids, cbd->ids[i]))
887 did = repodata_str2dir(data, cbd->dirs[i], 0);
890 MAPSET(&cbd->useddirs, did);
893 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
895 for (i = 0; i < cbd->nfiles; i++)
897 if (cbd->dids[i] != value->id)
899 if (!strcmp(cbd->names[i], value->str))
902 if (i == cbd->nfiles)
904 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
909 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
915 int i, j, repoid, repodataid;
916 int provstart, provend;
918 int ndone, incomplete;
923 cbd->nfiles = sf->nfiles;
925 cbd->dirs = sf->dirs;
926 cbd->names = sf->names;
927 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
928 map_init(&cbd->providedids, pool->ss.nstrings);
931 repo = repoonly ? repoonly : pool->repos[0];
932 map_init(&donemap, pool->nsolvables);
933 queue_init(&fileprovidesq);
934 provstart = provend = 0;
939 if (repoonly || ++repoid == pool->nrepos)
941 repo = pool->repos[repoid];
945 for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
947 if (ndone >= repo->nsolvables)
950 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
952 map_empty(&cbd->providedids);
953 for (i = 0; i < fileprovidesq.count; i++)
954 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
955 provstart = data->start;
957 for (i = 0; i < cbd->nfiles; i++)
958 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
960 if (i == cbd->nfiles)
962 /* great! no need to search files */
963 for (p = data->start; p < data->end; p++)
964 if (pool->solvables[p].repo == repo)
966 if (MAPTST(&donemap, p))
975 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
978 if (data->start < provstart || data->end > provend)
980 map_empty(&cbd->providedids);
981 provstart = provend = 0;
984 /* check if the data is incomplete */
986 if (data->state == REPODATA_AVAILABLE)
988 for (j = 1; j < data->nkeys; j++)
989 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
994 for (i = 0; i < cbd->nfiles; i++)
995 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
996 printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
998 for (i = 0; i < cbd->nfiles; i++)
999 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
1001 if (i < cbd->nfiles)
1007 map_init(&cbd->useddirs, 0);
1008 for (p = data->start; p < data->end; p++)
1009 if (pool->solvables[p].repo == repo)
1011 if (MAPTST(&donemap, p))
1013 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1016 MAPSET(&donemap, p);
1020 map_free(&cbd->useddirs);
1023 if (repoonly || ++repoid == pool->nrepos)
1025 repo = pool->repos[repoid];
1028 queue_free(&fileprovidesq);
1029 map_free(&cbd->providedids);
1033 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1037 struct searchfiles sf, isf, *isfp;
1038 struct addfileprovides_cbdata cbd;
1042 now = sat_timems(0);
1043 memset(&sf, 0, sizeof(sf));
1044 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1045 memset(&isf, 0, sizeof(isf));
1046 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1048 isfp = installed ? &isf : 0;
1049 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1055 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1057 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1059 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1061 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1063 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1065 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1067 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1070 map_free(&isf.seen);
1071 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1078 for (i = 0; i < sf.nfiles; i++)
1079 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
1081 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1084 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1085 sf.ids[sf.nfiles] = 0;
1090 for (i = 0; i < sf.nfiles; i++)
1092 sat_free(sf.dirs[i]);
1093 sat_free(sf.names[i]);
1101 for (i = 0; i < isf.nfiles; i++)
1102 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
1105 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1107 for (i = 0; i < isf.nfiles; i++)
1109 sat_free(isf.dirs[i]);
1110 sat_free(isf.names[i]);
1113 sat_free(isf.names);
1116 pool_freewhatprovides(pool); /* as we have added provides */
1117 POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
1121 pool_addfileprovides(Pool *pool)
1123 pool_addfileprovides_ids(pool, pool->installed, 0);
1127 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)
1131 if (pool->solvables[p].repo)
1132 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1135 /* FIXME: obey callback return value! */
1136 for (p = 1; p < pool->nsolvables; p++)
1137 if (pool->solvables[p].repo)
1138 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1142 pool_clear_pos(Pool *pool)
1144 memset(&pool->pos, 0, sizeof(pool->pos));
1149 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1153 pool->languagecache = sat_free(pool->languagecache);
1154 pool->languagecacheother = 0;
1155 if (pool->nlanguages)
1157 for (i = 0; i < pool->nlanguages; i++)
1158 free((char *)pool->languages[i]);
1159 free(pool->languages);
1161 pool->nlanguages = nlanguages;
1164 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1165 for (i = 0; i < pool->nlanguages; i++)
1166 pool->languages[i] = strdup(languages[i]);
1170 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1178 n = id2str(pool, id);
1179 l = strlen(n) + strlen(lang) + 2;
1180 if (l > sizeof(buf))
1181 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1184 sprintf(p, "%s:%s", n, lang);
1185 id = str2id(pool, p, create);
1192 pool_alloctmpspace(Pool *pool, int len)
1194 int n = pool->tmpspacen;
1197 if (len > pool->tmpspacelen[n])
1199 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1200 pool->tmpspacelen[n] = len + 32;
1202 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1203 return pool->tmpspacebuf[n];
1207 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1211 l1 = str1 ? strlen(str1) : 0;
1212 l2 = str2 ? strlen(str2) : 0;
1213 l3 = str3 ? strlen(str3) : 0;
1214 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1235 /*******************************************************************/
1247 struct mptree *mptree;
1258 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1260 struct ducbdata *cbd = cbdata;
1263 if (data != cbd->olddata)
1265 Id dn, mp, comp, *dirmap, *dirs;
1267 const char *compstr;
1268 struct mptree *mptree;
1270 /* create map from dir to mptree */
1271 cbd->dirmap = sat_free(cbd->dirmap);
1273 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1274 mptree = cbd->mptree;
1276 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1290 if (!mptree[mp].child)
1295 if (data->localpool)
1296 compstr = stringpool_id2str(&data->spool, comp);
1298 compstr = id2str(data->repo->pool, comp);
1299 compl = strlen(compstr);
1300 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1301 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1303 dirmap[dn] = i ? i : -mp;
1305 /* change dirmap to point to mountpoint instead of mptree */
1306 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1309 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1311 cbd->dirmap = dirmap;
1312 cbd->nmap = data->dirpool.ndirs;
1313 cbd->olddata = data;
1316 if (value->id < 0 || value->id >= cbd->nmap)
1318 mp = cbd->dirmap[value->id];
1321 if (cbd->addsub > 0)
1323 cbd->mps[mp].kbytes += value->num;
1324 cbd->mps[mp].files += value->num2;
1328 cbd->mps[mp].kbytes -= value->num;
1329 cbd->mps[mp].files -= value->num2;
1335 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1338 if (mptree[pos].mountpoint == -1)
1339 mptree[pos].mountpoint = mountpoint;
1341 mountpoint = mptree[pos].mountpoint;
1342 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1343 propagate_mountpoints(mptree, i, mountpoint);
1346 #define MPTREE_BLOCK 15
1349 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1352 const char *path, *compstr;
1353 struct mptree *mptree;
1357 struct ducbdata cbd;
1361 Repo *oldinstalled = pool->installed;
1363 memset(&ignoredu, 0, sizeof(ignoredu));
1370 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1373 mptree[0].sibling = 0;
1374 mptree[0].child = 0;
1376 mptree[0].compl = 0;
1377 mptree[0].mountpoint = -1;
1380 /* create component tree */
1381 for (mp = 0; mp < nmps; mp++)
1386 path = mps[mp].path;
1391 if ((p = strchr(path, '/')) == 0)
1394 compl = strlen(compstr);
1405 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1406 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1410 /* create new node */
1411 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1413 mptree[i].sibling = mptree[pos].child;
1414 mptree[i].child = 0;
1415 mptree[i].comp = compstr;
1416 mptree[i].compl = compl;
1417 mptree[i].mountpoint = -1;
1418 mptree[pos].child = i;
1422 mptree[pos].mountpoint = mp;
1425 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1428 for (i = 0; i < nmptree; i++)
1430 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1431 printf("#%d child: %d\n", i, mptree[i].child);
1432 printf("#%d comp: %s\n", i, mptree[i].comp);
1433 printf("#%d compl: %d\n", i, mptree[i].compl);
1434 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1438 cbd.mptree = mptree;
1440 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1442 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1444 if (!MAPTST(installedmap, sp))
1447 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1448 if (!cbd.hasdu && oldinstalled)
1451 /* no du data available, ignore data of all installed solvables we obsolete */
1453 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1456 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1457 while ((obs = *obsp++) != 0)
1458 FOR_PROVIDES(op, opp, obs)
1459 if (op >= oldinstalled->start && op < oldinstalled->end)
1460 MAPSET(&ignoredu, op - oldinstalled->start);
1462 FOR_PROVIDES(op, opp, s->name)
1463 if (pool->solvables[op].name == s->name)
1464 if (op >= oldinstalled->start && op < oldinstalled->end)
1465 MAPSET(&ignoredu, op - oldinstalled->start);
1471 /* assumes we allways have du data for installed solvables */
1472 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1474 if (MAPTST(installedmap, sp))
1476 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1478 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1482 map_free(&ignoredu);
1483 sat_free(cbd.dirmap);
1488 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1493 Repo *oldinstalled = pool->installed;
1495 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1497 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1499 if (!MAPTST(installedmap, sp))
1501 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1505 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1507 if (MAPTST(installedmap, sp))
1509 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1517 * 2: conflicts with installed
1518 * 8: interesting (only true if installed)
1522 static inline Id dep2name(Pool *pool, Id dep)
1524 while (ISRELDEP(dep))
1526 Reldep *rd = rd = GETRELDEP(pool, dep);
1532 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1535 Solvable *sn = pool->solvables + n;
1537 FOR_PROVIDES(p, pp, sn->name)
1539 Solvable *s = pool->solvables + p;
1540 if (s->name != sn->name || s->arch != sn->arch)
1542 if ((map[p] & 9) != 9)
1544 if (pool_match_nevr(pool, pool->solvables + p, con))
1546 return 1; /* found installed package that doesn't conflict */
1551 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1555 FOR_PROVIDES(p, pp, dep)
1557 if (p == SYSTEMSOLVABLE)
1558 return 1; /* always boring, as never constraining */
1559 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1561 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1562 if (providedbyinstalled_multiversion(pool, map, p, dep))
1564 if ((map[p] & 9) == 9)
1572 * pool_trivial_installable - calculate if a set of solvables is
1573 * trivial installable without any other installs/deinstalls of
1574 * packages not belonging to the set.
1576 * the state is returned in the result queue:
1577 * 1: solvable is installable without any other package changes
1578 * 0: solvable is not installable
1579 * -1: solvable is installable, but doesn't constrain any installed packages
1583 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1586 Id p, *dp, con, *conp, req, *reqp;
1590 map = sat_calloc(pool->nsolvables, 1);
1591 for (p = 1; p < pool->nsolvables; p++)
1593 if (!MAPTST(installedmap, p))
1596 s = pool->solvables + p;
1599 conp = s->repo->idarraydata + s->conflicts;
1600 while ((con = *conp++) != 0)
1602 dp = pool_whatprovides_ptr(pool, con);
1604 map[p] |= 2; /* XXX: self conflict ? */
1607 for (i = 0; i < pkgs->count; i++)
1608 map[pkgs->elements[i]] = 16;
1610 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1612 if (i == pkgs->count)
1614 p = pkgs->elements[i];
1615 if ((map[p] & 16) == 0)
1617 if ((map[p] & 2) != 0)
1622 s = pool->solvables + p;
1626 reqp = s->repo->idarraydata + s->requires;
1627 while ((req = *reqp++) != 0)
1629 if (req == SOLVABLE_PREREQMARKER)
1631 r = providedbyinstalled(pool, map, req, 0, 0);
1634 /* decided and miss */
1638 m |= r; /* 1 | 9 | 16 | 17 */
1647 int ispatch = 0; /* see solver.c patch handling */
1649 if (!strncmp("patch:", id2str(pool, s->name), 6))
1651 conp = s->repo->idarraydata + s->conflicts;
1652 while ((con = *conp++) != 0)
1654 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1659 if ((m == 1 || m == 17) && ISRELDEP(con))
1661 con = dep2name(pool, con);
1662 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1667 continue; /* found a conflict */
1670 if (s->repo && s->repo != oldinstalled)
1672 Id p2, obs, *obsp, *pp;
1676 obsp = s->repo->idarraydata + s->obsoletes;
1677 while ((obs = *obsp++) != 0)
1679 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1688 FOR_PROVIDES(p2, pp, s->name)
1690 s2 = pool->solvables + p2;
1691 if (s2->name == s->name && (map[p2] & 1) != 0)
1708 queue_init_clone(res, pkgs);
1709 for (i = 0; i < pkgs->count; i++)
1711 m = map[pkgs->elements[i]];
1718 res->elements[i] = r;
1724 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1726 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1730 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1732 if (entry == SOLVID_POS && pool->pos.repo)
1733 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1736 return solvable_lookup_str(pool->solvables + entry, keyname);
1740 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1742 if (entry == SOLVID_POS && pool->pos.repo)
1744 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1745 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1746 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1750 return solvable_lookup_id(pool->solvables + entry, keyname);
1754 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1756 if (entry == SOLVID_POS && pool->pos.repo)
1759 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1765 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1769 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1771 if (entry == SOLVID_POS && pool->pos.repo)
1772 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1775 return solvable_lookup_void(pool->solvables + entry, keyname);
1778 const unsigned char *
1779 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1781 if (entry == SOLVID_POS && pool->pos.repo)
1782 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1785 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1789 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1791 if (entry == SOLVID_POS && pool->pos.repo)
1793 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1794 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1798 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1802 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1804 int hadhashes = pool->relhashtbl ? 1 : 0;
1810 if (!conflicts->count)
1812 pool_freewhatprovides(pool);
1813 for (i = 0; i < conflicts->count; i += 5)
1815 fn = conflicts->elements[i];
1816 p = conflicts->elements[i + 1];
1817 md5 = conflicts->elements[i + 2];
1818 q = conflicts->elements[i + 3];
1819 id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1820 s = pool->solvables + p;
1823 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1824 s = pool->solvables + q;
1827 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1830 pool_freeidhashes(pool);