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);
92 pool_add_solvable(Pool *pool)
94 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
95 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
96 return pool->nsolvables++;
100 pool_add_solvable_block(Pool *pool, int count)
102 Id nsolvables = pool->nsolvables;
105 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
106 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
107 pool->nsolvables += count;
112 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
116 if (reuseids && start + count == pool->nsolvables)
118 /* might want to shrink solvable array */
119 pool->nsolvables = start;
122 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
127 pool_set_installed(Pool *pool, Repo *installed)
129 if (pool->installed == installed)
131 pool->installed = installed;
132 pool_freewhatprovides(pool);
135 static Pool *pool_shrink_whatprovides_sortcmp_data;
138 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
141 Pool *pool = pool_shrink_whatprovides_sortcmp_data;
143 oa = pool->whatprovides[*(Id *)ap];
144 ob = pool->whatprovides[*(Id *)bp];
146 return *(Id *)ap - *(Id *)bp;
151 da = pool->whatprovidesdata + oa;
152 db = pool->whatprovidesdata + ob;
154 if ((r = (*da++ - *db++)) != 0)
158 return *(Id *)ap - *(Id *)bp;
162 * pool_shrink_whatprovides - unify whatprovides data
164 * whatprovides_rel must be empty for this to work!
168 pool_shrink_whatprovides(Pool *pool)
172 Id lastid, *last, *dp, *lp;
176 if (pool->ss.nstrings < 3)
178 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
179 for (id = 0; id < pool->ss.nstrings; id++)
181 pool_shrink_whatprovides_sortcmp_data = pool;
182 qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
185 for (i = 1; i < pool->ss.nstrings; i++)
188 o = pool->whatprovides[id];
189 if (o == 0 || o == 1)
191 dp = pool->whatprovidesdata + o;
205 pool->whatprovides[id] = -lastid;
209 last = pool->whatprovidesdata + o;
213 dp = pool->whatprovidesdata + 2;
214 for (id = 1; id < pool->ss.nstrings; id++)
216 o = pool->whatprovides[id];
217 if (o == 0 || o == 1)
224 pool->whatprovides[id] = pool->whatprovides[i];
227 lp = pool->whatprovidesdata + o;
230 pool->whatprovides[id] = dp - pool->whatprovidesdata;
231 while ((*dp++ = *lp++) != 0)
234 o = dp - pool->whatprovidesdata;
235 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
236 if (pool->whatprovidesdataoff == o)
238 r = pool->whatprovidesdataoff - o;
239 pool->whatprovidesdataoff = o;
240 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
241 if (r > pool->whatprovidesdataleft)
242 r = pool->whatprovidesdataleft;
243 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
248 * pool_createwhatprovides()
250 * create hashes over pool of solvables to ease provide lookups
254 pool_createwhatprovides(Pool *pool)
256 int i, num, np, extra;
261 Offset *whatprovides;
262 Id *whatprovidesdata, *d;
263 Repo *installed = pool->installed;
267 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
268 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
270 pool_freeidhashes(pool); /* XXX: should not be here! */
271 pool_freewhatprovides(pool);
272 num = pool->ss.nstrings;
273 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
274 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
276 /* count providers for each name */
277 for (i = 1; i < pool->nsolvables; i++)
280 s = pool->solvables + i;
283 /* we always need the installed solvable in the whatprovides data,
284 otherwise obsoletes/conflicts on them won't work */
285 if (s->repo != installed && !pool_installable(pool, s))
287 pp = s->repo->idarraydata + s->provides;
288 while ((id = *pp++) != ID_NULL)
292 Reldep *rd = GETRELDEP(pool, id);
295 whatprovides[id]++; /* inc count of providers */
299 off = 2; /* first entry is undef, second is empty list */
301 np = 0; /* number of names provided */
302 for (i = 0; i < num; i++, idp++)
305 if (!n) /* no providers */
307 *idp = off; /* move from counts to offsets into whatprovidesdata */
308 off += n + 1; /* make space for all providers + terminating ID_NULL */
309 np++; /* inc # of provider 'slots' */
312 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
314 /* reserve some space for relation data */
315 extra = 2 * pool->nrels;
319 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
321 /* alloc space for all providers + extra */
322 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
324 /* now fill data for all provides */
325 for (i = 1; i < pool->nsolvables; i++)
328 s = pool->solvables + i;
331 if (s->repo != installed && !pool_installable(pool, s))
334 /* for all provides of this solvable */
335 pp = s->repo->idarraydata + s->provides;
336 while ((id = *pp++) != 0)
340 Reldep *rd = GETRELDEP(pool, id);
343 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
347 while (*d) /* find free slot */
349 if (d[-1] == i) /* solvable already tacked at end ? */
350 continue; /* Y: skip, on to next provides */
352 *d = i; /* put solvable Id into data */
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 /* check if a package's nevr matches a dependency */
425 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
427 Reldep *rd = GETRELDEP(pool, d);
430 int flags = rd->flags;
439 return pool_match_nevr(pool, s, name);
441 if (pool_match_nevr(pool, s, name))
443 return pool_match_nevr(pool, s, evr);
446 if (!pool_match_nevr(pool, s, name))
448 return pool_match_nevr(pool, s, evr);
453 if (!pool_match_nevr(pool, s, name))
456 return flags & 2 ? 1 : 0;
461 if (flags != 2 && flags != 5)
463 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
471 * add packages fulfilling the relation to whatprovides array
472 * no exact providers, do range match
477 pool_addrelproviders(Pool *pool, Id d)
479 Reldep *rd = GETRELDEP(pool, d);
485 int flags = rd->flags;
487 Id p, wp, *pp, *pp2, *pp3;
490 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
495 pp = pool_whatprovides_ptr(pool, name);
496 pp2 = pool_whatprovides_ptr(pool, evr);
497 while ((p = *pp++) != 0)
499 for (pp3 = pp2; *pp3;)
502 queue_push(&plist, p);
508 pp = pool_whatprovides_ptr(pool, name);
509 while ((p = *pp++) != 0)
510 queue_push(&plist, p);
511 pp = pool_whatprovides_ptr(pool, evr);
512 while ((p = *pp++) != 0)
513 queue_pushunique(&plist, p);
516 if (name == NAMESPACE_OTHERPROVIDERS)
518 wp = pool_whatprovides(pool, evr);
519 pool->whatprovides_rel[d] = wp;
522 if (pool->nscallback)
524 /* ask callback which packages provide the dependency
526 * 1: the system (aka SYSTEMSOLVABLE)
527 * >1: a set of packages, stored as offset on whatprovidesdata
529 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
533 pool->whatprovides_rel[d] = p;
537 queue_push(&plist, SYSTEMSOLVABLE);
541 /* small hack: make it possible to match <pkg>.src
542 * we have to iterate over the solvables as src packages do not
543 * provide anything, thus they are not indexed in our
544 * whatprovides hash */
548 for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
550 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
552 if (pool_match_nevr(pool, s, name))
553 queue_push(&plist, p);
557 wp = pool_whatprovides(pool, name);
558 pp = pool->whatprovidesdata + wp;
559 while ((p = *pp++) != 0)
561 Solvable *s = pool->solvables + p;
563 queue_push(&plist, p);
569 pool->whatprovides_rel[d] = wp;
577 /* convert to whatprovides id */
579 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
581 if (flags && flags < 8)
583 pp = pool_whatprovides_ptr(pool, name);
584 while (ISRELDEP(name))
586 rd = GETRELDEP(pool, name);
589 while ((p = *pp++) != 0)
591 Solvable *s = pool->solvables + p;
593 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
597 /* no provides - check nevr */
598 if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
599 queue_push(&plist, p);
602 /* solvable p provides name in some rels */
603 pidp = s->repo->idarraydata + s->provides;
604 while ((pid = *pidp++) != 0)
611 #ifdef DEBIAN_SEMANTICS
612 continue; /* unversioned provides can
613 * never match versioned deps */
615 break; /* yes, provides all versions */
619 continue; /* wrong provides name */
620 prd = GETRELDEP(pool, pid);
621 if (prd->name != name)
622 continue; /* wrong provides name */
623 /* right package, both deps are rels */
627 if (flags == 7 || pflags == 7)
628 break; /* included */
629 if ((pflags & flags & 5) != 0)
630 break; /* same direction, match */
634 if ((pflags & flags & 2) != 0)
635 break; /* both have =, match */
639 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
640 #ifdef DEBIAN_SEMANTICS
641 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_COMPARE)))) != 0)
644 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
650 continue; /* no rel match */
651 queue_push(&plist, p);
653 /* make our system solvable provide all unknown rpmlib() stuff */
654 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
655 queue_push(&plist, SYSTEMSOLVABLE);
657 /* add providers to whatprovides */
659 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
661 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
664 return pool->whatprovides_rel[d];
667 /*************************************************************************/
670 pool_debug(Pool *pool, int type, const char *format, ...)
675 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
677 if ((pool->debugmask & type) == 0)
680 va_start(args, format);
681 if (!pool->debugcallback)
683 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
684 vprintf(format, args);
686 vfprintf(stderr, format, args);
689 vsnprintf(buf, sizeof(buf), format, args);
690 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
694 pool_setdebuglevel(Pool *pool, int level)
696 int mask = SAT_DEBUG_RESULT;
698 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
700 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
702 mask |= SAT_DEBUG_PROPAGATE;
704 mask |= SAT_DEBUG_RULE_CREATION;
706 mask |= SAT_DEBUG_SCHUBI;
707 pool->debugmask = mask;
710 /*************************************************************************/
720 #define SEARCHFILES_BLOCK 127
723 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
727 struct searchfiles *csf;
729 while ((dep = *ida++) != 0)
732 while (ISRELDEP(dep))
735 sid = pool->ss.nstrings + GETRELID(dep);
736 if (MAPTST(&csf->seen, sid))
741 MAPSET(&csf->seen, sid);
742 rd = GETRELDEP(pool, dep);
745 else if (rd->flags == REL_NAMESPACE)
747 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
750 if (!csf || MAPTST(&csf->seen, sid))
755 MAPSET(&csf->seen, sid);
764 pool_addfileprovides_dep(pool, ids, csf, isf);
770 if (MAPTST(&csf->seen, dep))
772 MAPSET(&csf->seen, dep);
773 s = id2str(pool, dep);
776 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
777 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
778 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
779 csf->ids[csf->nfiles] = dep;
780 sr = strrchr(s, '/');
781 csf->names[csf->nfiles] = strdup(sr + 1);
782 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
784 strncpy(csf->dirs[csf->nfiles], s, sr - s);
785 csf->dirs[csf->nfiles][sr - s] = 0;
790 struct addfileprovides_cbdata {
802 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
804 struct addfileprovides_cbdata *cbd = cbdata;
807 if (data != cbd->olddata)
809 map_free(&cbd->useddirs);
810 map_init(&cbd->useddirs, data->dirpool.ndirs);
811 for (i = 0; i < cbd->nfiles; i++)
813 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
816 MAPSET(&cbd->useddirs, did);
820 if (!MAPTST(&cbd->useddirs, value->id))
822 for (i = 0; i < cbd->nfiles; i++)
824 if (cbd->dids[i] != value->id)
826 if (!strcmp(cbd->names[i], value->str))
829 if (i == cbd->nfiles)
831 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
836 addfileprovides_setid_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv)
838 Map *provideids = cbdata;
839 if (key->type != REPOKEY_TYPE_IDARRAY)
841 MAPSET(provideids, kv->id);
842 return kv->eof ? SEARCH_NEXT_SOLVABLE : 0;
847 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
851 Repodata *data = 0, *nextdata;
853 int dataincludes = 0;
857 cbd->nfiles = sf->nfiles;
859 cbd->dirs = sf->dirs;
860 cbd->names = sf->names;
862 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
865 start = repoonly->start;
870 start = 2; /* skip system solvable */
871 end = pool->nsolvables;
873 for (p = start, s = pool->solvables + p; p < end; p++, s++)
875 if (!s->repo || (repoonly && s->repo != repoonly))
877 /* check if p is in (oldrepo,data) */
878 if (s->repo != oldrepo || (data && p >= data->end))
885 /* nope, find new repo/repodata */
886 /* if we don't find a match, set data to the next repodata */
888 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
892 if (data->state != REPODATA_AVAILABLE)
894 for (j = 1; j < data->nkeys; j++)
895 if (data->keys[j].name == REPOSITORY_ADDEDFILEPROVIDES && data->keys[j].type == REPOKEY_TYPE_IDARRAY)
897 if (j == data->nkeys)
899 /* great, this repodata contains addedfileprovides */
900 if (!nextdata || nextdata->start > data->start)
902 if (p >= data->start)
905 if (i == s->repo->nrepodata)
906 data = nextdata; /* no direct hit, use next repodata */
909 map_init(&providedids, pool->ss.nstrings);
910 repodata_search(data, SOLVID_META, REPOSITORY_ADDEDFILEPROVIDES, 0, addfileprovides_setid_cb, &providedids);
911 for (i = 0; i < cbd->nfiles; i++)
912 if (!MAPTST(&providedids, cbd->ids[i]))
914 map_free(&providedids);
915 dataincludes = i == cbd->nfiles;
919 if (data && p >= data->start && dataincludes)
921 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
926 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
930 struct searchfiles sf, isf, *isfp;
931 struct addfileprovides_cbdata cbd;
934 memset(&sf, 0, sizeof(sf));
935 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
936 memset(&isf, 0, sizeof(isf));
937 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
939 isfp = installed ? &isf : 0;
940 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
946 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
948 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
950 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
952 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
954 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
956 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
958 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
962 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
963 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
965 map_init(&cbd.useddirs, 1);
971 for (i = 0; i < sf.nfiles; i++)
972 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
974 pool_addfileprovides_search(pool, &cbd, &sf, 0);
977 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
978 sf.ids[sf.nfiles] = 0;
983 for (i = 0; i < sf.nfiles; i++)
985 sat_free(sf.dirs[i]);
986 sat_free(sf.names[i]);
994 for (i = 0; i < isf.nfiles; i++)
995 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
998 pool_addfileprovides_search(pool, &cbd, &isf, installed);
1000 for (i = 0; i < isf.nfiles; i++)
1002 sat_free(isf.dirs[i]);
1003 sat_free(isf.names[i]);
1006 sat_free(isf.names);
1008 map_free(&cbd.useddirs);
1010 pool_freewhatprovides(pool); /* as we have added provides */
1014 pool_addfileprovides(Pool *pool)
1016 pool_addfileprovides_ids(pool, pool->installed, 0);
1020 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)
1024 if (pool->solvables[p].repo)
1025 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1028 /* FIXME: obey callback return value! */
1029 for (p = 1; p < pool->nsolvables; p++)
1030 if (pool->solvables[p].repo)
1031 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
1035 pool_clear_pos(Pool *pool)
1037 memset(&pool->pos, 0, sizeof(pool->pos));
1042 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
1046 pool->languagecache = sat_free(pool->languagecache);
1047 pool->languagecacheother = 0;
1048 if (pool->nlanguages)
1050 for (i = 0; i < pool->nlanguages; i++)
1051 free((char *)pool->languages[i]);
1052 free(pool->languages);
1054 pool->nlanguages = nlanguages;
1057 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
1058 for (i = 0; i < pool->nlanguages; i++)
1059 pool->languages[i] = strdup(languages[i]);
1063 pool_id2langid(Pool *pool, Id id, const char *lang, int create)
1071 n = id2str(pool, id);
1072 l = strlen(n) + strlen(lang) + 2;
1073 if (l > sizeof(buf))
1074 p = sat_malloc(strlen(n) + strlen(lang) + 2);
1077 sprintf(p, "%s:%s", n, lang);
1078 id = str2id(pool, p, create);
1085 pool_alloctmpspace(Pool *pool, int len)
1087 int n = pool->tmpspacen;
1090 if (len > pool->tmpspacelen[n])
1092 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
1093 pool->tmpspacelen[n] = len + 32;
1095 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
1096 return pool->tmpspacebuf[n];
1099 /*******************************************************************/
1111 struct mptree *mptree;
1122 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1124 struct ducbdata *cbd = cbdata;
1127 if (data != cbd->olddata)
1129 Id dn, mp, comp, *dirmap, *dirs;
1131 const char *compstr;
1132 struct mptree *mptree;
1134 /* create map from dir to mptree */
1135 cbd->dirmap = sat_free(cbd->dirmap);
1137 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1138 mptree = cbd->mptree;
1140 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1154 if (!mptree[mp].child)
1159 if (data->localpool)
1160 compstr = stringpool_id2str(&data->spool, comp);
1162 compstr = id2str(data->repo->pool, comp);
1163 compl = strlen(compstr);
1164 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1165 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1167 dirmap[dn] = i ? i : -mp;
1169 /* change dirmap to point to mountpoint instead of mptree */
1170 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1173 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1175 cbd->dirmap = dirmap;
1176 cbd->nmap = data->dirpool.ndirs;
1177 cbd->olddata = data;
1180 if (value->id < 0 || value->id >= cbd->nmap)
1182 mp = cbd->dirmap[value->id];
1185 if (cbd->addsub > 0)
1187 cbd->mps[mp].kbytes += value->num;
1188 cbd->mps[mp].files += value->num2;
1192 cbd->mps[mp].kbytes -= value->num;
1193 cbd->mps[mp].files -= value->num2;
1199 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1202 if (mptree[pos].mountpoint == -1)
1203 mptree[pos].mountpoint = mountpoint;
1205 mountpoint = mptree[pos].mountpoint;
1206 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1207 propagate_mountpoints(mptree, i, mountpoint);
1210 #define MPTREE_BLOCK 15
1213 pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps)
1216 const char *path, *compstr;
1217 struct mptree *mptree;
1221 struct ducbdata cbd;
1225 Repo *oldinstalled = pool->installed;
1227 memset(&ignoredu, 0, sizeof(ignoredu));
1234 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1237 mptree[0].sibling = 0;
1238 mptree[0].child = 0;
1240 mptree[0].compl = 0;
1241 mptree[0].mountpoint = -1;
1244 /* create component tree */
1245 for (mp = 0; mp < nmps; mp++)
1250 path = mps[mp].path;
1255 if ((p = strchr(path, '/')) == 0)
1258 compl = strlen(compstr);
1269 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1270 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1274 /* create new node */
1275 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1277 mptree[i].sibling = mptree[pos].child;
1278 mptree[i].child = 0;
1279 mptree[i].comp = compstr;
1280 mptree[i].compl = compl;
1281 mptree[i].mountpoint = -1;
1282 mptree[pos].child = i;
1286 mptree[pos].mountpoint = mp;
1289 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1292 for (i = 0; i < nmptree; i++)
1294 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1295 printf("#%d child: %d\n", i, mptree[i].child);
1296 printf("#%d comp: %s\n", i, mptree[i].comp);
1297 printf("#%d compl: %d\n", i, mptree[i].compl);
1298 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1302 cbd.mptree = mptree;
1304 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1306 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1308 if (!MAPTST(installedmap, sp))
1311 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1312 if (!cbd.hasdu && oldinstalled)
1315 /* no du data available, ignore data of all installed solvables we obsolete */
1317 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1320 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1321 while ((obs = *obsp++) != 0)
1322 FOR_PROVIDES(op, opp, obs)
1323 if (op >= oldinstalled->start && op < oldinstalled->end)
1324 MAPSET(&ignoredu, op - oldinstalled->start);
1326 FOR_PROVIDES(op, opp, s->name)
1327 if (pool->solvables[op].name == s->name)
1328 if (op >= oldinstalled->start && op < oldinstalled->end)
1329 MAPSET(&ignoredu, op - oldinstalled->start);
1335 /* assumes we allways have du data for installed solvables */
1336 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1338 if (MAPTST(installedmap, sp))
1340 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1342 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1346 map_free(&ignoredu);
1347 sat_free(cbd.dirmap);
1352 pool_calc_installsizechange(Pool *pool, Map *installedmap)
1357 Repo *oldinstalled = pool->installed;
1359 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1361 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1363 if (!MAPTST(installedmap, sp))
1365 change += solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1369 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1371 if (MAPTST(installedmap, sp))
1373 change -= solvable_lookup_num(s, SOLVABLE_INSTALLSIZE, 0);
1381 * 2: conflicts with installed
1382 * 8: interesting (only true if installed)
1386 static inline Id dep2name(Pool *pool, Id dep)
1388 while (ISRELDEP(dep))
1390 Reldep *rd = rd = GETRELDEP(pool, dep);
1396 static int providedbyinstalled_multiversion(Pool *pool, unsigned char *map, Id n, Id dep)
1399 Solvable *sn = pool->solvables + n;
1401 FOR_PROVIDES(p, pp, sn->name)
1403 Solvable *s = pool->solvables + p;
1404 if (s->name != sn->name || s->arch != sn->arch)
1406 if ((map[p] & 9) == 9)
1412 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep, int ispatch, Map *noobsoletesmap)
1416 FOR_PROVIDES(p, pp, dep)
1418 if (p == SYSTEMSOLVABLE)
1419 return 1; /* always boring, as never constraining */
1420 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
1422 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
1423 if (providedbyinstalled_multiversion(pool, map, p, dep))
1425 if ((map[p] & 9) == 9)
1433 * pool_trivial_installable - calculate if a set of solvables is
1434 * trivial installable without any other installs/deinstalls of
1435 * packages not belonging to the set.
1437 * the state is returned in the result queue:
1438 * 1: solvable is installable without any other package changes
1439 * 0: solvable is not installable
1440 * -1: solvable is installable, but doesn't constrain any installed packages
1444 pool_trivial_installable_noobsoletesmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *noobsoletesmap)
1447 Id p, *dp, con, *conp, req, *reqp;
1451 map = sat_calloc(pool->nsolvables, 1);
1452 for (p = 1; p < pool->nsolvables; p++)
1454 if (!MAPTST(installedmap, p))
1457 s = pool->solvables + p;
1460 conp = s->repo->idarraydata + s->conflicts;
1461 while ((con = *conp++) != 0)
1463 dp = pool_whatprovides_ptr(pool, con);
1465 map[p] |= 2; /* XXX: self conflict ? */
1468 for (i = 0; i < pkgs->count; i++)
1469 map[pkgs->elements[i]] = 16;
1471 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1473 if (i == pkgs->count)
1475 p = pkgs->elements[i];
1476 if ((map[p] & 16) == 0)
1478 if ((map[p] & 2) != 0)
1483 s = pool->solvables + p;
1487 reqp = s->repo->idarraydata + s->requires;
1488 while ((req = *reqp++) != 0)
1490 if (req == SOLVABLE_PREREQMARKER)
1492 r = providedbyinstalled(pool, map, req, 0, 0);
1495 /* decided and miss */
1499 m |= r; /* 1 | 9 | 16 | 17 */
1508 int ispatch = 0; /* see solver.c patch handling */
1510 if (!strncmp("patch:", id2str(pool, s->name), 6))
1512 conp = s->repo->idarraydata + s->conflicts;
1513 while ((con = *conp++) != 0)
1515 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1520 if ((m == 1 || m == 17) && ISRELDEP(con))
1522 con = dep2name(pool, con);
1523 if ((providedbyinstalled(pool, map, con, ispatch, noobsoletesmap) & 1) != 0)
1528 continue; /* found a conflict */
1531 if (s->repo && s->repo != oldinstalled)
1533 Id p2, obs, *obsp, *pp;
1537 obsp = s->repo->idarraydata + s->obsoletes;
1538 while ((obs = *obsp++) != 0)
1540 if ((providedbyinstalled(pool, map, obs, 0, 0) & 1) != 0)
1549 FOR_PROVIDES(p2, pp, s->name)
1551 s2 = pool->solvables + p2;
1552 if (s2->name == s->name && (map[p2] & 1) != 0)
1569 queue_clone(res, pkgs);
1570 for (i = 0; i < pkgs->count; i++)
1572 m = map[pkgs->elements[i]];
1579 res->elements[i] = r;
1585 pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res)
1587 pool_trivial_installable_noobsoletesmap(pool, installedmap, pkgs, res, 0);