2 * Copyright (c) 2008, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * set/retrieve data from solvables
25 solvable2str(Pool *pool, Solvable *s)
27 const char *n, *e, *a;
29 n = id2str(pool, s->name);
30 e = id2str(pool, s->evr);
31 a = id2str(pool, s->arch);
32 p = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
33 sprintf(p, "%s-%s.%s", n, e, a);
38 solvable_lookup_id(Solvable *s, Id keyname)
42 return repo_lookup_id(s->repo, s - s->repo->pool->solvables, keyname);
46 solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q)
54 dataiterator_init(&di, s->repo->pool, s->repo, s - s->repo->pool->solvables, keyname, 0, SEARCH_ARRAYSENTINEL);
55 while (dataiterator_step(&di))
57 if (di.key->type != REPOKEY_TYPE_IDARRAY && di.key->type != REPOKEY_TYPE_REL_IDARRAY)
62 queue_push(q, di.kv.id);
64 dataiterator_free(&di);
69 solvable_lookup_str(Solvable *s, Id keyname)
73 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
77 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname, int usebase)
80 const char *str, *basestr;
88 str = solvable_lookup_str(s, keyname);
89 if (str || keyname == basekeyname)
91 basestr = solvable_lookup_str(s, basekeyname);
94 /* search for a solvable with same name and same base that has the
96 if (!pool->whatprovides)
97 return usebase ? basestr : 0;
98 /* we do this in two passes, first same vendor, then all other vendors */
99 for (pass = 0; pass < 2; pass++)
101 FOR_PROVIDES(p, pp, s->name)
103 s2 = pool->solvables + p;
104 if (s2->name != s->name)
106 if ((s->vendor == s2->vendor) != (pass == 0))
108 str = solvable_lookup_str(s2, basekeyname);
109 if (!str || strcmp(str, basestr))
111 str = solvable_lookup_str(s2, keyname);
116 return usebase ? basestr : 0;
120 solvable_lookup_str_poollang(Solvable *s, Id keyname)
129 pool = s->repo->pool;
130 if (!pool->nlanguages)
131 return solvable_lookup_str(s, keyname);
132 cols = pool->nlanguages + 1;
133 if (!pool->languagecache)
135 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
136 pool->languagecacheother = 0;
138 if (keyname >= ID_NUM_INTERNAL)
140 row = pool->languagecache + ID_NUM_INTERNAL * cols;
141 for (i = 0; i < pool->languagecacheother; i++, row += cols)
144 if (i >= pool->languagecacheother)
146 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
147 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
152 row = pool->languagecache + keyname * cols;
153 row++; /* skip keyname */
154 for (i = 0; i < pool->nlanguages; i++, row++)
157 *row = pool_id2langid(pool, keyname, pool->languages[i], 1);
158 str = solvable_lookup_str_base(s, *row, keyname, 0);
162 return solvable_lookup_str(s, keyname);
166 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase)
170 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
172 return solvable_lookup_str_base(s, id, keyname, usebase);
176 return solvable_lookup_str(s, keyname);
180 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
184 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
188 solvable_lookup_void(Solvable *s, Id keyname)
192 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
196 solvable_lookup_bool(Solvable *s, Id keyname)
198 Repo *repo = s->repo;
206 n = s - pool->solvables;
207 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
209 if (n < data->start || n >= data->end)
211 /* there are two ways of storing a bool, as num == 1 or void */
212 for (j = 1; j < data->nkeys; j++)
214 if (data->keys[j].name == keyname
215 && (data->keys[j].type == REPOKEY_TYPE_U32
216 || data->keys[j].type == REPOKEY_TYPE_NUM
217 || data->keys[j].type == REPOKEY_TYPE_CONSTANT
218 || data->keys[j].type == REPOKEY_TYPE_VOID))
221 if (repodata_lookup_num(data, n, keyname, &value))
223 if (repodata_lookup_void(data, n, keyname))
231 const unsigned char *
232 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
234 Repo *repo = s->repo;
241 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
245 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
247 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
248 /* we need the repodata just as a reference for a pool */
249 return chk ? repodata_chk2str(s->repo->repodata, *typep, chk) : 0;
252 static inline const char *
253 evrid2vrstr(Pool *pool, Id evrid)
255 const char *p, *evr = id2str(pool, evrid);
258 for (p = evr; *p >= '0' && *p <= '9'; p++)
260 return p != evr && *p == ':' ? p + 1 : evr;
264 solvable_get_location(Solvable *s, unsigned int *medianrp)
269 const char *mediadir, *mediafile;
274 pool = s->repo->pool;
275 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
276 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
277 mediadir = id2str(pool, s->arch);
279 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
281 l = strlen(mediadir) + 1;
282 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
284 const char *name, *evr, *arch;
285 name = id2str(pool, s->name);
286 evr = evrid2vrstr(pool, s->evr);
287 arch = id2str(pool, s->arch);
288 /* name-vr.arch.rpm */
289 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
291 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
293 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
297 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
300 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
302 sprintf(loc, "%s/%s", mediadir, mediafile);
304 strcpy(loc, mediafile);
309 /*****************************************************************************/
311 static inline Id dep2name(Pool *pool, Id dep)
313 while (ISRELDEP(dep))
315 Reldep *rd = rd = GETRELDEP(pool, dep);
321 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
324 FOR_PROVIDES(p, pp, dep)
326 if (p == SYSTEMSOLVABLE)
328 if (MAPTST(installed, p))
335 * solvable_trivial_installable_map - anwers is a solvable is installable
336 * without any other installs/deinstalls.
337 * The packages considered to be installed are provided via the
338 * installedmap bitmap. A additional "conflictsmap" bitmap providing
339 * information about the conflicts of the installed packages can be
340 * used for extra speed up. Provide a NULL pointer if you do not
341 * have this information.
342 * Both maps can be created with pool_create_state_maps() or
343 * solver_create_state_maps().
346 * 1: solvable is installable without any other package changes
347 * 0: solvable is not installable
348 * -1: solvable is installable, but doesn't constrain any installed packages
351 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap)
353 Pool *pool = s->repo->pool;
359 int r, interesting = 0;
361 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
365 reqp = s->repo->idarraydata + s->requires;
366 while ((req = *reqp++) != 0)
368 if (req == SOLVABLE_PREREQMARKER)
370 r = providedbyinstalled(pool, installedmap, req);
379 conp = s->repo->idarraydata + s->conflicts;
380 while ((con = *conp++) != 0)
382 if (providedbyinstalled(pool, installedmap, con))
384 if (!interesting && ISRELDEP(con))
386 con = dep2name(pool, con);
387 if (providedbyinstalled(pool, installedmap, con))
395 if (s->obsoletes && s->repo != installed)
397 obsp = s->repo->idarraydata + s->obsoletes;
398 while ((obs = *obsp++) != 0)
400 if (providedbyinstalled(pool, installedmap, obs))
404 if (s->repo != installed)
406 FOR_PROVIDES(p, pp, s->name)
408 s2 = pool->solvables + p;
409 if (s2->repo == installed && s2->name == s->name)
418 p = s - pool->solvables;
419 for (i = 1; i < pool->nsolvables; i++)
421 if (!MAPTST(installedmap, i))
423 s2 = pool->solvables + i;
426 conp = s2->repo->idarraydata + s2->conflicts;
427 while ((con = *conp++) != 0)
429 dp = pool_whatprovides_ptr(pool, con);
436 return interesting ? 1 : -1;
440 * different interface for solvable_trivial_installable_map, where
441 * the information about the installed packages is provided
445 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
447 Pool *pool = s->repo->pool;
453 map_init(&installedmap, pool->nsolvables);
454 for (i = 0; i < installed->count; i++)
456 p = installed->elements[i];
457 if (p > 0) /* makes it work with decisionq */
458 MAPSET(&installedmap, p);
460 r = solvable_trivial_installable_map(s, &installedmap, 0);
461 map_free(&installedmap);
466 * different interface for solvable_trivial_installable_map, where
467 * the information about the installed packages is provided
468 * by a repo containing the installed solvables.
471 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
473 Pool *pool = s->repo->pool;
479 map_init(&installedmap, pool->nsolvables);
480 FOR_REPO_SOLVABLES(installed, p, s2)
481 MAPSET(&installedmap, p);
482 r = solvable_trivial_installable_map(s, &installedmap, 0);
483 map_free(&installedmap);
488 /*****************************************************************************/
491 * Create maps containing the state of each solvable. Input is a "installed" queue,
492 * it contains all solvable ids that are considered to be installed.
494 * The created maps can be used for solvable_trivial_installable_map(),
495 * pool_calc_duchanges(), pool_calc_installsizechange().
499 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
506 map_init(installedmap, pool->nsolvables);
508 map_init(conflictsmap, pool->nsolvables);
509 for (i = 0; i < installed->count; i++)
511 p = installed->elements[i];
512 if (p <= 0) /* makes it work with decisionq */
514 MAPSET(installedmap, p);
517 s = pool->solvables + p;
520 conp = s->repo->idarraydata + s->conflicts;
521 while ((con = *conp++) != 0)
523 dp = pool_whatprovides_ptr(pool, con);
525 MAPSET(conflictsmap, *dp);
530 /* Tests if two solvables have identical content. Currently
531 * both solvables need to come from the same pool */
534 solvable_identical(Solvable *s1, Solvable *s2)
536 unsigned int bt1, bt2;
540 if (s1->name != s2->name)
542 if (s1->arch != s2->arch)
544 if (s1->evr != s2->evr)
546 /* map missing vendor to empty string */
547 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
550 /* looking good, try some fancier stuff */
551 /* might also look up the package checksum here */
552 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
553 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
561 /* look at requires in a last attempt to find recompiled packages */
564 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
567 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
575 /* return the self provide dependency of a solvable */
577 solvable_selfprovidedep(Solvable *s)
585 pool = s->repo->pool;
588 provp = s->repo->idarraydata + s->provides;
589 while ((prov = *provp++) != 0)
593 rd = GETRELDEP(pool, prov);
594 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
598 return rel2id(pool, s->name, s->evr, REL_EQ, 1);