2 * Copyright (c) 2007, 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 sat_free(pool->ss.stringspace);
80 sat_free(pool->ss.strings);
82 queue_free(&pool->vendormap);
83 for (i = 0; i < POOL_TMPSPACEBUF; i++)
84 sat_free(pool->tmpspacebuf[i]);
85 for (i = 0; i < pool->nlanguages; i++)
86 free((char *)pool->languages[i]);
87 sat_free(pool->languages);
88 sat_free(pool->languagecache);
93 pool_add_solvable(Pool *pool)
95 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, 1, sizeof(Solvable), SOLVABLE_BLOCK);
96 memset(pool->solvables + pool->nsolvables, 0, sizeof(Solvable));
97 return pool->nsolvables++;
101 pool_add_solvable_block(Pool *pool, int count)
103 Id nsolvables = pool->nsolvables;
106 pool->solvables = sat_extend(pool->solvables, pool->nsolvables, count, sizeof(Solvable), SOLVABLE_BLOCK);
107 memset(pool->solvables + nsolvables, 0, sizeof(Solvable) * count);
108 pool->nsolvables += count;
113 pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids)
117 if (reuseids && start + count == pool->nsolvables)
119 /* might want to shrink solvable array */
120 pool->nsolvables = start;
123 memset(pool->solvables + start, 0, sizeof(Solvable) * count);
127 static Pool *pool_shrink_whatprovides_sortcmp_data;
130 pool_shrink_whatprovides_sortcmp(const void *ap, const void *bp)
133 Pool *pool = pool_shrink_whatprovides_sortcmp_data;
135 oa = pool->whatprovides[*(Id *)ap];
136 ob = pool->whatprovides[*(Id *)bp];
138 return *(Id *)ap - *(Id *)bp;
143 da = pool->whatprovidesdata + oa;
144 db = pool->whatprovidesdata + ob;
146 if ((r = (*da++ - *db++)) != 0)
150 return *(Id *)ap - *(Id *)bp;
154 * pool_shrink_whatprovides - unify whatprovides data
156 * whatprovides_rel must be empty for this to work!
160 pool_shrink_whatprovides(Pool *pool)
164 Id lastid, *last, *dp, *lp;
168 if (pool->ss.nstrings < 3)
170 sorted = sat_malloc2(pool->ss.nstrings, sizeof(Id));
171 for (id = 0; id < pool->ss.nstrings; id++)
173 pool_shrink_whatprovides_sortcmp_data = pool;
174 qsort(sorted + 1, pool->ss.nstrings - 1, sizeof(Id), pool_shrink_whatprovides_sortcmp);
177 for (i = 1; i < pool->ss.nstrings; i++)
180 o = pool->whatprovides[id];
181 if (o == 0 || o == 1)
183 dp = pool->whatprovidesdata + o;
197 pool->whatprovides[id] = -lastid;
201 last = pool->whatprovidesdata + o;
205 dp = pool->whatprovidesdata + 2;
206 for (id = 1; id < pool->ss.nstrings; id++)
208 o = pool->whatprovides[id];
209 if (o == 0 || o == 1)
216 pool->whatprovides[id] = pool->whatprovides[i];
219 lp = pool->whatprovidesdata + o;
222 pool->whatprovides[id] = dp - pool->whatprovidesdata;
223 while ((*dp++ = *lp++) != 0)
226 o = dp - pool->whatprovidesdata;
227 POOL_DEBUG(SAT_DEBUG_STATS, "shrunk whatprovidesdata from %d to %d\n", pool->whatprovidesdataoff, o);
228 if (pool->whatprovidesdataoff == o)
230 r = pool->whatprovidesdataoff - o;
231 pool->whatprovidesdataoff = o;
232 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (o + pool->whatprovidesdataleft) * sizeof(Id));
233 if (r > pool->whatprovidesdataleft)
234 r = pool->whatprovidesdataleft;
235 memset(pool->whatprovidesdata + o, 0, r * sizeof(Id));
240 * pool_createwhatprovides()
242 * create hashes over pool of solvables to ease provide lookups
246 pool_createwhatprovides(Pool *pool)
248 int i, num, np, extra;
253 Offset *whatprovides;
254 Id *whatprovidesdata, *d;
256 POOL_DEBUG(SAT_DEBUG_STATS, "number of solvables: %d\n", pool->nsolvables);
257 POOL_DEBUG(SAT_DEBUG_STATS, "number of ids: %d + %d\n", pool->ss.nstrings, pool->nrels);
259 pool_freeidhashes(pool); /* XXX: should not be here! */
260 pool_freewhatprovides(pool);
261 num = pool->ss.nstrings;
262 pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
263 pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
265 /* count providers for each name */
266 for (i = 1; i < pool->nsolvables; i++)
269 s = pool->solvables + i;
272 if (!pool_installable(pool, s))
274 pp = s->repo->idarraydata + s->provides;
275 while ((id = *pp++) != ID_NULL)
279 Reldep *rd = GETRELDEP(pool, id);
282 whatprovides[id]++; /* inc count of providers */
286 off = 2; /* first entry is undef, second is empty list */
288 np = 0; /* number of names provided */
289 for (i = 0; i < num; i++, idp++)
292 if (!n) /* no providers */
294 *idp = off; /* move from counts to offsets into whatprovidesdata */
295 off += n + 1; /* make space for all providers + terminating ID_NULL */
296 np++; /* inc # of provider 'slots' */
299 POOL_DEBUG(SAT_DEBUG_STATS, "provide ids: %d\n", np);
301 /* reserve some space for relation data */
302 extra = 2 * pool->nrels;
306 POOL_DEBUG(SAT_DEBUG_STATS, "provide space needed: %d + %d\n", off, extra);
308 /* alloc space for all providers + extra */
309 whatprovidesdata = sat_calloc(off + extra, sizeof(Id));
311 /* now fill data for all provides */
312 for (i = 1; i < pool->nsolvables; i++)
315 s = pool->solvables + i;
318 if (!pool_installable(pool, s))
321 /* for all provides of this solvable */
322 pp = s->repo->idarraydata + s->provides;
323 while ((id = *pp++) != 0)
327 Reldep *rd = GETRELDEP(pool, id);
330 d = whatprovidesdata + whatprovides[id]; /* offset into whatprovidesdata */
334 while (*d) /* find free slot */
336 if (d[-1] == i) /* solvable already tacked at end ? */
337 continue; /* Y: skip, on to next provides */
339 *d = i; /* put solvable Id into data */
342 pool->whatprovidesdata = whatprovidesdata;
343 pool->whatprovidesdataoff = off;
344 pool->whatprovidesdataleft = extra;
345 pool_shrink_whatprovides(pool);
349 * free all of our whatprovides data
350 * be careful, everything internalized with pool_queuetowhatprovides is gone, too
353 pool_freewhatprovides(Pool *pool)
355 pool->whatprovides = sat_free(pool->whatprovides);
356 pool->whatprovides_rel = sat_free(pool->whatprovides_rel);
357 pool->whatprovidesdata = sat_free(pool->whatprovidesdata);
358 pool->whatprovidesdataoff = 0;
359 pool->whatprovidesdataleft = 0;
363 /******************************************************************************/
366 * pool_queuetowhatprovides - add queue contents to whatprovidesdata
368 * on-demand filling of provider information
369 * move queue data into whatprovidesdata
371 * returns: Offset into whatprovides
375 pool_queuetowhatprovides(Pool *pool, Queue *q)
378 int count = q->count;
380 if (count == 0) /* queue empty -> ID_EMPTY */
383 /* extend whatprovidesdata if needed, +1 for ID_NULL-termination */
384 if (pool->whatprovidesdataleft < count + 1)
386 POOL_DEBUG(SAT_DEBUG_STATS, "growing provides hash data...\n");
387 pool->whatprovidesdata = sat_realloc(pool->whatprovidesdata, (pool->whatprovidesdataoff + count + 4096) * sizeof(Id));
388 pool->whatprovidesdataleft = count + 4096;
391 /* copy queue to next free slot */
392 off = pool->whatprovidesdataoff;
393 memcpy(pool->whatprovidesdata + pool->whatprovidesdataoff, q->elements, count * sizeof(Id));
395 /* adapt count and ID_NULL-terminate */
396 pool->whatprovidesdataoff += count;
397 pool->whatprovidesdata[pool->whatprovidesdataoff++] = ID_NULL;
398 pool->whatprovidesdataleft -= count + 1;
404 /*************************************************************************/
406 /* check if a package's nevr matches a dependency */
409 pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
411 Reldep *rd = GETRELDEP(pool, d);
414 int flags = rd->flags;
423 return pool_match_nevr(pool, s, name);
425 if (pool_match_nevr(pool, s, name))
427 return pool_match_nevr(pool, s, evr);
430 if (!pool_match_nevr(pool, s, name))
432 return pool_match_nevr(pool, s, evr);
437 if (!pool_match_nevr(pool, s, name))
440 return flags & 2 ? 1 : 0;
445 if (flags != 2 && flags != 5)
447 if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
455 * add packages fulfilling the relation to whatprovides array
456 * no exact providers, do range match
461 pool_addrelproviders(Pool *pool, Id d)
463 Reldep *rd = GETRELDEP(pool, d);
469 int flags = rd->flags;
471 Id p, *pp, *pp2, *pp3;
474 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
479 pp = pool_whatprovides(pool, name);
480 pp2 = pool_whatprovides(pool, evr);
481 while ((p = *pp++) != 0)
483 for (pp3 = pp2; *pp3;)
486 queue_push(&plist, p);
492 pp = pool_whatprovides(pool, name);
493 while ((p = *pp++) != 0)
494 queue_push(&plist, p);
495 pp = pool_whatprovides(pool, evr);
496 while ((p = *pp++) != 0)
497 queue_pushunique(&plist, p);
500 if (pool->nscallback)
502 /* ask callback which packages provide the dependency
504 * 1: the system (aka SYSTEMSOLVABLE)
505 * >1: a set of packages, stored as offset on whatprovidesdata
507 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
511 pool->whatprovides_rel[d] = p;
512 return pool->whatprovidesdata + p;
515 queue_push(&plist, SYSTEMSOLVABLE);
519 pp = pp2 = pool_whatprovides(pool, name);
520 while ((p = *pp++) != 0)
522 Solvable *s = pool->solvables + p;
524 queue_push(&plist, p);
535 /* convert to whatprovides id */
537 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
539 if (flags && flags < 8)
541 pp = pool_whatprovides(pool, name);
542 while (ISRELDEP(name))
544 rd = GETRELDEP(pool, name);
547 while ((p = *pp++) != 0)
550 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, pool->p[p].name));
552 /* solvable p provides name in some rels */
553 pidp = pool->solvables[p].repo->idarraydata + pool->solvables[p].provides;
554 while ((pid = *pidp++) != 0)
561 #ifdef DEBIAN_SEMANTICS
562 continue; /* unversioned provides can
563 * never match versioned deps */
565 break; /* yes, provides all versions */
569 continue; /* wrong provides name */
570 prd = GETRELDEP(pool, pid);
571 if (prd->name != name)
572 continue; /* wrong provides name */
573 /* right package, both deps are rels */
577 if (flags == 7 || pflags == 7)
578 break; /* included */
579 if ((pflags & flags & 5) != 0)
580 break; /* same direction, match */
584 if ((pflags & flags & 2) != 0)
585 break; /* both have =, match */
589 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
590 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
595 continue; /* no rel match */
596 queue_push(&plist, p);
598 /* make our system solvable provide all unknown rpmlib() stuff */
599 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
600 queue_push(&plist, SYSTEMSOLVABLE);
602 /* add providers to whatprovides */
604 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
606 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
609 return pool->whatprovidesdata + pool->whatprovides_rel[d];
612 /*************************************************************************/
615 pool_debug(Pool *pool, int type, const char *format, ...)
620 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
622 if ((pool->debugmask & type) == 0)
625 va_start(args, format);
626 if (!pool->debugcallback)
628 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
629 vprintf(format, args);
631 vfprintf(stderr, format, args);
634 vsnprintf(buf, sizeof(buf), format, args);
635 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
639 pool_setdebuglevel(Pool *pool, int level)
641 int mask = SAT_DEBUG_RESULT;
643 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
645 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
647 mask |= SAT_DEBUG_PROPAGATE;
649 mask |= SAT_DEBUG_RULE_CREATION;
651 mask |= SAT_DEBUG_SCHUBI;
652 pool->debugmask = mask;
655 /*************************************************************************/
665 #define SEARCHFILES_BLOCK 127
668 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
672 struct searchfiles *csf;
674 while ((dep = *ida++) != 0)
677 while (ISRELDEP(dep))
680 sid = pool->ss.nstrings + GETRELID(dep);
681 if (MAPTST(&csf->seen, sid))
686 MAPSET(&csf->seen, sid);
687 rd = GETRELDEP(pool, dep);
690 else if (rd->flags == REL_NAMESPACE)
692 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
695 if (!csf || MAPTST(&csf->seen, sid))
700 MAPSET(&csf->seen, sid);
709 pool_addfileprovides_dep(pool, ids, csf, isf);
715 if (MAPTST(&csf->seen, dep))
717 MAPSET(&csf->seen, dep);
718 s = id2str(pool, dep);
721 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
722 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
723 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
724 csf->ids[csf->nfiles] = dep;
725 sr = strrchr(s, '/');
726 csf->names[csf->nfiles] = strdup(sr + 1);
727 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
729 strncpy(csf->dirs[csf->nfiles], s, sr - s);
730 csf->dirs[csf->nfiles][sr - s] = 0;
735 struct addfileprovides_cbdata {
747 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
749 struct addfileprovides_cbdata *cbd = cbdata;
752 if (data != cbd->olddata)
754 map_free(&cbd->useddirs);
755 map_init(&cbd->useddirs, data->dirpool.ndirs);
756 for (i = 0; i < cbd->nfiles; i++)
758 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
761 MAPSET(&cbd->useddirs, did);
765 if (!MAPTST(&cbd->useddirs, value->id))
767 for (i = 0; i < cbd->nfiles; i++)
769 if (cbd->dids[i] != value->id)
771 if (!strcmp(cbd->names[i], value->str))
774 if (i == cbd->nfiles)
776 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
782 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
784 Id p, start, end, *idp;
786 Repodata *data = 0, *nextdata;
788 int dataincludes = 0;
792 cbd->nfiles = sf->nfiles;
794 cbd->dirs = sf->dirs;
795 cbd->names = sf->names;
797 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
800 start = repoonly->start;
805 start = 2; /* skip system solvable */
806 end = pool->nsolvables;
808 for (p = start, s = pool->solvables + p; p < end; p++, s++)
810 if (!s->repo || (repoonly && s->repo != repoonly))
812 if (s->repo != oldrepo || (data && p >= data->end))
820 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
822 if (!data->addedfileprovides || p >= data->end)
824 if (!nextdata || nextdata->start > data->start)
826 if (p >= data->start)
829 if (i == s->repo->nrepodata)
833 map_init(&providedids, pool->ss.nstrings);
834 for (idp = data->addedfileprovides; *idp; idp++)
835 MAPSET(&providedids, *idp);
836 for (i = 0; i < cbd->nfiles; i++)
837 if (!MAPTST(&providedids, cbd->ids[i]))
841 map_free(&providedids);
842 dataincludes = i == cbd->nfiles;
846 if (data && p >= data->start && dataincludes)
848 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
853 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
857 struct searchfiles sf, isf, *isfp;
858 struct addfileprovides_cbdata cbd;
861 memset(&sf, 0, sizeof(sf));
862 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
863 memset(&isf, 0, sizeof(isf));
864 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
866 isfp = installed ? &isf : 0;
867 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
873 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
875 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
877 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
879 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
881 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
883 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
885 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
887 pool_addfileprovides_dep(pool, repo->idarraydata + s->freshens, &sf, isfp);
891 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
892 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
894 map_init(&cbd.useddirs, 1);
900 for (i = 0; i < sf.nfiles; i++)
901 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
903 pool_addfileprovides_search(pool, &cbd, &sf, 0);
906 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
907 sf.ids[sf.nfiles] = 0;
912 for (i = 0; i < sf.nfiles; i++)
914 sat_free(sf.dirs[i]);
915 sat_free(sf.names[i]);
923 for (i = 0; i < isf.nfiles; i++)
924 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
927 pool_addfileprovides_search(pool, &cbd, &isf, installed);
929 for (i = 0; i < isf.nfiles; i++)
931 sat_free(isf.dirs[i]);
932 sat_free(isf.names[i]);
937 map_free(&cbd.useddirs);
939 pool_freewhatprovides(pool); /* as we have added provides */
943 pool_addfileprovides(Pool *pool, Repo *installed)
945 pool_addfileprovides_ids(pool, installed, 0);
949 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)
953 if (pool->solvables[p].repo)
954 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
957 /* FIXME: obey callback return value! */
958 for (p = 1; p < pool->nsolvables; p++)
959 if (pool->solvables[p].repo)
960 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
965 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
969 pool->languagecache = sat_free(pool->languagecache);
970 pool->languagecacheother = 0;
971 if (pool->nlanguages)
973 for (i = 0; i < pool->nlanguages; i++)
974 free((char *)pool->languages[i]);
975 free(pool->languages);
977 pool->nlanguages = nlanguages;
980 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
981 for (i = 0; i < pool->nlanguages; i++)
982 pool->languages[i] = strdup(languages[i]);
986 pool_alloctmpspace(Pool *pool, int len)
988 int n = pool->tmpspacen;
991 if (len > pool->tmpspacelen[n])
993 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
994 pool->tmpspacelen[n] = len + 32;
996 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
997 return pool->tmpspacebuf[n];
1000 /*******************************************************************/
1012 struct mptree *mptree;
1023 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
1025 struct ducbdata *cbd = cbdata;
1028 if (data != cbd->olddata)
1030 Id dn, mp, comp, *dirmap, *dirs;
1032 const char *compstr;
1033 struct mptree *mptree;
1035 /* create map from dir to mptree */
1036 cbd->dirmap = sat_free(cbd->dirmap);
1038 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
1039 mptree = cbd->mptree;
1041 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1055 if (!mptree[mp].child)
1060 if (data->localpool)
1061 compstr = stringpool_id2str(&data->spool, comp);
1063 compstr = id2str(data->repo->pool, comp);
1064 compl = strlen(compstr);
1065 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1066 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1068 dirmap[dn] = i ? i : -mp;
1070 /* change dirmap to point to mountpoint instead of mptree */
1071 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1074 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1076 cbd->dirmap = dirmap;
1077 cbd->nmap = data->dirpool.ndirs;
1078 cbd->olddata = data;
1081 if (value->id < 0 || value->id >= cbd->nmap)
1083 mp = cbd->dirmap[value->id];
1086 if (cbd->addsub > 0)
1088 cbd->mps[mp].kbytes += value->num;
1089 cbd->mps[mp].files += value->num2;
1093 cbd->mps[mp].kbytes -= value->num;
1094 cbd->mps[mp].files -= value->num2;
1100 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1103 if (mptree[pos].mountpoint == -1)
1104 mptree[pos].mountpoint = mountpoint;
1106 mountpoint = mptree[pos].mountpoint;
1107 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1108 propagate_mountpoints(mptree, i, mountpoint);
1111 #define MPTREE_BLOCK 15
1114 pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges *mps, int nmps)
1117 const char *path, *compstr;
1118 struct mptree *mptree;
1122 struct ducbdata cbd;
1127 memset(&ignoredu, 0, sizeof(ignoredu));
1134 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1137 mptree[0].sibling = 0;
1138 mptree[0].child = 0;
1140 mptree[0].compl = 0;
1141 mptree[0].mountpoint = -1;
1144 /* create component tree */
1145 for (mp = 0; mp < nmps; mp++)
1150 path = mps[mp].path;
1155 if ((p = strchr(path, '/')) == 0)
1158 compl = strlen(compstr);
1169 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1170 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1174 /* create new node */
1175 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1177 mptree[i].sibling = mptree[pos].child;
1178 mptree[i].child = 0;
1179 mptree[i].comp = compstr;
1180 mptree[i].compl = compl;
1181 mptree[i].mountpoint = -1;
1182 mptree[pos].child = i;
1186 mptree[pos].mountpoint = mp;
1189 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1192 for (i = 0; i < nmptree; i++)
1194 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1195 printf("#%d child: %d\n", i, mptree[i].child);
1196 printf("#%d comp: %s\n", i, mptree[i].comp);
1197 printf("#%d compl: %d\n", i, mptree[i].compl);
1198 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1202 cbd.mptree = mptree;
1204 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1206 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1208 if (!MAPTST(installedmap, sp))
1211 repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1212 if (!cbd.hasdu && oldinstalled)
1215 /* no du data available, ignore data of all installed solvables we obsolete */
1217 map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
1220 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
1221 while ((obs = *obsp++) != 0)
1222 FOR_PROVIDES(op, opp, obs)
1223 if (op >= oldinstalled->start && op < oldinstalled->end)
1224 MAPSET(&ignoredu, op - oldinstalled->start);
1226 FOR_PROVIDES(op, opp, s->name)
1227 if (pool->solvables[op].name == s->name)
1228 if (op >= oldinstalled->start && op < oldinstalled->end)
1229 MAPSET(&ignoredu, op - oldinstalled->start);
1235 /* assumes we allways have du data for installed solvables */
1236 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1238 if (MAPTST(installedmap, sp))
1240 if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
1242 repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1246 map_free(&ignoredu);
1247 sat_free(cbd.dirmap);
1252 pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
1258 for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
1260 if (!s->repo || (oldinstalled && s->repo == oldinstalled))
1262 if (!MAPTST(installedmap, sp))
1264 change += repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
1268 FOR_REPO_SOLVABLES(oldinstalled, sp, s)
1270 if (MAPTST(installedmap, sp))
1272 change -= repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
1280 * 2: conflicts with installed
1281 * 8: interesting (only true if installed)
1285 static inline Id dep2name(Pool *pool, Id dep)
1287 while (ISRELDEP(dep))
1289 Reldep *rd = rd = GETRELDEP(pool, dep);
1295 static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
1299 FOR_PROVIDES(p, pp, dep)
1301 if (p == SYSTEMSOLVABLE)
1302 return 1; /* always boring, as never constraining */
1303 if ((map[p] & 9) == 9)
1311 * pool_trivial_installable - calculate if a set of solvables is
1312 * trivial installable without any other installs/deinstalls of
1313 * packages not belonging to the set.
1315 * the state is returned in the result queue:
1316 * 1: solvable is installable without any other package changes
1317 * 0: solvable is not installable
1318 * -1: solvable is installable, but doesn't constrain any installed packages
1322 pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queue *pkgs, Queue *res)
1325 Id p, *dp, con, *conp, req, *reqp, obs, *obsp, *pp;
1329 map = sat_calloc(pool->nsolvables, 1);
1330 for (p = 0; p < pool->nsolvables; p++)
1332 if (!MAPTST(installedmap, p))
1335 s = pool->solvables + p;
1338 conp = s->repo->idarraydata + s->conflicts;
1339 while ((con = *conp++) != 0)
1341 dp = pool_whatprovides(pool, con);
1343 map[p] |= 2; /* XXX: self conflict ? */
1346 for (i = 0; i < pkgs->count; i++)
1347 map[pkgs->elements[i]] = 16;
1349 for (i = 0, did = 0; did < pkgs->count; i++, did++)
1351 if (i == pkgs->count)
1353 p = pkgs->elements[i];
1354 if ((map[p] & 16) == 0)
1356 if ((map[p] & 2) != 0)
1361 s = pool->solvables + p;
1365 reqp = s->repo->idarraydata + s->requires;
1366 while ((req = *reqp++) != 0)
1368 if (req == SOLVABLE_PREREQMARKER)
1370 r = providedbyinstalled(pool, map, req);
1373 /* decided and miss */
1377 m |= r; /* 1 | 9 | 16 | 17 */
1386 conp = s->repo->idarraydata + s->conflicts;
1387 while ((con = *conp++) != 0)
1389 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1394 if ((m == 1 || m == 17) && ISRELDEP(con))
1396 con = dep2name(pool, con);
1397 if ((providedbyinstalled(pool, map, con) & 1) != 0)
1402 continue; /* found a conflict */
1404 if (s->repo && s->repo != oldinstalled)
1410 obsp = s->repo->idarraydata + s->obsoletes;
1411 while ((obs = *obsp++) != 0)
1413 if ((providedbyinstalled(pool, map, obs) & 1) != 0)
1422 FOR_PROVIDES(p2, pp, s->name)
1424 s2 = pool->solvables + p2;
1425 if (s2->name == s->name && (map[p2] & 1) != 0)
1441 queue_clone(res, pkgs);
1442 for (i = 0; i < pkgs->count; i++)
1444 m = map[pkgs->elements[i]];
1451 res->elements[i] = r;