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 */
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 /*************************************************************************/
409 * add packages fulfilling the relation to whatprovides array
410 * no exact providers, do range match
415 pool_addrelproviders(Pool *pool, Id d)
417 Reldep *rd = GETRELDEP(pool, d);
423 int flags = rd->flags;
425 Id p, *pp, *pp2, *pp3;
429 queue_init_buffer(&plist, buf, sizeof(buf)/sizeof(*buf));
434 pp = pool_whatprovides(pool, name);
435 pp2 = pool_whatprovides(pool, evr);
436 while ((p = *pp++) != 0)
438 for (pp3 = pp2; *pp3;)
441 queue_push(&plist, p);
447 pp = pool_whatprovides(pool, name);
448 while ((p = *pp++) != 0)
449 queue_push(&plist, p);
450 pp = pool_whatprovides(pool, evr);
451 while ((p = *pp++) != 0)
452 queue_pushunique(&plist, p);
455 if (pool->nscallback)
457 /* ask callback which packages provide the dependency
459 * 1: the system (aka SYSTEMSOLVABLE)
460 * >1: a set of packages, stored as offset on whatprovidesdata
462 p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
466 pool->whatprovides_rel[d] = p;
467 return pool->whatprovidesdata + p;
470 queue_push(&plist, SYSTEMSOLVABLE);
474 pp = pool_whatprovides(pool, name);
476 while ((p = *pp++) != 0)
478 Solvable *s = pool->solvables + p;
480 queue_push(&plist, p);
491 /* convert to whatprovides id */
493 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
495 if (flags && flags < 8)
497 pp = pool_whatprovides(pool, name);
498 while (ISRELDEP(name))
500 rd = GETRELDEP(pool, name);
503 while ((p = *pp++) != 0)
506 POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, pool->p[p].name));
508 /* solvable p provides name in some rels */
509 pidp = pool->solvables[p].repo->idarraydata + pool->solvables[p].provides;
510 while ((pid = *pidp++) != 0)
517 #ifdef DEBIAN_SEMANTICS
518 continue; /* unversioned provides can
519 * never match versioned deps */
521 break; /* yes, provides all versions */
525 continue; /* wrong provides name */
526 prd = GETRELDEP(pool, pid);
527 if (prd->name != name)
528 continue; /* wrong provides name */
529 /* right package, both deps are rels */
533 if (flags == 7 || pflags == 7)
534 break; /* included */
535 if ((pflags & flags & 5) != 0)
536 break; /* same direction, match */
540 if ((pflags & flags & 2) != 0)
541 break; /* both have =, match */
545 int f = flags == 5 ? 5 : flags == 2 ? pflags : (flags ^ 5) & (pflags | 5);
546 if ((f & (1 << (1 + evrcmp(pool, pevr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
551 continue; /* no rel match */
552 queue_push(&plist, p);
554 /* make our system solvable provide all unknown rpmlib() stuff */
555 if (plist.count == 0 && !strncmp(id2str(pool, name), "rpmlib(", 7))
556 queue_push(&plist, SYSTEMSOLVABLE);
558 /* add providers to whatprovides */
560 POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
562 pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
565 return pool->whatprovidesdata + pool->whatprovides_rel[d];
568 /*************************************************************************/
571 pool_debug(Pool *pool, int type, const char *format, ...)
576 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
578 if ((pool->debugmask & type) == 0)
581 va_start(args, format);
582 if (!pool->debugcallback)
584 if ((type & (SAT_FATAL|SAT_ERROR)) == 0)
585 vprintf(format, args);
587 vfprintf(stderr, format, args);
590 vsnprintf(buf, sizeof(buf), format, args);
591 pool->debugcallback(pool, pool->debugcallbackdata, type, buf);
595 pool_setdebuglevel(Pool *pool, int level)
597 int mask = SAT_DEBUG_RESULT;
599 mask |= SAT_DEBUG_STATS|SAT_DEBUG_ANALYZE|SAT_DEBUG_UNSOLVABLE;
601 mask |= SAT_DEBUG_JOB|SAT_DEBUG_SOLUTIONS|SAT_DEBUG_POLICY;
603 mask |= SAT_DEBUG_PROPAGATE;
605 mask |= SAT_DEBUG_RULE_CREATION;
607 mask |= SAT_DEBUG_SCHUBI;
608 pool->debugmask = mask;
611 /*************************************************************************/
621 #define SEARCHFILES_BLOCK 127
624 pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
628 struct searchfiles *csf;
630 while ((dep = *ida++) != 0)
633 while (ISRELDEP(dep))
636 sid = pool->ss.nstrings + GETRELID(dep);
637 if (MAPTST(&csf->seen, sid))
642 MAPSET(&csf->seen, sid);
643 rd = GETRELDEP(pool, dep);
646 else if (rd->flags == REL_NAMESPACE)
648 if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
651 if (!csf || MAPTST(&csf->seen, sid))
656 MAPSET(&csf->seen, sid);
665 pool_addfileprovides_dep(pool, ids, csf, isf);
671 if (MAPTST(&csf->seen, dep))
673 MAPSET(&csf->seen, dep);
674 s = id2str(pool, dep);
677 csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
678 csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
679 csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
680 csf->ids[csf->nfiles] = dep;
681 sr = strrchr(s, '/');
682 csf->names[csf->nfiles] = strdup(sr + 1);
683 csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
685 strncpy(csf->dirs[csf->nfiles], s, sr - s);
686 csf->dirs[csf->nfiles][sr - s] = 0;
691 struct addfileprovides_cbdata {
703 addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
705 struct addfileprovides_cbdata *cbd = cbdata;
708 if (data != cbd->olddata)
710 map_free(&cbd->useddirs);
711 map_init(&cbd->useddirs, data->dirpool.ndirs);
712 for (i = 0; i < cbd->nfiles; i++)
714 Id did = repodata_str2dir(data, cbd->dirs[i], 0);
717 MAPSET(&cbd->useddirs, did);
721 if (!MAPTST(&cbd->useddirs, value->id))
723 for (i = 0; i < cbd->nfiles; i++)
725 if (cbd->dids[i] != value->id)
727 if (!strcmp(cbd->names[i], value->str))
730 if (i == cbd->nfiles)
732 s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
738 pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
740 Id p, start, end, *idp;
742 Repodata *data = 0, *nextdata;
744 int dataincludes = 0;
748 cbd->nfiles = sf->nfiles;
750 cbd->dirs = sf->dirs;
751 cbd->names = sf->names;
753 cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
756 start = repoonly->start;
761 start = 2; /* skip system solvable */
762 end = pool->nsolvables;
764 for (p = start, s = pool->solvables + p; p < end; p++, s++)
766 if (!s->repo || (repoonly && s->repo != repoonly))
768 if (s->repo != oldrepo || (data && p >= data->end))
776 for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
778 if (!data->addedfileprovides || p >= data->end)
780 if (!nextdata || nextdata->start > data->start)
782 if (p >= data->start)
785 if (i == s->repo->nrepodata)
789 map_init(&providedids, pool->ss.nstrings);
790 for (idp = data->addedfileprovides; *idp; idp++)
791 MAPSET(&providedids, *idp);
792 for (i = 0; i < cbd->nfiles; i++)
793 if (!MAPTST(&providedids, cbd->ids[i]))
797 map_free(&providedids);
798 dataincludes = i == cbd->nfiles;
802 if (data && p >= data->start && dataincludes)
804 repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
809 pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
813 struct searchfiles sf, isf, *isfp;
814 struct addfileprovides_cbdata cbd;
817 memset(&sf, 0, sizeof(sf));
818 map_init(&sf.seen, pool->ss.nstrings + pool->nrels);
819 memset(&isf, 0, sizeof(isf));
820 map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
822 isfp = installed ? &isf : 0;
823 for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
829 pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
831 pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
833 pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
835 pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
837 pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
839 pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
841 pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
843 pool_addfileprovides_dep(pool, repo->idarraydata + s->freshens, &sf, isfp);
847 POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
848 POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
850 map_init(&cbd.useddirs, 1);
856 for (i = 0; i < sf.nfiles; i++)
857 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
859 pool_addfileprovides_search(pool, &cbd, &sf, 0);
862 sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
863 sf.ids[sf.nfiles] = 0;
868 for (i = 0; i < sf.nfiles; i++)
870 sat_free(sf.dirs[i]);
871 sat_free(sf.names[i]);
879 for (i = 0; i < isf.nfiles; i++)
880 POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
883 pool_addfileprovides_search(pool, &cbd, &isf, installed);
885 for (i = 0; i < isf.nfiles; i++)
887 sat_free(isf.dirs[i]);
888 sat_free(isf.names[i]);
893 map_free(&cbd.useddirs);
895 pool_freewhatprovides(pool); /* as we have added provides */
899 pool_addfileprovides(Pool *pool, Repo *installed)
901 pool_addfileprovides_ids(pool, installed, 0);
905 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)
909 if (pool->solvables[p].repo)
910 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
913 /* FIXME: obey callback return value! */
914 for (p = 1; p < pool->nsolvables; p++)
915 if (pool->solvables[p].repo)
916 repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
921 pool_set_languages(Pool *pool, const char **languages, int nlanguages)
925 pool->languagecache = sat_free(pool->languagecache);
926 pool->languagecacheother = 0;
927 if (pool->nlanguages)
929 for (i = 0; i < pool->nlanguages; i++)
930 free((char *)pool->languages[i]);
931 free(pool->languages);
933 pool->nlanguages = nlanguages;
936 pool->languages = sat_calloc(nlanguages, sizeof(const char **));
937 for (i = 0; i < pool->nlanguages; i++)
938 pool->languages[i] = strdup(languages[i]);
942 pool_alloctmpspace(Pool *pool, int len)
944 int n = pool->tmpspacen;
947 if (len > pool->tmpspacelen[n])
949 pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
950 pool->tmpspacelen[n] = len + 32;
952 pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
953 return pool->tmpspacebuf[n];
956 /*******************************************************************/
968 struct mptree *mptree;
978 solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
980 struct ducbdata *cbd = cbdata;
983 if (data != cbd->olddata)
985 Id dn, mp, comp, *dirmap, *dirs;
988 struct mptree *mptree;
990 /* create map from dir to mptree */
991 cbd->dirmap = sat_free(cbd->dirmap);
993 dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
994 mptree = cbd->mptree;
996 for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
1010 if (!mptree[mp].child)
1015 if (data->localpool)
1016 compstr = stringpool_id2str(&data->spool, comp);
1018 compstr = id2str(data->repo->pool, comp);
1019 compl = strlen(compstr);
1020 for (i = mptree[mp].child; i; i = mptree[i].sibling)
1021 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1023 dirmap[dn] = i ? i : -mp;
1025 /* change dirmap to point to mountpoint instead of mptree */
1026 for (dn = 0; dn < data->dirpool.ndirs; dn++)
1029 dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
1031 cbd->dirmap = dirmap;
1032 cbd->nmap = data->dirpool.ndirs;
1033 cbd->olddata = data;
1035 if (value->id < 0 || value->id >= cbd->nmap)
1037 mp = cbd->dirmap[value->id];
1040 if (cbd->addsub > 0)
1042 cbd->mps[mp].kbytes += value->num;
1043 cbd->mps[mp].files += value->num2;
1047 cbd->mps[mp].kbytes -= value->num;
1048 cbd->mps[mp].files -= value->num2;
1054 propagate_mountpoints(struct mptree *mptree, int pos, Id mountpoint)
1057 if (mptree[pos].mountpoint == -1)
1058 mptree[pos].mountpoint = mountpoint;
1060 mountpoint = mptree[pos].mountpoint;
1061 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1062 propagate_mountpoints(mptree, i, mountpoint);
1065 #define MPTREE_BLOCK 15
1068 pool_calc_duchanges(Pool *pool, Queue *pkgs, DUChanges *mps, int nmps)
1071 const char *path, *compstr;
1072 struct mptree *mptree;
1076 struct ducbdata cbd;
1084 mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
1087 mptree[0].sibling = 0;
1088 mptree[0].child = 0;
1090 mptree[0].compl = 0;
1091 mptree[0].mountpoint = -1;
1094 /* create component tree */
1095 for (mp = 0; mp < nmps; mp++)
1100 path = mps[mp].path;
1105 if ((p = strchr(path, '/')) == 0)
1108 compl = strlen(compstr);
1119 for (i = mptree[pos].child; i; i = mptree[i].sibling)
1120 if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
1124 /* create new node */
1125 mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
1127 mptree[i].sibling = mptree[pos].child;
1128 mptree[i].child = 0;
1129 mptree[i].comp = compstr;
1130 mptree[i].compl = compl;
1131 mptree[i].mountpoint = -1;
1132 mptree[pos].child = i;
1136 mptree[pos].mountpoint = mp;
1139 propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
1142 for (i = 0; i < nmptree; i++)
1144 printf("#%d sibling: %d\n", i, mptree[i].sibling);
1145 printf("#%d child: %d\n", i, mptree[i].child);
1146 printf("#%d comp: %s\n", i, mptree[i].comp);
1147 printf("#%d compl: %d\n", i, mptree[i].compl);
1148 printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
1152 cbd.mptree = mptree;
1154 for (i = 0; i < pkgs->count; i++)
1156 Id sp = pkgs->elements[i];
1158 repo_search(pool->solvables[sp].repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1161 for (i = 0; i < pkgs->count; i++)
1163 Id sp = pkgs->elements[i];
1165 repo_search(pool->solvables[-sp].repo, -sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
1167 sat_free(cbd.dirmap);
1172 pool_calc_installsizechange(Pool *pool, Queue *pkgs)
1177 for (i = 0; i < pkgs->count; i++)
1179 Id sp = pkgs->elements[i];
1181 change += repo_lookup_num(pool->solvables + sp, SOLVABLE_INSTALLSIZE);
1183 change -= repo_lookup_num(pool->solvables - sp, SOLVABLE_INSTALLSIZE);