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;
68 pool->allowselfconflicts = 1;
69 # ifdef MULTI_SEMANTICS
70 pool->disttype = DISTTYPE_DEB;
74 pool->obsoleteusesprovides = 1;
75 pool->implicitobsoleteusesprovides = 1;
81 /* free all the resources of our pool */
87 pool_freewhatprovides(pool);
88 pool_freeidhashes(pool);
89 repo_freeallrepos(pool, 1);
90 sat_free(pool->id2arch);
91 sat_free(pool->solvables);
92 stringpool_free(&pool->ss);
94 pool_setvendorclasses(pool, 0);
95 queue_free(&pool->vendormap);
96 for (i = 0; i < POOL_TMPSPACEBUF; i++)
97 sat_free(pool->tmpspace.buf[i]);
98 for (i = 0; i < pool->nlanguages; i++)
99 free((char *)pool->languages[i]);
100 sat_free(pool->languages);
101 sat_free(pool->languagecache);
105 #ifdef MULTI_SEMANTICS
107 pool_setdisttype(Pool *pool, int disttype)
109 pool->disttype = disttype;
114 pool_add_solvable(Pool *pool)
116 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
117 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
118 return pool->nsolvables++;
122 pool_add_solvable_block(Pool *pool, int count)
124 Id nsolvables = pool->nsolvables;
127 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
128 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
129 pool->nsolvables += count;
134 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
138 if (reuseids && start + count == pool->nsolvables)
140 /* might want to shrink solvable array */
141 pool->nsolvables = start;
144 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
149 pool_set_installed(Pool *pool, Repo *installed)
151 if (pool->installed == installed)
153 pool->installed = installed;
154 pool_freewhatprovides(pool);
158 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp, void *dp)
163 oa = pool->whatprovides[*(Id *)ap];
164 ob = pool->whatprovides[*(Id *)bp];
166 return *(Id *)ap - *(Id *)bp;
171 da = pool->whatprovidesdata + oa;
172 db = pool->whatprovidesdata + ob;
174 if ((r = (*da++ - *db++)) != 0)
178 return *(Id *)ap - *(Id *)bp;
182 * pool_shrink_whatprovides - unify whatprovides data
184 * whatprovides_rel must be empty for this to work!
188 pool_shrink_whatprovides(Pool *pool)
192 Id lastid, *last, *dp, *lp;
196 if (pool->ss.nstrings < 3)
198 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
199 for (id = 0; id < pool->ss.nstrings; id++)
201 sat_sort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp, pool);
204 for (i = 1; i < pool->ss.nstrings; i++)
207 o = pool->whatprovides[id];
208 if (o == 0 || o == 1)
210 dp = pool->whatprovidesdata + o;
224 pool->whatprovides[id] = -lastid;
228 last = pool->whatprovidesdata + o;
232 dp = pool->whatprovidesdata + 2;
233 for (id = 1; id < pool->ss.nstrings; id++)
235 o = pool->whatprovides[id];
236 if (o == 0 || o == 1)
243 pool->whatprovides[id] = pool->whatprovides[i];
246 lp = pool->whatprovidesdata + o;
249 pool->whatprovides[id] = dp - pool->whatprovidesdata;
250 while ((*dp++ = *lp++) != 0)
253 o = dp - pool->whatprovidesdata;
254 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
255 if (pool->whatprovidesdataoff == o)
257 r = pool->whatprovidesdataoff - o;
258 pool->whatprovidesdataoff = o;
259 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
260 if (r > pool->whatprovidesdataleft)
261 r = pool->whatprovidesdataleft;
262 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
267 * pool_createwhatprovides()
269 * create hashes over pool of solvables to ease provide lookups
273 pool_createwhatprovides(Pool *pool)
275 int i, num, np, extra;
280 Offset *whatprovides;
281 Id *whatprovidesdata, *d;
282 Repo *installed = pool->installed;
286 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
287 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
289 pool_freeidhashes(pool); /* XXX: should not be here! */
290 pool_freewhatprovides(pool);
291 num = pool->ss.nstrings;
292 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
293 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
295 /* count providers for each name */
296 for (i = pool->nsolvables - 1; i > 0; i--)
299 s = pool->solvables + i;
300 if (!s->provides || !s->repo || s->repo->disabled)
302 /* we always need the installed solvable in the whatprovides data,
303 otherwise obsoletes/conflicts on them won't work */
304 if (s->repo != installed && !pool_installable(pool, s))
306 pp = s->repo->idarraydata + s->provides;
307 while ((id = *pp++) != 0)
311 Reldep *rd = GETRELDEP(pool, id);
314 whatprovides[id]++; /* inc count of providers */
318 off = 2; /* first entry is undef, second is empty list */
319 np = 0; /* number of names provided */
320 for (i = 0, idp = whatprovides; i < num; i++, idp++)
323 if (!n) /* no providers */
325 off += n; /* make space for all providers */
326 *idp = off++; /* now idp points to terminating zero */
327 np++; /* inc # of provider 'slots' for stats */
330 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
332 /* reserve some space for relation data */
333 extra = 2 * pool->nrels;
337 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
339 /* alloc space for all providers + extra */
340 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
342 /* now fill data for all provides */
343 for (i = pool->nsolvables - 1; i > 0; i--)
346 s = pool->solvables + i;
347 if (!s->provides || !s->repo || s->repo->disabled)
349 if (s->repo != installed && !pool_installable(pool, s))
352 /* for all provides of this solvable */
353 pp = s->repo->idarraydata + s->provides;
354 while ((id = *pp++) != 0)
358 Reldep *rd = GETRELDEP(pool, id);
361 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
362 if (*d != i) /* don't add same solvable twice */
369 pool->whatprovidesdata = whatprovidesdata;
370 pool->whatprovidesdataoff = off;
371 pool->whatprovidesdataleft = extra;
372 pool_shrink_whatprovides(pool);
373 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)));
374 POOL_DEBUG(SAT_DEBUG_STATS, "createwhatprovides took %d ms\n", sat_timems(now));
378 * free all of our whatprovides data
379 * be careful, everything internalized with pool_queuetowhatprovides is
383 pool_freewhatprovides(Pool *pool)
385 pool->whatprovides = sat_free(pool->whatprovides);
386 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
387 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
388 pool->whatprovidesdataoff = 0;
389 pool->whatprovidesdataleft = 0;
393 /******************************************************************************/
396 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
398 * on-demand filling of provider information
399 * move queue data into whatprovidesdata
401 * returns: Offset into whatprovides
405 pool_queuetowhatprovides(Pool *pool, Queue *q)
408 int count = q->count;
410 if (count == 0) /* queue empty -> 1 */
413 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
414 if (pool->whatprovidesdataleft < count + 1)
416 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
417 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
418 pool->whatprovidesdataleft = count + 4096;
421 /* copy queue to next free slot */
422 off = pool->whatprovidesdataoff;
423 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
425 /* adapt count and ID_NULL-terminate */
426 pool->whatprovidesdataoff += count;
427 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
428 pool->whatprovidesdataleft -= count + 1;
434 /*************************************************************************/
436 #if defined(MULTI_SEMANTICS)
437 # define EVRCMP_DEPCMP (pool->disttype == DISTTYPE_DEB ? EVRCMP_COMPARE : EVRCMP_MATCH_RELEASE)
438 #elif defined(DEBIAN_SEMANTICS)
439 # define EVRCMP_DEPCMP EVRCMP_COMPARE
441 # define EVRCMP_DEPCMP EVRCMP_MATCH_RELEASE
444 /* check if a package's nevr matches a dependency */
447 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
449 Reldep *rd = GETRELDEP(pool, d);
452 int flags = rd->flags;
461 return pool_match_nevr(pool, s, name);
463 if (pool_match_nevr(pool, s, name))
465 return pool_match_nevr(pool, s, evr);
468 if (!pool_match_nevr(pool, s, name))
470 return pool_match_nevr(pool, s, evr);
475 if (!pool_match_nevr(pool, s, name))
478 return flags & 2 ? 1 : 0;
483 if (flags != 2 && flags != 5)
485 if ((flags & (1 << (1 + pool_evrcmp(pool, s->evr, evr, EVRCMP_DEPCMP)))) != 0)
490 /* match (flags, evr) against provider (pflags, pevr) */
492 pool_match_flags_evr(Pool *pool, int pflags, Id pevr, int flags, int evr)
494 if (!pflags || !flags || pflags >= 8 || flags >= 8)
496 if (flags == 7 || pflags == 7)
497 return 1; /* rel provides every version */
498 if ((pflags & flags & 5) != 0)
499 return 1; /* both rels show in the same direction */
502 if ((pflags & flags & 2) != 0)
503 return 1; /* both have '=', match */
507 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
508 if ((f & (1 << (1 + pool_evrcmp(pool, pevr, evr, EVRCMP_DEPCMP)))) != 0)
514 /* match two dependencies (d1 = provider) */
517 pool_match_dep(Pool *pool, Id d1, Id d2)
527 rd2 = GETRELDEP(pool, d2);
528 return pool_match_dep(pool, d1, rd2->name);
530 rd1 = GETRELDEP(pool, d1);
533 return pool_match_dep(pool, rd1->name, d2);
535 rd2 = GETRELDEP(pool, d2);
536 /* first match name */
537 if (!pool_match_dep(pool, rd1->name, rd2->name))
539 /* name matches, check flags and evr */
540 return pool_match_flags_evr(pool, rd1->flags, rd1->evr, rd2->flags, rd2->evr);
546 * add packages fulfilling the relation to whatprovides array
547 * no exact providers, do range match
552 pool_addrelproviders(Pool *pool, Id d)
554 Reldep *rd = GETRELDEP(pool, d);
560 int flags = rd->flags;
565 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
569 /* special relation */
577 wp = pool_whatprovides(pool, name);
578 pp2 = pool_whatprovides_ptr(pool, evr);
579 pp = pool->whatprovidesdata + wp;
580 while ((p = *pp++) != 0)
582 for (pp3 = pp2; *pp3; pp3++)
586 queue_push(&plist, p); /* found it */
592 wp = pool_whatprovides(pool, name);
593 pp = pool->whatprovidesdata + wp;
595 wp = pool_whatprovides(pool, evr);
599 while ((p = *pp++) != 0)
600 queue_push(&plist, p);
602 pp = pool_whatprovides_ptr(pool, evr);
603 while ((p = *pp++) != 0)
604 queue_pushunique(&plist, p);
605 if (plist.count != cnt)
610 if (name == NAMESPACE_OTHERPROVIDERS)
612 wp = pool_whatprovides(pool, evr);
615 if (pool->nscallback)
617 /* ask callback which packages provide the dependency
619 * 1: the system (aka SYSTEMSOLVABLE)
620 * >1: set of packages, stored as offset on whatprovidesdata
622 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
626 queue_push(&plist, SYSTEMSOLVABLE);
630 /* small hack: make it possible to match <pkg>.src
631 * we have to iterate over the solvables as src packages do not
632 * provide anything, thus they are not indexed in our
633 * whatprovides hash */
637 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
639 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
641 if (pool_match_nevr(pool, s, name))
642 queue_push(&plist, p);
646 wp = pool_whatprovides(pool, name);
647 pp = pool->whatprovidesdata + wp;
648 while ((p = *pp++) != 0)
650 Solvable *s = pool->solvables + p;
652 queue_push(&plist, p);
657 case REL_FILECONFLICT:
658 pp = pool_whatprovides_ptr(pool, name);
659 while ((p = *pp++) != 0)
661 Id origd = MAKERELDEP(d);
662 Solvable *s = pool->solvables + p;
665 pidp = s->repo->idarraydata + s->provides;
666 while ((pid = *pidp++) != 0)
670 queue_push(&plist, p);
678 /* we can reuse an existing entry */
680 pool->whatprovides_rel[d] = wp;
686 /* simple version comparison relation */
688 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", pool_dep2str(pool, name));
690 pp = pool_whatprovides_ptr(pool, name);
691 while (ISRELDEP(name))
693 rd = GETRELDEP(pool, name);
696 while ((p = *pp++) != 0)
698 Solvable *s = pool->solvables + p;
701 /* no provides - check nevr */
702 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
703 queue_push(&plist, p);
706 /* solvable p provides name in some rels */
707 pidp = s->repo->idarraydata + s->provides;
708 while ((pid = *pidp++) != 0)
712 #if defined(MULTI_SEMANTICS)
713 if (pool->disttype == DISTTYPE_DEB)
717 #elif defined(DEBIAN_SEMANTICS)
718 continue; /* unversioned provides can
719 * never match versioned deps */
721 break; /* yes, provides all versions */
725 continue; /* wrong provides name */
726 prd = GETRELDEP(pool, pid);
727 if (prd->name != name)
728 continue; /* wrong provides name */
729 /* right package, both deps are rels. check flags/evr */
730 if (pool_match_flags_evr(pool, prd->flags, prd->evr, flags, evr))
734 continue; /* none of the providers matched */
735 queue_push(&plist, p);
737 /* make our system solvable provide all unknown rpmlib() stuff */
738 if (plist.count == 0 && !strncmp(pool_id2str(pool, name), "rpmlib(", 7))
739 queue_push(&plist, SYSTEMSOLVABLE);
741 /* add providers to whatprovides */
743 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
745 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
748 return pool->whatprovides_rel[d];
751 /*************************************************************************/
754 pool_debug(Pool *pool, int type, const char *format, ...)
759 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
761 if ((pool->debugmask & type) == 0)
764 va_start(args, format);
765 if (!pool->debugcallback)
767 if ((type & (SAT_FATAL|SAT_ERROR)) == 0 && !(pool->debugmask & SAT_DEBUG_TO_STDERR))
768 vprintf(format, args);
770 vfprintf(stderr, format, args);
773 vsnprintf(buf, sizeof(buf), format, args);
774 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
778 pool_setdebuglevel(Pool *pool, int level)
780 int mask = SAT_DEBUG_RESULT;
782 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE|SAT_DEBUG_SOLVER|SAT_DEBUG_TRANSACTION;
784 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
786 mask |= SAT_DEBUG_PROPAGATE;
788 mask |= SAT_DEBUG_RULE_CREATION;
789 mask |= pool->debugmask & SAT_DEBUG_TO_STDERR; /* keep bit */
790 pool->debugmask = mask;
793 void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct _Pool *, void *data, int type, const char *str), void *debugcallbackdata)
795 pool->debugcallback = debugcallback;
796 pool->debugcallbackdata = debugcallbackdata;
799 void pool_setdebugmask(Pool *pool, int mask)
801 pool->debugmask = mask;
804 void pool_setloadcallback(Pool *pool, int (*cb)(struct _Pool *, struct _Repodata *, void *), void *loadcbdata)
806 pool->loadcallback = cb;
807 pool->loadcallbackdata = loadcbdata;
810 /*************************************************************************/
820 #define SEARCHFILES_BLOCK 127
823 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
827 struct searchfiles *csf;
829 while ((dep = *ida++) != 0)
832 while (ISRELDEP(dep))
835 sid = pool->ss.nstrings + GETRELID(dep);
836 if (MAPTST(&csf->seen, sid))
841 MAPSET(&csf->seen, sid);
842 rd = GETRELDEP(pool, dep);
845 else if (rd->flags == REL_NAMESPACE)
847 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
850 if (!csf || MAPTST(&csf->seen, sid))
855 MAPSET(&csf->seen, sid);
859 else if (rd->flags == REL_FILECONFLICT)
869 pool_addfileprovides_dep(pool, ids, csf, isf);
875 if (MAPTST(&csf->seen, dep))
877 MAPSET(&csf->seen, dep);
878 s = pool_id2str(pool, dep);
881 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
882 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
883 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
884 csf->ids[csf->nfiles] = dep;
885 sr = strrchr(s, '/');
886 csf->names[csf->nfiles] = strdup(sr + 1);
887 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
889 strncpy(csf->dirs[csf->nfiles], s, sr - s);
890 csf->dirs[csf->nfiles][sr - s] = 0;
895 struct addfileprovides_cbdata {
909 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
911 struct addfileprovides_cbdata *cbd = cbdata;
914 if (!cbd->useddirs.size)
916 map_init(&cbd->useddirs, data->dirpool.ndirs + 1);
917 for (i = 0; i < cbd->nfiles; i++)
920 if (MAPTST(&cbd->providedids, cbd->ids[i]))
925 did = repodata_str2dir(data, cbd->dirs[i], 0);
928 MAPSET(&cbd->useddirs, did);
931 if (value->id >= data->dirpool.ndirs || !MAPTST(&cbd->useddirs, value->id))
933 for (i = 0; i < cbd->nfiles; i++)
935 if (cbd->dids[i] != value->id)
937 if (!strcmp(cbd->names[i], value->str))
940 if (i == cbd->nfiles)
942 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
947 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
953 int i, j, repoid, repodataid;
954 int provstart, provend;
956 int ndone, incomplete;
961 cbd->nfiles = sf->nfiles;
963 cbd->dirs = sf->dirs;
964 cbd->names = sf->names;
965 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
966 map_init(&cbd->providedids, pool->ss.nstrings);
969 repo = repoonly ? repoonly : pool->repos[0];
970 map_init(&donemap, pool->nsolvables);
971 queue_init(&fileprovidesq);
972 provstart = provend = 0;
977 if (repoonly || ++repoid == pool->nrepos)
979 repo = pool->repos[repoid];
983 for (data = repo->repodata, repodataid = 0; repodataid < repo->nrepodata; repodataid++, data++)
985 if (ndone >= repo->nsolvables)
988 if (repodata_lookup_idarray(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, &fileprovidesq))
990 map_empty(&cbd->providedids);
991 for (i = 0; i < fileprovidesq.count; i++)
992 MAPSET(&cbd->providedids, fileprovidesq.elements[i]);
993 provstart = data->start;
995 for (i = 0; i < cbd->nfiles; i++)
996 if (!MAPTST(&cbd->providedids, cbd->ids[i]))
998 if (i == cbd->nfiles)
1000 /* great! no need to search files */
1001 for (p = data->start; p < data->end; p++)
1002 if (pool->solvables[p].repo == repo)
1004 if (MAPTST(&donemap, p))
1006 MAPSET(&donemap, p);
1013 if (!repodata_has_keyname(data, SOLVABLE_FILELIST))
1016 if (data->start < provstart || data->end > provend)
1018 map_empty(&cbd->providedids);
1019 provstart = provend = 0;
1022 /* check if the data is incomplete */
1024 if (data->state == REPODATA_AVAILABLE)
1026 for (j = 1; j < data->nkeys; j++)
1027 if (data->keys[j].name != REPOSITORY_SOLVABLES && data->keys[j].name != SOLVABLE_FILELIST)
1029 if (j < data->nkeys)
1032 for (i = 0; i < cbd->nfiles; i++)
1033 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1034 printf("need complete filelist because of %s\n", pool_id2str(pool, cbd->ids[i]));
1036 for (i = 0; i < cbd->nfiles; i++)
1037 if (!MAPTST(&cbd->providedids, cbd->ids[i]) && !repodata_filelistfilter_matches(data, pool_id2str(pool, cbd->ids[i])))
1039 if (i < cbd->nfiles)
1045 map_init(&cbd->useddirs, 0);
1046 for (p = data->start; p < data->end; p++)
1047 if (pool->solvables[p].repo == repo)
1049 if (MAPTST(&donemap, p))
1051 repodata_search(data, p, SOLVABLE_FILELIST, 0, addfileprovides_cb, cbd);
1054 MAPSET(&donemap, p);
1058 map_free(&cbd->useddirs);
1061 if (repoonly || ++repoid == pool->nrepos)
1063 repo = pool->repos[repoid];
1066 queue_free(&fileprovidesq);
1067 map_free(&cbd->providedids);
1071 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
1075 struct searchfiles sf, isf, *isfp;
1076 struct addfileprovides_cbdata cbd;
1080 now = sat_timems(0);
1081 memset(&sf, 0, sizeof(sf));
1082 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
1083 memset(&isf, 0, sizeof(isf));
1084 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
1086 isfp = installed ? &isf : 0;
1087 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
1093 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
1095 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
1097 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
1099 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
1101 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
1103 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
1105 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
1108 map_free(&isf.seen);
1109 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies, %d installed file dependencies\n", sf.nfiles, isf.nfiles);
1116 for (i = 0; i < sf.nfiles; i++)
1117 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", pool_id2str(pool, sf.ids[i]));
1119 pool_addfileprovides_search(pool, &cbd, &sf, 0);
1122 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
1123 sf.ids[sf.nfiles] = 0;
1128 for (i = 0; i < sf.nfiles; i++)
1130 sat_free(sf.dirs[i]);
1131 sat_free(sf.names[i]);
1139 for (i = 0; i < isf.nfiles; i++)
1140 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", pool_id2str(pool, isf.ids[i]));
1143 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1145 for (i = 0; i < isf.nfiles; i++)
1147 sat_free(isf.dirs[i]);
1148 sat_free(isf.names[i]);
1151 sat_free(isf.names);
1154 pool_freewhatprovides(pool); /* as we have added provides */
1155 POOL_DEBUG(SAT_DEBUG_STATS, "addfileprovides took %d ms\n", sat_timems(now));
1159 pool_addfileprovides(Pool *pool)
1161 pool_addfileprovides_ids(pool, pool->installed, 0);
1165 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)
1169 if (pool->solvables[p].repo)
1170 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1173 /* FIXME: obey callback return value! */
1174 for (p = 1; p < pool->nsolvables; p++)
1175 if (pool->solvables[p].repo)
1176 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1180 pool_clear_pos(Pool *pool)
1182 memset(&pool->pos, 0, sizeof(pool->pos));
1187 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1191 pool->languagecache = sat_free(pool->languagecache);
1192 pool->languagecacheother = 0;
1193 if (pool->nlanguages)
1195 for (i = 0; i < pool->nlanguages; i++)
1196 free((char *)pool->languages[i]);
1197 free(pool->languages);
1199 pool->nlanguages = nlanguages;
1202 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1203 for (i = 0; i < pool->nlanguages; i++)
1204 pool->languages[i] = strdup(languages[i]);
1208 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1216 n = pool_id2str(pool, id);
1217 l = strlen(n) + strlen(lang) + 2;
1218 if (l > sizeof(buf))
1219 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1222 sprintf(p, "%s:%s", n, lang);
1223 id = pool_str2id(pool, p, create);
1230 pool_alloctmpspace(Pool *pool, int len)
1232 int n = pool->tmpspace.n;
1235 if (len > pool->tmpspace.len[n])
1237 pool->tmpspace.buf[n] = sat_realloc(pool->tmpspace.buf[n], len + 32);
1238 pool->tmpspace.len[n] = len + 32;
1240 pool->tmpspace.n = (n + 1) % POOL_TMPSPACEBUF;
1241 return pool->tmpspace.buf[n];
1245 pool_alloctmpspace_free(Pool *pool, const char *space, int len)
1250 n = oldn = pool->tmpspace.n;
1254 n = POOL_TMPSPACEBUF - 1;
1257 if (pool->tmpspace.buf[n] != space)
1259 if (len > pool->tmpspace.len[n])
1261 pool->tmpspace.buf[n] = sat_realloc(pool->tmpspace.buf[n], len + 32);
1262 pool->tmpspace.len[n] = len + 32;
1264 return pool->tmpspace.buf[n];
1271 pool_freetmpspace(Pool *pool, const char *space)
1273 int n = pool->tmpspace.n;
1276 n = (n + (POOL_TMPSPACEBUF - 1)) % POOL_TMPSPACEBUF;
1277 if (pool->tmpspace.buf[n] == space)
1278 pool->tmpspace.n = n;
1282 pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3)
1286 l1 = str1 ? strlen(str1) : 0;
1287 l2 = str2 ? strlen(str2) : 0;
1288 l3 = str3 ? strlen(str3) : 0;
1289 s = str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1310 pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3)
1315 l1 = str1 ? strlen(str1) : 0;
1316 l2 = str2 ? strlen(str2) : 0;
1317 l3 = str3 ? strlen(str3) : 0;
1318 str = pool_alloctmpspace_free(pool, str1, l1 + l2 + l3 + 1);
1322 str = pool_alloctmpspace(pool, l1 + l2 + l3 + 1);
1345 pool_bin2hex(Pool *pool, const unsigned char *buf, int len)
1350 s = pool_alloctmpspace(pool, 2 * len + 1);
1351 sat_bin2hex(buf, len, s);
1355 /*******************************************************************/
1367 struct mptree *mptree;
1378 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1380 struct ducbdata *cbd = cbdata;
1383 if (data != cbd->olddata)
1385 Id dn, mp, comp, *dirmap, *dirs;
1387 const char *compstr;
1388 struct mptree *mptree;
1390 /* create map from dir to mptree */
1391 cbd->dirmap = sat_free(cbd->dirmap);
1393 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1394 mptree = cbd->mptree;
1396 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1410 if (!mptree[mp].child)
1415 if (data->localpool)
1416 compstr = stringpool_id2str(&data->spool, comp);
1418 compstr = pool_id2str(data->repo->pool, comp);
1419 compl = strlen(compstr);
1420 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1421 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1423 dirmap[dn] = i ? i : -mp;
1425 /* change dirmap to point to mountpoint instead of mptree */
1426 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1429 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1431 cbd->dirmap = dirmap;
1432 cbd->nmap = data->dirpool.ndirs;
1433 cbd->olddata = data;
1436 if (value->id < 0 || value->id >= cbd->nmap)
1438 mp = cbd->dirmap[value->id];
1441 if (cbd->addsub > 0)
1443 cbd->mps[mp].kbytes += value->num;
1444 cbd->mps[mp].files += value->num2;
1448 cbd->mps[mp].kbytes -= value->num;
1449 cbd->mps[mp].files -= value->num2;
1455 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1458 if (mptree[pos].mountpoint == -1)
1459 mptree[pos].mountpoint = mountpoint;
1461 mountpoint = mptree[pos].mountpoint;
1462 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1463 propagate_mountpoints(mptree, i, mountpoint);
1466 #define MPTREE_BLOCK 15
1469 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1472 const char *path, *compstr;
1473 struct mptree *mptree;
1477 struct ducbdata cbd;
1481 Repo *oldinstalled = pool->installed;
1483 memset(&ignoredu, 0, sizeof(ignoredu));
1490 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1493 mptree[0].sibling = 0;
1494 mptree[0].child = 0;
1496 mptree[0].compl = 0;
1497 mptree[0].mountpoint = -1;
1500 /* create component tree */
1501 for (mp = 0; mp < nmps; mp++)
1506 path = mps[mp].path;
1511 if ((p = strchr(path, '/')) == 0)
1514 compl = strlen(compstr);
1525 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1526 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1530 /* create new node */
1531 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1533 mptree[i].sibling = mptree[pos].child;
1534 mptree[i].child = 0;
1535 mptree[i].comp = compstr;
1536 mptree[i].compl = compl;
1537 mptree[i].mountpoint = -1;
1538 mptree[pos].child = i;
1542 mptree[pos].mountpoint = mp;
1545 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1548 for (i = 0; i < nmptree; i++)
1550 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1551 printf("#%d child: %d\n", i, mptree[i].child);
1552 printf("#%d comp: %s\n", i, mptree[i].comp);
1553 printf("#%d compl: %d\n", i, mptree[i].compl);
1554 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1558 cbd.mptree = mptree;
1560 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1562 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1564 if (!MAPTST(installedmap, sp))
1567 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1568 if (!cbd.hasdu && oldinstalled)
1571 /* no du data available, ignore data of all installed solvables we obsolete */
1573 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1576 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1577 while ((obs = *obsp++) != 0)
1578 FOR_PROVIDES(op, opp, obs)
1579 if (op >= oldinstalled->start && op < oldinstalled->end)
1580 MAPSET(&ignoredu, op - oldinstalled->start);
1582 FOR_PROVIDES(op, opp, s->name)
1583 if (pool->solvables[op].name == s->name)
1584 if (op >= oldinstalled->start && op < oldinstalled->end)
1585 MAPSET(&ignoredu, op - oldinstalled->start);
1591 /* assumes we allways have du data for installed solvables */
1592 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1594 if (MAPTST(installedmap, sp))
1596 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1598 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1602 map_free(&ignoredu);
1603 sat_free(cbd.dirmap);
1608 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1613 Repo *oldinstalled = pool->installed;
1615 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1617 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1619 if (!MAPTST(installedmap, sp))
1621 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1625 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1627 if (MAPTST(installedmap, sp))
1629 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1637 * 2: conflicts with installed
1638 * 8: interesting (only true if installed)
1642 static inline Id dep2name(Pool *pool, Id dep)
1644 while (ISRELDEP(dep))
1646 Reldep *rd = rd = GETRELDEP(pool, dep);
1652 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id con)
1655 Solvable *sn = pool->solvables + n;
1657 FOR_PROVIDES(p, pp, sn->name)
1659 Solvable *s = pool->solvables + p;
1660 if (s->name != sn->name || s->arch != sn->arch)
1662 if ((map[p] & 9) != 9)
1664 if (pool_match_nevr(pool, pool->solvables + p, con))
1666 return 1; /* found installed package that doesn't conflict */
1671 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1675 FOR_PROVIDES(p, pp, dep)
1677 if (p == SYSTEMSOLVABLE)
1678 return 1; /* always boring, as never constraining */
1679 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1681 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1682 if (providedbyinstalled_multiversion(pool, map, p, dep))
1684 if ((map[p] & 9) == 9)
1692 * pool_trivial_installable - calculate if a set of solvables is
1693 * trivial installable without any other installs/deinstalls of
1694 * packages not belonging to the set.
1696 * the state is returned in the result queue:
1697 * 1: solvable is installable without any other package changes
1698 * 0: solvable is not installable
1699 * -1: solvable is installable, but doesn't constrain any installed packages
1703 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1706 Id p, *dp, con, *conp, req, *reqp;
1710 map = sat_calloc(pool->nsolvables, 1);
1711 for (p = 1; p < pool->nsolvables; p++)
1713 if (!MAPTST(installedmap, p))
1716 s = pool->solvables + p;
1719 conp = s->repo->idarraydata + s->conflicts;
1720 while ((con = *conp++) != 0)
1722 dp = pool_whatprovides_ptr(pool, con);
1724 map[p] |= 2; /* XXX: self conflict ? */
1727 for (i = 0; i < pkgs->count; i++)
1728 map[pkgs->elements[i]] = 16;
1730 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1732 if (i == pkgs->count)
1734 p = pkgs->elements[i];
1735 if ((map[p] & 16) == 0)
1737 if ((map[p] & 2) != 0)
1742 s = pool->solvables + p;
1746 reqp = s->repo->idarraydata + s->requires;
1747 while ((req = *reqp++) != 0)
1749 if (req == SOLVABLE_PREREQMARKER)
1751 r = providedbyinstalled(pool, map, req, 0, 0);
1754 /* decided and miss */
1758 m |= r; /* 1 | 9 | 16 | 17 */
1767 int ispatch = 0; /* see solver.c patch handling */
1769 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
1771 conp = s->repo->idarraydata + s->conflicts;
1772 while ((con = *conp++) != 0)
1774 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1779 if ((m == 1 || m == 17) && ISRELDEP(con))
1781 con = dep2name(pool, con);
1782 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1787 continue; /* found a conflict */
1790 if (s->repo && s->repo != oldinstalled)
1792 Id p2, obs, *obsp, *pp;
1796 obsp = s->repo->idarraydata + s->obsoletes;
1797 while ((obs = *obsp++) != 0)
1799 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1808 FOR_PROVIDES(p2, pp, s->name)
1810 s2 = pool->solvables + p2;
1811 if (s2->name == s->name && (map[p2] & 1) != 0)
1828 queue_init_clone(res, pkgs);
1829 for (i = 0; i < pkgs->count; i++)
1831 m = map[pkgs->elements[i]];
1838 res->elements[i] = r;
1844 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1846 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);
1850 pool_lookup_str(Pool *pool, Id entry, Id keyname)
1852 if (entry == SOLVID_POS && pool->pos.repo)
1853 return repodata_lookup_str(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1856 return solvable_lookup_str(pool->solvables + entry, keyname);
1860 pool_lookup_id(Pool *pool, Id entry, Id keyname)
1862 if (entry == SOLVID_POS && pool->pos.repo)
1864 Repodata *data = pool->pos.repo->repodata + pool->pos.repodataid;
1865 Id id = repodata_lookup_id(data, SOLVID_POS, keyname);
1866 return data->localpool ? repodata_globalize_id(data, id, 1) : id;
1870 return solvable_lookup_id(pool->solvables + entry, keyname);
1874 pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned int notfound)
1876 if (entry == SOLVID_POS && pool->pos.repo)
1879 if (repodata_lookup_num(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, &value))
1885 return solvable_lookup_num(pool->solvables + entry, keyname, notfound);
1889 pool_lookup_void(Pool *pool, Id entry, Id keyname)
1891 if (entry == SOLVID_POS && pool->pos.repo)
1892 return repodata_lookup_void(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname);
1895 return solvable_lookup_void(pool->solvables + entry, keyname);
1898 const unsigned char *
1899 pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1901 if (entry == SOLVID_POS && pool->pos.repo)
1902 return repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1905 return solvable_lookup_bin_checksum(pool->solvables + entry, keyname, typep);
1909 pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep)
1911 if (entry == SOLVID_POS && pool->pos.repo)
1913 const unsigned char *chk = repodata_lookup_bin_checksum(pool->pos.repo->repodata + pool->pos.repodataid, SOLVID_POS, keyname, typep);
1914 return chk ? repodata_chk2str(pool->pos.repo->repodata + pool->pos.repodataid, *typep, chk) : 0;
1918 return solvable_lookup_checksum(pool->solvables + entry, keyname, typep);
1922 pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts)
1924 int hadhashes = pool->relhashtbl ? 1 : 0;
1930 if (!conflicts->count)
1932 pool_freewhatprovides(pool);
1933 for (i = 0; i < conflicts->count; i += 5)
1935 fn = conflicts->elements[i];
1936 p = conflicts->elements[i + 1];
1937 md5 = conflicts->elements[i + 2];
1938 q = conflicts->elements[i + 3];
1939 id = pool_rel2id(pool, fn, md5, REL_FILECONFLICT, 1);
1940 s = pool->solvables + p;
1943 s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
1944 s = pool->solvables + q;
1947 s->conflicts = repo_addid_dep(s->repo, s->conflicts, id, 0);
1950 pool_freeidhashes(pool);