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 */
68 /* free all the resources of our pool */
74 pool_freewhatprovides(pool);
75 pool_freeidhashes(pool);
76 repo_freeallrepos(pool, 1);
77 sat_free(pool->id2arch);
78 sat_free(pool->solvables);
79 stringpool_free(&pool->ss);
81 queue_free(&pool->vendormap);
82 for (i = 0; i < POOL_TMPSPACEBUF; i++)
83 sat_free(pool->tmpspacebuf[i]);
84 for (i = 0; i < pool->nlanguages; i++)
85 free((char *)pool->languages[i]);
86 sat_free(pool->languages);
87 sat_free(pool->languagecache);
91 #ifdef MULTI_SEMANTICS
93 pool_setdisttype(Pool *pool, int disttype)
95 pool->disttype = disttype;
100 pool_add_solvable(Pool *pool)
102 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
103 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
104 return pool->nsolvables++;
108 pool_add_solvable_block(Pool *pool, int count)
110 Id nsolvables = pool->nsolvables;
113 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
114 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
115 pool->nsolvables += count;
120 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
124 if (reuseids && start + count == pool->nsolvables)
126 /* might want to shrink solvable array */
127 pool->nsolvables = start;
130 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
135 pool_set_installed(Pool *pool, Repo *installed)
137 if (pool->installed == installed)
139 pool->installed = installed;
140 pool_freewhatprovides(pool);
144 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
149 oa = pool->whatprovides[*(Id *)ap];
150 ob = pool->whatprovides[*(Id *)bp];
152 return *(Id *)ap - *(Id *)bp;
157 da = pool->whatprovidesdata + oa;
158 db = pool->whatprovidesdata + ob;
160 if ((r = (*da++ - *db++)) != 0)
164 return *(Id *)ap - *(Id *)bp;
168 * pool_shrink_whatprovides - unify whatprovides data
170 * whatprovides_rel must be empty for this to work!
174 pool_shrink_whatprovides(Pool *pool)
178 Id lastid, *last, *dp, *lp;
182 if (pool->ss.nstrings < 3)
184 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
185 for (id = 0; id < pool->ss.nstrings; id++)
187 sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
190 for (i = 1; i < pool->ss.nstrings; i++)
193 o = pool->whatprovides[id];
194 if (o == 0 || o == 1)
196 dp = pool->whatprovidesdata + o;
210 pool->whatprovides[id] = -lastid;
214 last = pool->whatprovidesdata + o;
218 dp = pool->whatprovidesdata + 2;
219 for (id = 1; id < pool->ss.nstrings; id++)
221 o = pool->whatprovides[id];
222 if (o == 0 || o == 1)
229 pool->whatprovides[id] = pool->whatprovides[i];
232 lp = pool->whatprovidesdata + o;
235 pool->whatprovides[id] = dp - pool->whatprovidesdata;
236 while ((*dp++ = *lp++) != 0)
239 o = dp - pool->whatprovidesdata;
240 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
241 if (pool->whatprovidesdataoff == o)
243 r = pool->whatprovidesdataoff - o;
244 pool->whatprovidesdataoff = o;
245 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
246 if (r > pool->whatprovidesdataleft)
247 r = pool->whatprovidesdataleft;
248 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
253 * pool_createwhatprovides()
255 * create hashes over pool of solvables to ease provide lookups
259 pool_createwhatprovides(Pool *pool)
261 int i, num, np, extra;
266 Offset *whatprovides;
267 Id *whatprovidesdata, *d;
268 Repo *installed = pool->installed;
272 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
273 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
275 pool_freeidhashes(pool); /* XXX: should not be here! */
276 pool_freewhatprovides(pool);
277 num = pool->ss.nstrings;
278 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
279 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
281 /* count providers for each name */
282 for (i = pool->nsolvables - 1; i > 0; i--)
285 s = pool->solvables + i;
286 if (!s->provides || !s->repo || s->repo->disabled)
288 /* we always need the installed solvable in the whatprovides data,
289 otherwise obsoletes/conflicts on them won't work */
290 if (s->repo != installed && !pool_installable(pool, s))
292 pp = s->repo->idarraydata + s->provides;
293 while ((id = *pp++) != 0)
297 Reldep *rd = GETRELDEP(pool, id);
300 whatprovides[id]++; /* inc count of providers */
304 off = 2; /* first entry is undef, second is empty list */
305 np = 0; /* number of names provided */
306 for (i = 0, idp = whatprovides; i < num; i++, idp++)
309 if (!n) /* no providers */
311 off += n; /* make space for all providers */
312 *idp = off++; /* now idp points to terminating zero */
313 np++; /* inc # of provider 'slots' for stats */
316 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
318 /* reserve some space for relation data */
319 extra = 2 * pool->nrels;
323 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
325 /* alloc space for all providers + extra */
326 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
328 /* now fill data for all provides */
329 for (i = pool->nsolvables - 1; i > 0; i--)
332 s = pool->solvables + i;
333 if (!s->provides || !s->repo || s->repo->disabled)
335 if (s->repo != installed && !pool_installable(pool, s))
338 /* for all provides of this solvable */
339 pp = s->repo->idarraydata + s->provides;
340 while ((id = *pp++) != 0)
344 Reldep *rd = GETRELDEP(pool, id);
347 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
348 if (*d != i) /* don't add same solvable twice */
355 pool->whatprovidesdata = whatprovidesdata;
356 pool->whatprovidesdataoff = off;
357 pool->whatprovidesdataleft = extra;
358 pool_shrink_whatprovides(pool);
359 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)));
360 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
364 * free all of our whatprovides data
365 * be careful, everything internalized with pool_queuetowhatprovides is
369 pool_freewhatprovides(Pool *pool)
371 pool->whatprovides = sat_free(pool->whatprovides);
372 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
373 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
374 pool->whatprovidesdataoff = 0;
375 pool->whatprovidesdataleft = 0;
379 /******************************************************************************/
382 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
384 * on-demand filling of provider information
385 * move queue data into whatprovidesdata
387 * returns: Offset into whatprovides
391 pool_queuetowhatprovides(Pool *pool, Queue *q)
394 int count = q->count;
396 if (count == 0) /* queue empty -> 1 */
399 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
400 if (pool->whatprovidesdataleft < count + 1)
402 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
403 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
404 pool->whatprovidesdataleft = count + 4096;
407 /* copy queue to next free slot */
408 off = pool->whatprovidesdataoff;
409 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
411 /* adapt count and ID_NULL-terminate */
412 pool->whatprovidesdataoff += count;
413 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
414 pool->whatprovidesdataleft -= count + 1;
420 /*************************************************************************/
422 #if defined(MULTI_SEMANTICS)
423 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
424 #elif defined(DEBIAN_SEMANTICS)
425 # define EVRCMP_DEPCMP EVRCMP_COMPARE
427 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
430 /* check if a package's nevr matches a dependency */
433 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
435 Reldep *rd = GETRELDEP(pool, d);
438 int flags = rd->flags;
447 return pool_match_nevr(pool, s, name);
449 if (pool_match_nevr(pool, s, name))
451 return pool_match_nevr(pool, s, evr);
454 if (!pool_match_nevr(pool, s, name))
456 return pool_match_nevr(pool, s, evr);
461 if (!pool_match_nevr(pool, s, name))
464 return flags & 2 ? 1 : 0;
469 if (flags != 2 && flags != 5)
471 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
476 /* match two dependencies */
479 pool_match_dep(Pool *pool, Id d1, Id d2)
490 rd2 = GETRELDEP(pool, d2);
491 return pool_match_dep(pool, d1, rd2->name);
493 rd1 = GETRELDEP(pool, d1);
496 return pool_match_dep(pool, rd1->name, d2);
498 rd2 = GETRELDEP(pool, d2);
499 if (!pool_match_dep(pool, rd1->name, rd2->name))
503 if (!pflags || !flags || pflags >= 8 || flags >= 8)
505 if (flags == 7 || pflags == 7)
507 if ((pflags & flags & 5) != 0)
509 if (rd1->evr == rd2->evr)
511 if ((pflags & flags & 2) != 0)
516 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
517 if ((f & (1 << (1 + evrcmp(pool, rd1->evr, rd2->evr, EVRCMP_DEPCMP)))) != 0)
526 * add packages fulfilling the relation to whatprovides array
527 * no exact providers, do range match
532 pool_addrelproviders(Pool *pool, Id d)
534 Reldep *rd = GETRELDEP(pool, d);
540 int flags = rd->flags;
542 Id p, wp, *pp, *pp2, *pp3;
545 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
550 pp = pool_whatprovides_ptr(pool, name);
551 pp2 = pool_whatprovides_ptr(pool, evr);
552 while ((p = *pp++) != 0)
554 for (pp3 = pp2; *pp3;)
557 queue_push(&plist, p);
563 pp = pool_whatprovides_ptr(pool, name);
564 while ((p = *pp++) != 0)
565 queue_push(&plist, p);
566 pp = pool_whatprovides_ptr(pool, evr);
567 while ((p = *pp++) != 0)
568 queue_pushunique(&plist, p);
571 if (name == NAMESPACE_OTHERPROVIDERS)
573 wp = pool_whatprovides(pool, evr);
574 pool->whatprovides_rel[d] = wp;
577 if (pool->nscallback)
579 /* ask callback which packages provide the dependency
581 * 1: the system (aka SYSTEMSOLVABLE)
582 * >1: a set of packages, stored as offset on whatprovidesdata
584 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
588 pool->whatprovides_rel[d] = p;
592 queue_push(&plist, SYSTEMSOLVABLE);
596 /* small hack: make it possible to match <pkg>.src
597 * we have to iterate over the solvables as src packages do not
598 * provide anything, thus they are not indexed in our
599 * whatprovides hash */
603 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
605 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
607 if (pool_match_nevr(pool, s, name))
608 queue_push(&plist, p);
612 wp = pool_whatprovides(pool, name);
613 pp = pool->whatprovidesdata + wp;
614 while ((p = *pp++) != 0)
616 Solvable *s = pool->solvables + p;
618 queue_push(&plist, p);
624 /* all solvables match, no need to create a new list */
625 pool->whatprovides_rel[d] = wp;
629 case REL_FILECONFLICT:
630 pp = pool_whatprovides_ptr(pool, name);
631 while ((p = *pp++) != 0)
633 Id origd = MAKERELDEP(d);
634 Solvable *s = pool->solvables + p;
637 pidp = s->repo->idarraydata + s->provides;
638 while ((pid = *pidp++) != 0)
642 queue_push(&plist, p);
649 /* convert to whatprovides id */
651 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
653 if (flags && flags < 8)
655 pp = pool_whatprovides_ptr(pool, name);
656 while (ISRELDEP(name))
658 rd = GETRELDEP(pool, name);
661 while ((p = *pp++) != 0)
663 Solvable *s = pool->solvables + p;
665 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
669 /* no provides - check nevr */
670 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
671 queue_push(&plist, p);
674 /* solvable p provides name in some rels */
675 pidp = s->repo->idarraydata + s->provides;
676 while ((pid = *pidp++) != 0)
683 #if defined(MULTI_SEMANTICS)
684 if (pool->disttype == DISTTYPE_DEB)
688 #elif defined(DEBIAN_SEMANTICS)
689 continue; /* unversioned provides can
690 * never match versioned deps */
692 break; /* yes, provides all versions */
696 continue; /* wrong provides name */
697 prd = GETRELDEP(pool, pid);
698 if (prd->name != name)
699 continue; /* wrong provides name */
700 /* right package, both deps are rels */
704 if (flags == 7 || pflags == 7)
705 break; /* included */
706 if ((pflags & flags & 5) != 0)
707 break; /* same direction, match */
711 if ((pflags & flags & 2) != 0)
712 break; /* both have =, match */
716 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
717 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
722 continue; /* no rel match */
723 queue_push(&plist, p);
725 /* make our system solvable provide all unknown rpmlib() stuff */
726 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
727 queue_push(&plist, SYSTEMSOLVABLE);
729 /* add providers to whatprovides */
731 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
733 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
736 return pool->whatprovides_rel[d];
739 /*************************************************************************/
742 pool_debug(Pool *pool, int type, const char *format, ...)
747 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
749 if ((pool->debugmask & type) == 0)
752 va_start(args, format);
753 if (!pool->debugcallback)
755 if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
756 vprintf(format, args);
758 vfprintf(stderr, format, args);
761 vsnprintf(buf, sizeof(buf), format, args);
762 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
766 pool_setdebuglevel(Pool *pool, int level)
768 int mask = SAT_DEBUG_RESULT;
770 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
772 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
774 mask |= SAT_DEBUG_PROPAGATE;
776 mask |= SAT_DEBUG_RULE_CREATION;
778 mask |= SAT_DEBUG_SCHUBI;
779 mask |= pool->debugmask & SAT_DEBUG_TO_STDERR; /* keep bit */
780 pool->debugmask = mask;
783 /*************************************************************************/
793 #define SEARCHFILES_BLOCK 127
796 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
800 struct searchfiles *csf;
802 while ((dep = *ida++) != 0)
805 while (ISRELDEP(dep))
808 sid = pool->ss.nstrings + GETRELID(dep);
809 if (MAPTST(&csf->seen, sid))
814 MAPSET(&csf->seen, sid);
815 rd = GETRELDEP(pool, dep);
818 else if (rd->flags == REL_NAMESPACE)
820 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
823 if (!csf || MAPTST(&csf->seen, sid))
828 MAPSET(&csf->seen, sid);
832 else if (rd->flags == REL_FILECONFLICT)
842 pool_addfileprovides_dep(pool, ids, csf, isf);
848 if (MAPTST(&csf->seen, dep))
850 MAPSET(&csf->seen, dep);
851 s = id2str(pool, dep);
854 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
855 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
856 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
857 csf->ids[csf->nfiles] = dep;
858 sr = strrchr(s, '/');
859 csf->names[csf->nfiles] = strdup(sr + 1);
860 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
862 strncpy(csf->dirs[csf->nfiles], s, sr - s);
863 csf->dirs[csf->nfiles][sr - s] = 0;
868 struct addfileprovides_cbdata {
882 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
884 struct addfileprovides_cbdata *cbd = cbdata;
887 if (!cbd->useddirs.size)
889 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
890 for (i = 0; i < cbd->nfiles; i++)
893 if (MAPTST(&cbd->providedids, cbd->ids[i]))
898 did = repodata_str2dir(data, cbd->dirs[i], 0);
901 MAPSET(&cbd->useddirs, did);
904 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
906 for (i = 0; i < cbd->nfiles; i++)
908 if (cbd->dids[i] != value->id)
910 if (!strcmp(cbd->names[i], value->str))
913 if (i == cbd->nfiles)
915 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
920 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
926 int i, j, repoid, repodataid;
927 int provstart, provend;
929 int ndone, incomplete;
934 cbd->nfiles = sf->nfiles;
936 cbd->dirs = sf->dirs;
937 cbd->names = sf->names;
938 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
939 map_init(&cbd->providedids, pool->ss.nstrings);
942 repo = repoonly ? repoonly : pool->repos[0];
943 map_init(&donemap, pool->nsolvables);
944 queue_init(&fileprovidesq);
945 provstart = provend = 0;
950 if (repoonly || ++repoid == pool->nrepos)
952 repo = pool->repos[repoid];
956 for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
958 if (ndone >= repo->nsolvables)
961 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
963 map_empty(&cbd->providedids);
964 for (i = 0; i < fileprovidesq.count; i++)
965 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
966 provstart = data->start;
968 for (i = 0; i < cbd->nfiles; i++)
969 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
971 if (i == cbd->nfiles)
973 /* great! no need to search files */
974 for (p = data->start; p < data->end; p++)
975 if (pool->solvables[p].repo == repo)
977 if (MAPTST(&donemap, p))
986 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
989 if (data->start < provstart || data->end > provend)
991 map_empty(&cbd->providedids);
992 provstart = provend = 0;
995 /* check if the data is incomplete */
997 if (data->state == REPODATA_AVAILABLE)
999 for (j = 1; j < data->nkeys; j++)
1000 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1002 if (j < data->nkeys)
1005 for (i = 0; i < cbd->nfiles; i++)
1006 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
1007 printf("need complete filelist because of %s\n", id2str(pool, cbd->ids[i]));
1009 for (i = 0; i < cbd->nfiles; i++)
1010 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, id2str(pool, cbd->ids[i])))
1012 if (i < cbd->nfiles)
1018 map_init(&cbd->useddirs, 0);
1019 for (p = data->start; p < data->end; p++)
1020 if (pool->solvables[p].repo == repo)
1022 if (MAPTST(&donemap, p))
1024 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1027 MAPSET(&donemap, p);
1031 map_free(&cbd->useddirs);
1034 if (repoonly || ++repoid == pool->nrepos)
1036 repo = pool->repos[repoid];
1039 queue_free(&fileprovidesq);
1040 map_free(&cbd->providedids);
1044 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1048 struct searchfiles sf, isf, *isfp;
1049 struct addfileprovides_cbdata cbd;
1053 now = sat_timems(0);
1054 memset(&sf, 0, sizeof(sf));
1055 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1056 memset(&isf, 0, sizeof(isf));
1057 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1059 isfp = installed ? &isf : 0;
1060 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1066 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1068 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1070 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1072 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1074 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1076 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1078 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1081 map_free(&isf.seen);
1082 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1089 for (i = 0; i < sf.nfiles; i++)
1090 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
1092 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1095 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1096 sf.ids[sf.nfiles] = 0;
1101 for (i = 0; i < sf.nfiles; i++)
1103 sat_free(sf.dirs[i]);
1104 sat_free(sf.names[i]);
1112 for (i = 0; i < isf.nfiles; i++)
1113 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
1116 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1118 for (i = 0; i < isf.nfiles; i++)
1120 sat_free(isf.dirs[i]);
1121 sat_free(isf.names[i]);
1124 sat_free(isf.names);
1127 pool_freewhatprovides(pool); /* as we have added provides */
1128 POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
1132 pool_addfileprovides(Pool *pool)
1134 pool_addfileprovides_ids(pool, pool->installed, 0);
1138 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)
1142 if (pool->solvables[p].repo)
1143 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1146 /* FIXME: obey callback return value! */
1147 for (p = 1; p < pool->nsolvables; p++)
1148 if (pool->solvables[p].repo)
1149 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1153 pool_clear_pos(Pool *pool)
1155 memset(&pool->pos, 0, sizeof(pool->pos));
1160 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1164 pool->languagecache = sat_free(pool->languagecache);
1165 pool->languagecacheother = 0;
1166 if (pool->nlanguages)
1168 for (i = 0; i < pool->nlanguages; i++)
1169 free((char *)pool->languages[i]);
1170 free(pool->languages);
1172 pool->nlanguages = nlanguages;
1175 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1176 for (i = 0; i < pool->nlanguages; i++)
1177 pool->languages[i] = strdup(languages[i]);
1181 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1189 n = id2str(pool, id);
1190 l = strlen(n) + strlen(lang) + 2;
1191 if (l > sizeof(buf))
1192 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1195 sprintf(p, "%s:%s", n, lang);
1196 id = str2id(pool, p, create);
1203 pool_alloctmpspace(Pool *pool, int len)
1205 int n = pool->tmpspacen;
1208 if (len > pool->tmpspacelen[n])
1210 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1211 pool->tmpspacelen[n] = len + 32;
1213 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1214 return pool->tmpspacebuf[n];
1218 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1222 l1 = str1 ? strlen(str1) : 0;
1223 l2 = str2 ? strlen(str2) : 0;
1224 l3 = str3 ? strlen(str3) : 0;
1225 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1246 /*******************************************************************/
1258 struct mptree *mptree;
1269 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1271 struct ducbdata *cbd = cbdata;
1274 if (data != cbd->olddata)
1276 Id dn, mp, comp, *dirmap, *dirs;
1278 const char *compstr;
1279 struct mptree *mptree;
1281 /* create map from dir to mptree */
1282 cbd->dirmap = sat_free(cbd->dirmap);
1284 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1285 mptree = cbd->mptree;
1287 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1301 if (!mptree[mp].child)
1306 if (data->localpool)
1307 compstr = stringpool_id2str(&data->spool, comp);
1309 compstr = id2str(data->repo->pool, comp);
1310 compl = strlen(compstr);
1311 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1312 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1314 dirmap[dn] = i ? i : -mp;
1316 /* change dirmap to point to mountpoint instead of mptree */
1317 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1320 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1322 cbd->dirmap = dirmap;
1323 cbd->nmap = data->dirpool.ndirs;
1324 cbd->olddata = data;
1327 if (value->id < 0 || value->id >= cbd->nmap)
1329 mp = cbd->dirmap[value->id];
1332 if (cbd->addsub > 0)
1334 cbd->mps[mp].kbytes += value->num;
1335 cbd->mps[mp].files += value->num2;
1339 cbd->mps[mp].kbytes -= value->num;
1340 cbd->mps[mp].files -= value->num2;
1346 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1349 if (mptree[pos].mountpoint == -1)
1350 mptree[pos].mountpoint = mountpoint;
1352 mountpoint = mptree[pos].mountpoint;
1353 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1354 propagate_mountpoints(mptree, i, mountpoint);
1357 #define MPTREE_BLOCK 15
1360 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1363 const char *path, *compstr;
1364 struct mptree *mptree;
1368 struct ducbdata cbd;
1372 Repo *oldinstalled = pool->installed;
1374 memset(&ignoredu, 0, sizeof(ignoredu));
1381 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1384 mptree[0].sibling = 0;
1385 mptree[0].child = 0;
1387 mptree[0].compl = 0;
1388 mptree[0].mountpoint = -1;
1391 /* create component tree */
1392 for (mp = 0; mp < nmps; mp++)
1397 path = mps[mp].path;
1402 if ((p = strchr(path, '/')) == 0)
1405 compl = strlen(compstr);
1416 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1417 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1421 /* create new node */
1422 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1424 mptree[i].sibling = mptree[pos].child;
1425 mptree[i].child = 0;
1426 mptree[i].comp = compstr;
1427 mptree[i].compl = compl;
1428 mptree[i].mountpoint = -1;
1429 mptree[pos].child = i;
1433 mptree[pos].mountpoint = mp;
1436 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1439 for (i = 0; i < nmptree; i++)
1441 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1442 printf("#%d child: %d\n", i, mptree[i].child);
1443 printf("#%d comp: %s\n", i, mptree[i].comp);
1444 printf("#%d compl: %d\n", i, mptree[i].compl);
1445 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1449 cbd.mptree = mptree;
1451 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1453 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1455 if (!MAPTST(installedmap, sp))
1458 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1459 if (!cbd.hasdu && oldinstalled)
1462 /* no du data available, ignore data of all installed solvables we obsolete */
1464 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1467 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1468 while ((obs = *obsp++) != 0)
1469 FOR_PROVIDES(op, opp, obs)
1470 if (op >= oldinstalled->start && op < oldinstalled->end)
1471 MAPSET(&ignoredu, op - oldinstalled->start);
1473 FOR_PROVIDES(op, opp, s->name)
1474 if (pool->solvables[op].name == s->name)
1475 if (op >= oldinstalled->start && op < oldinstalled->end)
1476 MAPSET(&ignoredu, op - oldinstalled->start);
1482 /* assumes we allways have du data for installed solvables */
1483 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1485 if (MAPTST(installedmap, sp))
1487 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1489 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1493 map_free(&ignoredu);
1494 sat_free(cbd.dirmap);
1499 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1504 Repo *oldinstalled = pool->installed;
1506 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1508 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1510 if (!MAPTST(installedmap, sp))
1512 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1516 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1518 if (MAPTST(installedmap, sp))
1520 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1528 * 2: conflicts with installed
1529 * 8: interesting (only true if installed)
1533 static inline Id dep2name(Pool *pool, Id dep)
1535 while (ISRELDEP(dep))
1537 Reldep *rd = rd = GETRELDEP(pool, dep);
1543 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1546 Solvable *sn = pool->solvables + n;
1548 FOR_PROVIDES(p, pp, sn->name)
1550 Solvable *s = pool->solvables + p;
1551 if (s->name != sn->name || s->arch != sn->arch)
1553 if ((map[p] & 9) != 9)
1555 if (pool_match_nevr(pool, pool->solvables + p, con))
1557 return 1; /* found installed package that doesn't conflict */
1562 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1566 FOR_PROVIDES(p, pp, dep)
1568 if (p == SYSTEMSOLVABLE)
1569 return 1; /* always boring, as never constraining */
1570 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1572 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1573 if (providedbyinstalled_multiversion(pool, map, p, dep))
1575 if ((map[p] & 9) == 9)
1583 * pool_trivial_installable - calculate if a set of solvables is
1584 * trivial installable without any other installs/deinstalls of
1585 * packages not belonging to the set.
1587 * the state is returned in the result queue:
1588 * 1: solvable is installable without any other package changes
1589 * 0: solvable is not installable
1590 * -1: solvable is installable, but doesn't constrain any installed packages
1594 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1597 Id p, *dp, con, *conp, req, *reqp;
1601 map = sat_calloc(pool->nsolvables, 1);
1602 for (p = 1; p < pool->nsolvables; p++)
1604 if (!MAPTST(installedmap, p))
1607 s = pool->solvables + p;
1610 conp = s->repo->idarraydata + s->conflicts;
1611 while ((con = *conp++) != 0)
1613 dp = pool_whatprovides_ptr(pool, con);
1615 map[p] |= 2; /* XXX: self conflict ? */
1618 for (i = 0; i < pkgs->count; i++)
1619 map[pkgs->elements[i]] = 16;
1621 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1623 if (i == pkgs->count)
1625 p = pkgs->elements[i];
1626 if ((map[p] & 16) == 0)
1628 if ((map[p] & 2) != 0)
1633 s = pool->solvables + p;
1637 reqp = s->repo->idarraydata + s->requires;
1638 while ((req = *reqp++) != 0)
1640 if (req == SOLVABLE_PREREQMARKER)
1642 r = providedbyinstalled(pool, map, req, 0, 0);
1645 /* decided and miss */
1649 m |= r; /* 1 | 9 | 16 | 17 */
1658 int ispatch = 0; /* see solver.c patch handling */
1660 if (!strncmp("patch:", id2str(pool, s->name), 6))
1662 conp = s->repo->idarraydata + s->conflicts;
1663 while ((con = *conp++) != 0)
1665 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1670 if ((m == 1 || m == 17) && ISRELDEP(con))
1672 con = dep2name(pool, con);
1673 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1678 continue; /* found a conflict */
1681 if (s->repo && s->repo != oldinstalled)
1683 Id p2, obs, *obsp, *pp;
1687 obsp = s->repo->idarraydata + s->obsoletes;
1688 while ((obs = *obsp++) != 0)
1690 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1699 FOR_PROVIDES(p2, pp, s->name)
1701 s2 = pool->solvables + p2;
1702 if (s2->name == s->name && (map[p2] & 1) != 0)
1719 queue_init_clone(res, pkgs);
1720 for (i = 0; i < pkgs->count; i++)
1722 m = map[pkgs->elements[i]];
1729 res->elements[i] = r;
1735 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1737 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1741 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1743 if (entry == SOLVID_POS && pool->pos.repo)
1744 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1747 return solvable_lookup_str(pool->solvables + entry, keyname);
1751 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1753 if (entry == SOLVID_POS && pool->pos.repo)
1755 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1756 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1757 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1761 return solvable_lookup_id(pool->solvables + entry, keyname);
1765 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1767 if (entry == SOLVID_POS && pool->pos.repo)
1770 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1776 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1780 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1782 if (entry == SOLVID_POS && pool->pos.repo)
1783 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1786 return solvable_lookup_void(pool->solvables + entry, keyname);
1789 const unsigned char *
1790 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1792 if (entry == SOLVID_POS && pool->pos.repo)
1793 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1796 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1800 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1802 if (entry == SOLVID_POS && pool->pos.repo)
1804 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1805 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1809 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1813 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1815 int hadhashes = pool->relhashtbl ? 1 : 0;
1821 if (!conflicts->count)
1823 pool_freewhatprovides(pool);
1824 for (i = 0; i < conflicts->count; i += 5)
1826 fn = conflicts->elements[i];
1827 p = conflicts->elements[i + 1];
1828 md5 = conflicts->elements[i + 2];
1829 q = conflicts->elements[i + 3];
1830 id = rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1831 s = pool->solvables + p;
1834 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1835 s = pool->solvables + q;
1838 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1841 pool_freeidhashes(pool);