#define SOLVABLE_BLOCK 255
-
-// list of string constants, so we can do pointer/Id instead of string comparison
-// index into array matches ID_xxx constants in pool.h
-
-static const char *initpool_data[] = {
- "<NULL>", // ID_NULL
- "", // ID_EMPTY
- "solvable:name",
- "solvable:arch",
- "solvable:evr",
- "solvable:vendor",
- "solvable:provides",
- "solvable:obsoletes",
- "solvable:conflicts",
- "solvable:requires",
- "solvable:recommends",
- "solvable:suggests",
- "solvable:supplements",
- "solvable:enhances",
- "solvable:freshens",
- "rpm:dbid", /* direct key into rpmdb */
- "solvable:prereqmarker",
- "solvable:filemarker",
- "namespace:installed",
- "namespace:modalias",
- "namespace:splitprovides",
- "system:system",
- "src",
- "nosrc",
- "noarch",
- "repodata:external",
- "repodata:keys",
- "repodata:location",
- 0
-};
+#define KNOWNID_INITIALIZE
+#include "knownid.h"
+#undef KNOWNID_INITIALIZE
/* create pool */
Pool *
stringpool_init (&pool->ss, initpool_data);
- /* alloc space for ReDep 0 */
+ /* alloc space for RelDep 0 */
pool->rels = sat_extend_resize(0, 1, sizeof(Reldep), REL_BLOCK);
pool->nrels = 1;
memset(pool->rels, 0, sizeof(Reldep));
sat_free(pool->ss.strings);
sat_free(pool->rels);
queue_free(&pool->vendormap);
- for (i = 0; i < DEP2STRBUF; i++)
- sat_free(pool->dep2strbuf[i]);
+ for (i = 0; i < POOL_TMPSPACEBUF; i++)
+ sat_free(pool->tmpspacebuf[i]);
+ for (i = 0; i < pool->nlanguages; i++)
+ free((char *)pool->languages[i]);
+ sat_free(pool->languages);
+ sat_free(pool->languagecache);
sat_free(pool);
}
}
-const char *
-solvable2str(Pool *pool, Solvable *s)
-{
- int l, nn = pool->dep2strn;
- const char *n, *e, *a;
- n = id2str(pool, s->name);
- e = id2str(pool, s->evr);
- a = id2str(pool, s->arch);
- l = strlen(n) + strlen(e) + strlen(a) + 3;
- if (l > pool->dep2strlen[nn])
- {
- pool->dep2strbuf[nn] = sat_realloc(pool->dep2strbuf[nn], l + 32);
- pool->dep2strlen[nn] = l + 32;
- }
- sprintf(pool->dep2strbuf[nn], "%s-%s.%s", n, e, a);
- pool->dep2strn = (nn + 1) % DEP2STRBUF;
- return pool->dep2strbuf[nn];
-}
-
static Pool *pool_shrink_whatprovides_sortcmp_data;
static int
pool_freeidhashes(pool); /* XXX: should not be here! */
pool_freewhatprovides(pool);
num = pool->ss.nstrings;
- pool->whatprovides = whatprovides = sat_extend_resize(0, num, sizeof(Offset), WHATPROVIDES_BLOCK);
- memset(whatprovides, 0, num * sizeof(Offset));
- pool->whatprovides_rel = sat_extend_resize(0, pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
- memset(pool->whatprovides_rel, 0, pool->nrels * sizeof(Offset));
+ pool->whatprovides = whatprovides = sat_calloc_block(num, sizeof(Offset), WHATPROVIDES_BLOCK);
+ pool->whatprovides_rel = sat_calloc_block(pool->nrels, sizeof(Offset), WHATPROVIDES_BLOCK);
/* count providers for each name */
for (i = 1; i < pool->nsolvables; i++)
d++;
while (*d) /* find free slot */
d++;
- if (d[-1] == i)
- continue;
+ if (d[-1] == i) /* solvable already tacked at end ? */
+ continue; /* Y: skip, on to next provides */
}
*d = i; /* put solvable Id into data */
}
/*************************************************************************/
+/* check if a package's nevr matches a dependency */
+
+int
+pool_match_nevr_rel(Pool *pool, Solvable *s, Id d)
+{
+ Reldep *rd = GETRELDEP(pool, d);
+ Id name = rd->name;
+ Id evr = rd->evr;
+ int flags = rd->flags;
+
+ if (flags > 7)
+ {
+ switch (flags)
+ {
+ case REL_ARCH:
+ if (s->arch != evr)
+ return 0;
+ return pool_match_nevr(pool, s, name);
+ case REL_OR:
+ if (pool_match_nevr(pool, s, name))
+ return 1;
+ return pool_match_nevr(pool, s, evr);
+ case REL_AND:
+ case REL_WITH:
+ if (!pool_match_nevr(pool, s, name))
+ return 0;
+ return pool_match_nevr(pool, s, evr);
+ default:
+ return 0;
+ }
+ }
+ if (!pool_match_nevr(pool, s, name))
+ return 0;
+ if (evr == s->evr)
+ return flags & 2 ? 1 : 0;
+ if (!flags)
+ return 0;
+ if (flags == 7)
+ return 1;
+ if (flags != 2 && flags != 5)
+ flags ^= 5;
+ if ((flags & (1 << (1 + evrcmp(pool, s->evr, evr, EVRCMP_MATCH_RELEASE)))) != 0)
+ return 1;
+ return 0;
+}
+
/*
* addrelproviders
*
case REL_NAMESPACE:
if (pool->nscallback)
{
+ /* ask callback which packages provide the dependency
+ * 0: none
+ * 1: the system (aka SYSTEMSOLVABLE)
+ * >1: a set of packages, stored as offset on whatprovidesdata
+ */
p = pool->nscallback(pool, pool->nscallbackdata, name, evr);
if (p > 1)
{
queue_push(&plist, SYSTEMSOLVABLE);
}
break;
+ case REL_ARCH:
+ /* small hack: make it possible to match <pkg>.src
+ * we have to iterate over the solvables as src packages do not
+ * provide anything, thus they are not indexed in our
+ * whatprovides hash */
+ if (evr == ARCH_SRC)
+ {
+ Solvable *s;
+ for (p = 1, s = pool->solvables + p; p < pool->nsolvables; p++, s++)
+ {
+ if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
+ continue;
+ if (pool_match_nevr(pool, s, name))
+ queue_push(&plist, p);
+ }
+ break;
+ }
+ pp = pp2 = pool_whatprovides(pool, name);
+ while ((p = *pp++) != 0)
+ {
+ Solvable *s = pool->solvables + p;
+ if (s->arch == evr)
+ queue_push(&plist, p);
+ else
+ pp2 = 0;
+ }
+ if (pp2)
+ return pp2;
+ break;
default:
break;
}
/* convert to whatprovides id */
#if 0
- POOL_DEBUG(DEBUG_1, "addrelproviders: what provides %s?\n", id2str(pool, name));
+ POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: what provides %s?\n", dep2str(pool, name));
#endif
if (flags && flags < 8)
{
- FOR_PROVIDES(p, pp, name)
+ pp = pool_whatprovides(pool, name);
+ while (ISRELDEP(name))
{
+ rd = GETRELDEP(pool, name);
+ name = rd->name;
+ }
+ while ((p = *pp++) != 0)
+ {
+ Solvable *s = pool->solvables + p;
#if 0
- POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, pool->p[p].name));
+ POOL_DEBUG(DEBUG_1, "addrelproviders: checking package %s\n", id2str(pool, s->name));
#endif
+ if (!s->provides)
+ {
+ /* no provides - check nevr */
+ if (pool_match_nevr_rel(pool, s, MAKERELDEP(d)))
+ queue_push(&plist, p);
+ continue;
+ }
/* solvable p provides name in some rels */
- pidp = pool->solvables[p].repo->idarraydata + pool->solvables[p].provides;
+ pidp = s->repo->idarraydata + s->provides;
while ((pid = *pidp++) != 0)
{
int pflags;
}
/* add providers to whatprovides */
#if 0
- POOL_DEBUG(DEBUG_1, "addrelproviders: adding %d packages to %d\n", plist.count, d);
+ POOL_DEBUG(SAT_DEBUG_STATS, "addrelproviders: adding %d packages to %d\n", plist.count, d);
#endif
pool->whatprovides_rel[d] = pool_queuetowhatprovides(pool, &plist);
queue_free(&plist);
/*************************************************************************/
struct searchfiles {
- const char **files;
+ Id *ids;
+ char **dirs;
+ char **names;
int nfiles;
Map seen;
};
pool_addfileprovides_dep(Pool *pool, Id *ida, struct searchfiles *sf, struct searchfiles *isf)
{
Id dep, sid;
- const char *s;
+ const char *s, *sr;
+ struct searchfiles *csf;
while ((dep = *ida++) != 0)
{
+ csf = sf;
while (ISRELDEP(dep))
{
Reldep *rd;
sid = pool->ss.nstrings + GETRELID(dep);
- if (MAPTST(&sf->seen, sid))
+ if (MAPTST(&csf->seen, sid))
{
dep = 0;
break;
}
- MAPSET(&sf->seen, sid);
+ MAPSET(&csf->seen, sid);
rd = GETRELDEP(pool, dep);
if (rd->flags < 8)
dep = rd->name;
else if (rd->flags == REL_NAMESPACE)
{
- if (isf && (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES))
+ if (rd->name == NAMESPACE_INSTALLED || rd->name == NAMESPACE_SPLITPROVIDES)
{
- sf = isf;
- isf = 0;
- if (MAPTST(&sf->seen, sid))
+ csf = isf;
+ if (!csf || MAPTST(&csf->seen, sid))
{
dep = 0;
break;
}
- MAPSET(&sf->seen, sid);
+ MAPSET(&csf->seen, sid);
}
dep = rd->evr;
}
Id ids[2];
ids[0] = rd->name;
ids[1] = 0;
- pool_addfileprovides_dep(pool, ids, sf, isf);
+ pool_addfileprovides_dep(pool, ids, csf, isf);
dep = rd->evr;
}
}
if (!dep)
continue;
- if (MAPTST(&sf->seen, dep))
+ if (MAPTST(&csf->seen, dep))
continue;
- MAPSET(&sf->seen, dep);
+ MAPSET(&csf->seen, dep);
s = id2str(pool, dep);
if (*s != '/')
continue;
- sf->files = sat_extend(sf->files, sf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
- sf->files[sf->nfiles++] = strdup(s);
+ csf->ids = sat_extend(csf->ids, csf->nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
+ csf->dirs = sat_extend(csf->dirs, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
+ csf->names = sat_extend(csf->names, csf->nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
+ csf->ids[csf->nfiles] = dep;
+ sr = strrchr(s, '/');
+ csf->names[csf->nfiles] = strdup(sr + 1);
+ csf->dirs[csf->nfiles] = sat_malloc(sr - s + 1);
+ if (sr != s)
+ strncpy(csf->dirs[csf->nfiles], s, sr - s);
+ csf->dirs[csf->nfiles][sr - s] = 0;
+ csf->nfiles++;
}
}
-#if 0
+struct addfileprovides_cbdata {
+ int nfiles;
+ Id *ids;
+ char **dirs;
+ char **names;
+
+ Repodata *olddata;
+ Id *dids;
+ Map useddirs;
+};
+
static int
-addfileprovides_cb(void *data, Solvable *s, Id key, const char *str)
+addfileprovides_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
{
- Pool *pool = s->repo->pool;
- Id id;
- id = str2id(pool, str, 0);
- if (!id)
- return 0; /* can't happen */
- s->provides = repo_addid_dep(s->repo, s->provides, id, SOLVABLE_FILEMARKER);
+ struct addfileprovides_cbdata *cbd = cbdata;
+ int i;
+
+ if (data != cbd->olddata)
+ {
+ map_free(&cbd->useddirs);
+ map_init(&cbd->useddirs, data->dirpool.ndirs);
+ for (i = 0; i < cbd->nfiles; i++)
+ {
+ Id did = repodata_str2dir(data, cbd->dirs[i], 0);
+ cbd->dids[i] = did;
+ if (did)
+ MAPSET(&cbd->useddirs, did);
+ }
+ cbd->olddata = data;
+ }
+ if (!MAPTST(&cbd->useddirs, value->id))
+ return 0;
+ for (i = 0; i < cbd->nfiles; i++)
+ {
+ if (cbd->dids[i] != value->id)
+ continue;
+ if (!strcmp(cbd->names[i], value->str))
+ break;
+ }
+ if (i == cbd->nfiles)
+ return 0;
+ s->provides = repo_addid_dep(s->repo, s->provides, cbd->ids[i], SOLVABLE_FILEMARKER);
return 0;
}
-#endif
+
+
+static void
+pool_addfileprovides_search(Pool *pool, struct addfileprovides_cbdata *cbd, struct searchfiles *sf, Repo *repoonly)
+{
+ Id p, start, end, *idp;
+ Solvable *s;
+ Repodata *data = 0, *nextdata;
+ Repo *oldrepo = 0;
+ int dataincludes = 0;
+ int i;
+ Map providedids;
+
+ cbd->nfiles = sf->nfiles;
+ cbd->ids = sf->ids;
+ cbd->dirs = sf->dirs;
+ cbd->names = sf->names;
+ cbd->olddata = 0;
+ cbd->dids = sat_realloc2(cbd->dids, sf->nfiles, sizeof(Id));
+ if (repoonly)
+ {
+ start = repoonly->start;
+ end = repoonly->end;
+ }
+ else
+ {
+ start = 2; /* skip system solvable */
+ end = pool->nsolvables;
+ }
+ for (p = start, s = pool->solvables + p; p < end; p++, s++)
+ {
+ if (!s->repo || (repoonly && s->repo != repoonly))
+ continue;
+ if (s->repo != oldrepo || (data && p >= data->end))
+ {
+ data = 0;
+ oldrepo = 0;
+ }
+ if (oldrepo == 0)
+ {
+ nextdata = 0;
+ for (i = 0, data = s->repo->repodata; i < s->repo->nrepodata; i++, data++)
+ {
+ if (!data->addedfileprovides || p >= data->end)
+ continue;
+ if (!nextdata || nextdata->start > data->start)
+ nextdata = data;
+ if (p >= data->start)
+ break;
+ }
+ if (i == s->repo->nrepodata)
+ data = nextdata;
+ if (data)
+ {
+ map_init(&providedids, pool->ss.nstrings);
+ for (idp = data->addedfileprovides; *idp; idp++)
+ MAPSET(&providedids, *idp);
+ for (i = 0; i < cbd->nfiles; i++)
+ if (!MAPTST(&providedids, cbd->ids[i]))
+ {
+ break;
+ }
+ map_free(&providedids);
+ dataincludes = i == cbd->nfiles;
+ }
+ oldrepo = s->repo;
+ }
+ if (data && p >= data->start && dataincludes)
+ continue;
+ repo_search(s->repo, p, SOLVABLE_FILELIST, 0, 0, addfileprovides_cb, cbd);
+ }
+}
void
-pool_addfileprovides(Pool *pool, Repo *installed)
+pool_addfileprovides_ids(Pool *pool, Repo *installed, Id **idp)
{
Solvable *s;
Repo *repo;
- struct searchfiles sf, isf;
+ struct searchfiles sf, isf, *isfp;
+ struct addfileprovides_cbdata cbd;
int i;
memset(&sf, 0, sizeof(sf));
memset(&isf, 0, sizeof(isf));
map_init(&isf.seen, pool->ss.nstrings + pool->nrels);
+ isfp = installed ? &isf : 0;
for (i = 1, s = pool->solvables + i; i < pool->nsolvables; i++, s++)
{
repo = s->repo;
if (!repo)
continue;
if (s->obsoletes)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->obsoletes, &sf, isfp);
if (s->conflicts)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->conflicts, &sf, isfp);
if (s->requires)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->requires, &sf, isfp);
if (s->recommends)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->recommends, &sf, isfp);
if (s->suggests)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->suggests, &sf, isfp);
if (s->supplements)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->supplements, &sf, isfp);
if (s->enhances)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, &isf);
- if (s->freshens)
- pool_addfileprovides_dep(pool, repo->idarraydata + s->freshens, &sf, &isf);
+ pool_addfileprovides_dep(pool, repo->idarraydata + s->enhances, &sf, isfp);
}
map_free(&sf.seen);
map_free(&isf.seen);
POOL_DEBUG(SAT_DEBUG_STATS, "found %d file dependencies\n", sf.nfiles);
POOL_DEBUG(SAT_DEBUG_STATS, "found %d installed file dependencies\n", isf.nfiles);
+ cbd.dids = 0;
+ map_init(&cbd.useddirs, 1);
+ if (idp)
+ *idp = 0;
if (sf.nfiles)
{
#if 0
for (i = 0; i < sf.nfiles; i++)
- POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", sf.files[i]);
+ POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in filelist\n", id2str(pool, sf.ids[i]));
#endif
- sf.files = sat_extend(sf.files, sf.nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
- sf.files[sf.nfiles++] = 0;
-#if 0
- pool_search(0, SOLVABLE_FILELIST, (const char *)sf.files, SEARCH_STRING|SEARCH_MULTIPLE, addfileprovides_cb, 0);
-#endif
- sat_free(sf.files);
+ pool_addfileprovides_search(pool, &cbd, &sf, 0);
+ if (idp)
+ {
+ sf.ids = sat_extend(sf.ids, sf.nfiles, 1, sizeof(Id), SEARCHFILES_BLOCK);
+ sf.ids[sf.nfiles] = 0;
+ *idp = sf.ids;
+ sf.ids = 0;
+ }
+ sat_free(sf.ids);
+ for (i = 0; i < sf.nfiles; i++)
+ {
+ sat_free(sf.dirs[i]);
+ sat_free(sf.names[i]);
+ }
+ sat_free(sf.dirs);
+ sat_free(sf.names);
}
- if (isf.nfiles && installed)
+ if (isf.nfiles)
{
#if 0
for (i = 0; i < isf.nfiles; i++)
- POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", isf.files[i]);
-#endif
- isf.files = sat_extend(isf.files, isf.nfiles, 1, sizeof(const char *), SEARCHFILES_BLOCK);
- isf.files[isf.nfiles++] = 0;
-#if 0
- repo_search(installed, 0, SOLVABLE_FILELIST, (const char *)isf.files, SEARCH_STRING|SEARCH_MULTIPLE, addfileprovides_cb, 0);
+ POOL_DEBUG(SAT_DEBUG_STATS, "looking up %s in installed filelist\n", id2str(pool, isf.ids[i]));
#endif
- sat_free(isf.files);
+ if (installed)
+ pool_addfileprovides_search(pool, &cbd, &isf, installed);
+ sat_free(isf.ids);
+ for (i = 0; i < isf.nfiles; i++)
+ {
+ sat_free(isf.dirs[i]);
+ sat_free(isf.names[i]);
+ }
+ sat_free(isf.dirs);
+ sat_free(isf.names);
}
+ map_free(&cbd.useddirs);
+ sat_free(cbd.dids);
pool_freewhatprovides(pool); /* as we have added provides */
}
-#if 0
+void
+pool_addfileprovides(Pool *pool, Repo *installed)
+{
+ pool_addfileprovides_ids(pool, installed, 0);
+}
-struct mountpoint {
- const char *path;
- int kbytes;
- int files;
-};
+void
+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)
+{
+ if (p)
+ {
+ if (pool->solvables[p].repo)
+ repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
+ return;
+ }
+ /* FIXME: obey callback return value! */
+ for (p = 1; p < pool->nsolvables; p++)
+ if (pool->solvables[p].repo)
+ repo_search(pool->solvables[p].repo, p, key, match, flags, callback, cbdata);
+}
+
+
+void
+pool_set_languages(Pool *pool, const char **languages, int nlanguages)
+{
+ int i;
+
+ pool->languagecache = sat_free(pool->languagecache);
+ pool->languagecacheother = 0;
+ if (pool->nlanguages)
+ {
+ for (i = 0; i < pool->nlanguages; i++)
+ free((char *)pool->languages[i]);
+ free(pool->languages);
+ }
+ pool->nlanguages = nlanguages;
+ if (!nlanguages)
+ return;
+ pool->languages = sat_calloc(nlanguages, sizeof(const char **));
+ for (i = 0; i < pool->nlanguages; i++)
+ pool->languages[i] = strdup(languages[i]);
+}
+
+Id
+pool_id2langid(Pool *pool, Id id, const char *lang, int create)
+{
+ const char *n;
+ char buf[256], *p;
+ int l;
+
+ if (!lang)
+ return id;
+ n = id2str(pool, id);
+ l = strlen(n) + strlen(lang) + 2;
+ if (l > sizeof(buf))
+ p = sat_malloc(strlen(n) + strlen(lang) + 2);
+ else
+ p = buf;
+ sprintf(p, "%s:%s", n, lang);
+ id = str2id(pool, p, create);
+ if (p != buf)
+ free(p);
+ return id;
+}
+
+char *
+pool_alloctmpspace(Pool *pool, int len)
+{
+ int n = pool->tmpspacen;
+ if (!len)
+ return 0;
+ if (len > pool->tmpspacelen[n])
+ {
+ pool->tmpspacebuf[n] = sat_realloc(pool->tmpspacebuf[n], len + 32);
+ pool->tmpspacelen[n] = len + 32;
+ }
+ pool->tmpspacen = (n + 1) % POOL_TMPSPACEBUF;
+ return pool->tmpspacebuf[n];
+}
+
+/*******************************************************************/
struct mptree {
Id sibling;
Id mountpoint;
};
-struct cbdata {
- struct mountpoint *mps;
+struct ducbdata {
+ DUChanges *mps;
+ struct mptree *mptree;
+ int addsub;
+ int hasdu;
+
Id *dirmap;
int nmap;
+ Repodata *olddata;
};
+
static int
-pool_fill_DU_add_cb(void *data, Solvable *s, Id key, const char *str)
+solver_fill_DU_cb(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *value)
{
- struct cbdata *cbdata = data;
- Id mp, dirnum, kbytes, files;
+ struct ducbdata *cbd = cbdata;
+ Id mp;
- dp = data_read_id(dp, &dirnum);
- dp = data_read_id(dp, &kbytes);
- data_read_id(dp, &files);
- if (dirnum < 0 || dirnum > cbdata->nmap)
- return 0;
- mp = cbdata->dirmap[dirnum];
- if (mp >= 0)
+ if (data != cbd->olddata)
{
- cbdata->mps[mp].kbytes += kbytes;
- cbdata->mps[mp].files += files;
+ Id dn, mp, comp, *dirmap, *dirs;
+ int i, compl;
+ const char *compstr;
+ struct mptree *mptree;
+
+ /* create map from dir to mptree */
+ cbd->dirmap = sat_free(cbd->dirmap);
+ cbd->nmap = 0;
+ dirmap = sat_calloc(data->dirpool.ndirs, sizeof(Id));
+ mptree = cbd->mptree;
+ mp = 0;
+ for (dn = 2, dirs = data->dirpool.dirs + dn; dn < data->dirpool.ndirs; dn++)
+ {
+ comp = *dirs++;
+ if (comp <= 0)
+ {
+ mp = dirmap[-comp];
+ continue;
+ }
+ if (mp < 0)
+ {
+ /* unconnected */
+ dirmap[dn] = mp;
+ continue;
+ }
+ if (!mptree[mp].child)
+ {
+ dirmap[dn] = -mp;
+ continue;
+ }
+ if (data->localpool)
+ compstr = stringpool_id2str(&data->spool, comp);
+ else
+ compstr = id2str(data->repo->pool, comp);
+ compl = strlen(compstr);
+ for (i = mptree[mp].child; i; i = mptree[i].sibling)
+ if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
+ break;
+ dirmap[dn] = i ? i : -mp;
+ }
+ /* change dirmap to point to mountpoint instead of mptree */
+ for (dn = 0; dn < data->dirpool.ndirs; dn++)
+ {
+ mp = dirmap[dn];
+ dirmap[dn] = mptree[mp > 0 ? mp : -mp].mountpoint;
+ }
+ cbd->dirmap = dirmap;
+ cbd->nmap = data->dirpool.ndirs;
+ cbd->olddata = data;
}
- return 0;
-}
-
-static int
-pool_fill_DU_sub_cb(void *data, Solvable *s, Id key, const char *str)
-{
- struct cbdata *cbdata = data;
- Id mp, dirnum, kbytes, files;
-
- dp = data_read_id(dp, &dirnum);
- dp = data_read_id(dp, &kbytes);
- data_read_id(dp, &files);
- if (dirnum < 0 || dirnum > cbdata->nmap)
+ cbd->hasdu = 1;
+ if (value->id < 0 || value->id >= cbd->nmap)
return 0;
- mp = cbdata->dirmap[dirnum];
- if (mp >= 0)
+ mp = cbd->dirmap[value->id];
+ if (mp < 0)
+ return 0;
+ if (cbd->addsub > 0)
+ {
+ cbd->mps[mp].kbytes += value->num;
+ cbd->mps[mp].files += value->num2;
+ }
+ else
{
- cbdata->mps[mp].kbytes -= kbytes;
- cbdata->mps[mp].files -= files;
+ cbd->mps[mp].kbytes -= value->num;
+ cbd->mps[mp].files -= value->num2;
}
return 0;
}
propagate_mountpoints(mptree, i, mountpoint);
}
+#define MPTREE_BLOCK 15
+
void
-pool_fill_DU(Pool *pool, struct mountpoint *mps, int nmps)
+pool_calc_duchanges(Pool *pool, Repo *oldinstalled, Map *installedmap, DUChanges *mps, int nmps)
{
- char *path, *p;
- Id *dirmap;
+ char *p;
+ const char *path, *compstr;
struct mptree *mptree;
- int nmptree;
- int pos;
+ int i, nmptree;
+ int pos, compl;
int mp;
+ struct ducbdata cbd;
+ Solvable *s;
+ Id sp;
+ Map ignoredu;
- struct matchdata md;
- struct cbdata cbdata;
-
- memset(&md, 0, sizeof(md));
- md.pool = 0;
- md.matchstr = 0;
- md.flags = 0;
- md.callback = 0;
- md.callback_data = &cbdata
-
- cbdata.mps = mps;
- cbdata.dirmap = 0;
- cbdata.nmap = 0;
+ memset(&ignoredu, 0, sizeof(ignoredu));
+ cbd.mps = mps;
+ cbd.addsub = 0;
+ cbd.dirmap = 0;
+ cbd.nmap = 0;
+ cbd.olddata = 0;
- mptree = sat_malloc2(16, sizeof(mptree));
+ mptree = sat_extend_resize(0, 1, sizeof(struct mptree), MPTREE_BLOCK);
/* our root node */
mptree[0].sibling = 0;
/* create component tree */
for (mp = 0; mp < nmps; mp++)
{
+ mps[mp].kbytes = 0;
+ mps[mp].files = 0;
pos = 0;
path = mps[mp].path;
while(*path == '/')
path++;
while (*path)
{
- if ((p = strchr('/', path)) == 0)
+ if ((p = strchr(path, '/')) == 0)
{
- comp = path;
- compl = strlen(comp);
+ compstr = path;
+ compl = strlen(compstr);
path += compl;
}
else
{
- comp = path;
+ compstr = path;
compl = p - path;
path = p + 1;
while(*path == '/')
path++;
}
for (i = mptree[pos].child; i; i = mptree[i].sibling)
- if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
+ if (mptree[i].compl == compl && !strncmp(mptree[i].comp, compstr, compl))
break;
if (!i)
{
/* create new node */
- if ((nmptree & 15) == 0)
- mptree = sat_realloc2(mptree, nmptree + 16, sizeof(mptree));
+ mptree = sat_extend(mptree, nmptree, 1, sizeof(struct mptree), MPTREE_BLOCK);
i = nmptree++;
mptree[i].sibling = mptree[pos].child;
mptree[i].child = 0;
- mptree[i].comp = comp;
+ mptree[i].comp = compstr;
mptree[i].compl = compl;
mptree[i].mountpoint = -1;
mptree[pos].child = i;
}
mptree[pos].mountpoint = mp;
}
+
propagate_mountpoints(mptree, 0, mptree[0].mountpoint);
- for_all_repos
+#if 0
+ for (i = 0; i < nmptree; i++)
{
- for_all_repodatas_containing_DU
+ printf("#%d sibling: %d\n", i, mptree[i].sibling);
+ printf("#%d child: %d\n", i, mptree[i].child);
+ printf("#%d comp: %s\n", i, mptree[i].comp);
+ printf("#%d compl: %d\n", i, mptree[i].compl);
+ printf("#%d mountpont: %d\n", i, mptree[i].mountpoint);
+ }
+#endif
+
+ cbd.mptree = mptree;
+ cbd.addsub = 1;
+ for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
+ {
+ if (!s->repo || (oldinstalled && s->repo == oldinstalled))
+ continue;
+ if (!MAPTST(installedmap, sp))
+ continue;
+ cbd.hasdu = 0;
+ repo_search(s->repo, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
+ if (!cbd.hasdu && oldinstalled)
{
- /* create map from dir to mptree */
- dirmap = xcalloc2(pool->ndirs, sizeof(Id));
- mp = 0;
- for (dn = 2, dirs = pool->dirs + dn; dn < pool->ndirs; dn++)
+ Id op, *opp;
+ /* no du data available, ignore data of all installed solvables we obsolete */
+ if (!ignoredu.map)
+ map_init(&ignoredu, oldinstalled->end - oldinstalled->start);
+ if (s->obsoletes)
{
- id = *dirs++;
- if (id <= 0)
+ Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
+ while ((obs = *obsp++) != 0)
+ FOR_PROVIDES(op, opp, obs)
+ if (op >= oldinstalled->start && op < oldinstalled->end)
+ MAPSET(&ignoredu, op - oldinstalled->start);
+ }
+ FOR_PROVIDES(op, opp, s->name)
+ if (pool->solvables[op].name == s->name)
+ if (op >= oldinstalled->start && op < oldinstalled->end)
+ MAPSET(&ignoredu, op - oldinstalled->start);
+ }
+ }
+ cbd.addsub = -1;
+ if (oldinstalled)
+ {
+ /* assumes we allways have du data for installed solvables */
+ FOR_REPO_SOLVABLES(oldinstalled, sp, s)
+ {
+ if (MAPTST(installedmap, sp))
+ continue;
+ if (ignoredu.map && MAPTST(&ignoredu, sp - oldinstalled->start))
+ continue;
+ repo_search(oldinstalled, sp, SOLVABLE_DISKUSAGE, 0, 0, solver_fill_DU_cb, &cbd);
+ }
+ }
+ if (ignoredu.map)
+ map_free(&ignoredu);
+ sat_free(cbd.dirmap);
+ sat_free(mptree);
+}
+
+int
+pool_calc_installsizechange(Pool *pool, Repo *oldinstalled, Map *installedmap)
+{
+ Id sp;
+ Solvable *s;
+ int change = 0;
+
+ for (sp = 1, s = pool->solvables + sp; sp < pool->nsolvables; sp++, s++)
+ {
+ if (!s->repo || (oldinstalled && s->repo == oldinstalled))
+ continue;
+ if (!MAPTST(installedmap, sp))
+ continue;
+ change += repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
+ }
+ if (oldinstalled)
+ {
+ FOR_REPO_SOLVABLES(oldinstalled, sp, s)
+ {
+ if (MAPTST(installedmap, sp))
+ continue;
+ change -= repo_lookup_num(s, SOLVABLE_INSTALLSIZE);
+ }
+ }
+ return change;
+}
+
+/* map:
+ * 1: installed
+ * 2: conflicts with installed
+ * 8: interesting (only true if installed)
+ * 16: undecided
+ */
+
+static inline Id dep2name(Pool *pool, Id dep)
+{
+ while (ISRELDEP(dep))
+ {
+ Reldep *rd = rd = GETRELDEP(pool, dep);
+ dep = rd->name;
+ }
+ return dep;
+}
+
+static inline int providedbyinstalled(Pool *pool, unsigned char *map, Id dep)
+{
+ Id p, *pp;
+ int r = 0;
+ FOR_PROVIDES(p, pp, dep)
+ {
+ if (p == SYSTEMSOLVABLE)
+ return 1; /* always boring, as never constraining */
+ if ((map[p] & 9) == 9)
+ return 9;
+ r |= map[p] & 17;
+ }
+ return r;
+}
+
+/*
+ * pool_trivial_installable - calculate if a set of solvables is
+ * trivial installable without any other installs/deinstalls of
+ * packages not belonging to the set.
+ *
+ * the state is returned in the result queue:
+ * 1: solvable is installable without any other package changes
+ * 0: solvable is not installable
+ * -1: solvable is installable, but doesn't constrain any installed packages
+ */
+
+void
+pool_trivial_installable(Pool *pool, Repo *oldinstalled, Map *installedmap, Queue *pkgs, Queue *res)
+{
+ int i, r, m, did;
+ Id p, *dp, con, *conp, req, *reqp;
+ unsigned char *map;
+ Solvable *s;
+
+ map = sat_calloc(pool->nsolvables, 1);
+ for (p = 1; p < pool->nsolvables; p++)
+ {
+ if (!MAPTST(installedmap, p))
+ continue;
+ map[p] |= 9;
+ s = pool->solvables + p;
+ if (!s->conflicts)
+ continue;
+ conp = s->repo->idarraydata + s->conflicts;
+ while ((con = *conp++) != 0)
+ {
+ dp = pool_whatprovides(pool, con);
+ for (; *dp; dp++)
+ map[p] |= 2; /* XXX: self conflict ? */
+ }
+ }
+ for (i = 0; i < pkgs->count; i++)
+ map[pkgs->elements[i]] = 16;
+
+ for (i = 0, did = 0; did < pkgs->count; i++, did++)
+ {
+ if (i == pkgs->count)
+ i = 0;
+ p = pkgs->elements[i];
+ if ((map[p] & 16) == 0)
+ continue;
+ if ((map[p] & 2) != 0)
+ {
+ map[p] = 2;
+ continue;
+ }
+ s = pool->solvables + p;
+ m = 1;
+ if (s->requires)
+ {
+ reqp = s->repo->idarraydata + s->requires;
+ while ((req = *reqp++) != 0)
+ {
+ if (req == SOLVABLE_PREREQMARKER)
+ continue;
+ r = providedbyinstalled(pool, map, req);
+ if (!r)
{
- mp = dirmap[-id];
- continue;
+ /* decided and miss */
+ map[p] = 2;
+ break;
}
- if (mp < 0)
+ m |= r; /* 1 | 9 | 16 | 17 */
+ }
+ if (req)
+ continue;
+ if ((m & 9) == 9)
+ m = 9;
+ }
+ if (s->conflicts)
+ {
+ conp = s->repo->idarraydata + s->conflicts;
+ while ((con = *conp++) != 0)
+ {
+ if ((providedbyinstalled(pool, map, con) & 1) != 0)
{
- /* unconnected */
- dirmap[dn] = mp;
- continue;
+ map[p] = 2;
+ break;
}
- if (!mptree[mp].child)
+ if ((m == 1 || m == 17) && ISRELDEP(con))
{
- dirmap[dn] = -mp;
- continue;
+ con = dep2name(pool, con);
+ if ((providedbyinstalled(pool, map, con) & 1) != 0)
+ m = 9;
}
- comp = id2str(pool, id);
- compl = strlen(comp);
- for (i = mptree[mp].child; i; i = mptree[i].sibling)
- if (mptree[i].compl == compl && !strncmp(mptree[i].comp, comp, compl))
- break;
- dirmap[dn] = i ? i : -mp;
}
- /* change dirmap to point to mountpoint instead of mptree */
- for (dn = 0; dn < pool->ndirs; dn++)
- {
- mp = dirmap[i];
- dirmap[i] = mptree[mp > 0 ? mp : -mp].mountpoint;
- }
-
- cbdata.nmap = pool->ndirs;
- cbdata.dirmap = dirmap;
-
- md.callback = pool_fill_DU_add_cb;
- for_solvables_to_be_installed()
+ if (con)
+ continue; /* found a conflict */
+ }
+#if 0
+ if (s->repo && s->repo != oldinstalled)
+ {
+ Id p2, obs, *obsp, *pp;
+ Solvable *s2;
+ if (s->obsoletes)
{
- if (p < data->start || p >= data->end)
+ obsp = s->repo->idarraydata + s->obsoletes;
+ while ((obs = *obsp++) != 0)
+ {
+ if ((providedbyinstalled(pool, map, obs) & 1) != 0)
+ {
+ map[p] = 2;
+ break;
+ }
+ }
+ if (obs)
continue;
- repodata_search(data, p - data->start, SOLVABLE_DUDATA, &md);
}
- md.callback = pool_fill_DU_sub_cb;
- for_solvables_to_be_erased()
+ FOR_PROVIDES(p2, pp, s->name)
{
- if (p < data->start || p >= data->end)
- continue;
- repodata_search(data, p - data->start, SOLVABLE_DUDATA, &md);
+ s2 = pool->solvables + p2;
+ if (s2->name == s->name && (map[p2] & 1) != 0)
+ {
+ map[p] = 2;
+ break;
+ }
}
-
- cbdata.dirmap = 0;
- cbdata.nmap = 0;
- sat_free(dirmap);
+ if (p2)
+ continue;
}
+#endif
+ if (m != map[p])
+ {
+ map[p] = m;
+ did = 0;
+ }
+ }
+ queue_free(res);
+ queue_clone(res, pkgs);
+ for (i = 0; i < pkgs->count; i++)
+ {
+ m = map[pkgs->elements[i]];
+ if ((m & 9) == 9)
+ r = 1;
+ else if (m & 1)
+ r = -1;
+ else
+ r = 0;
+ res->elements[i] = r;
}
+ free(map);
}
-#endif
-
// EOF