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
26 pool_solvable2str(Pool *pool, Solvable *s)
28 const char *n, *e, *a;
30 n = pool_id2str(pool, s->name);
31 e = pool_id2str(pool, s->evr);
32 a = pool_id2str(pool, s->arch);
33 p = pool_alloctmpspace(pool, strlen(n) + strlen(e) + strlen(a) + 3);
34 sprintf(p, "%s-%s.%s", n, e, a);
39 solvable_lookup_type(Solvable *s, Id keyname)
43 return repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname);
47 solvable_lookup_id(Solvable *s, Id keyname)
51 return repo_lookup_id(s->repo, s - s->repo->pool->solvables, keyname);
55 solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q)
62 return repo_lookup_idarray(s->repo, s - s->repo->pool->solvables, keyname, q);
66 solvable_lookup_deparray(Solvable *s, Id keyname, Queue *q, Id marker)
73 return repo_lookup_deparray(s->repo, s - s->repo->pool->solvables, keyname, q, marker);
77 solvable_lookup_str(Solvable *s, Id keyname)
81 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
85 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname, int usebase)
88 const char *str, *basestr;
96 str = solvable_lookup_str(s, keyname);
97 if (str || keyname == basekeyname)
99 basestr = solvable_lookup_str(s, basekeyname);
102 /* search for a solvable with same name and same base that has the
104 if (!pool->whatprovides)
105 return usebase ? basestr : 0;
106 /* we do this in two passes, first same vendor, then all other vendors */
107 for (pass = 0; pass < 2; pass++)
109 FOR_PROVIDES(p, pp, s->name)
111 s2 = pool->solvables + p;
112 if (s2->name != s->name)
114 if ((s->vendor == s2->vendor) != (pass == 0))
116 str = solvable_lookup_str(s2, basekeyname);
117 if (!str || strcmp(str, basestr))
119 str = solvable_lookup_str(s2, keyname);
124 return usebase ? basestr : 0;
128 solvable_lookup_str_poollang(Solvable *s, Id keyname)
137 pool = s->repo->pool;
138 if (!pool->nlanguages)
139 return solvable_lookup_str(s, keyname);
140 cols = pool->nlanguages + 1;
141 if (!pool->languagecache)
143 pool->languagecache = solv_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
144 pool->languagecacheother = 0;
146 if (keyname >= ID_NUM_INTERNAL)
148 row = pool->languagecache + ID_NUM_INTERNAL * cols;
149 for (i = 0; i < pool->languagecacheother; i++, row += cols)
152 if (i >= pool->languagecacheother)
154 pool->languagecache = solv_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
155 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
160 row = pool->languagecache + keyname * cols;
161 row++; /* skip keyname */
162 for (i = 0; i < pool->nlanguages; i++, row++)
165 *row = pool_id2langid(pool, keyname, pool->languages[i], 1);
166 str = solvable_lookup_str_base(s, *row, keyname, 0);
170 return solvable_lookup_str(s, keyname);
174 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase)
178 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
180 return solvable_lookup_str_base(s, id, keyname, usebase);
184 return solvable_lookup_str(s, keyname);
188 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
192 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
196 solvable_lookup_void(Solvable *s, Id keyname)
200 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
204 solvable_lookup_bool(Solvable *s, Id keyname)
208 /* historic nonsense: there are two ways of storing a bool, as num == 1 or void. test both. */
209 if (repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname) == REPOKEY_TYPE_VOID)
211 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, 0) == 1;
214 const unsigned char *
215 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
217 Repo *repo = s->repo;
224 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
228 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
230 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
231 return chk ? pool_bin2hex(s->repo->pool, chk, solv_chksum_len(*typep)) : 0;
234 static inline const char *
235 evrid2vrstr(Pool *pool, Id evrid)
237 const char *p, *evr = pool_id2str(pool, evrid);
240 for (p = evr; *p >= '0' && *p <= '9'; p++)
242 return p != evr && *p == ':' ? p + 1 : evr;
246 solvable_get_location(Solvable *s, unsigned int *medianrp)
251 const char *mediadir, *mediafile;
257 pool = s->repo->pool;
259 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
260 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
261 mediadir = pool_id2str(pool, s->arch);
263 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
265 l = strlen(mediadir) + 1;
266 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
268 const char *name, *evr, *arch;
269 name = pool_id2str(pool, s->name);
270 evr = evrid2vrstr(pool, s->evr);
271 arch = pool_id2str(pool, s->arch);
272 /* name-vr.arch.rpm */
273 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
275 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
277 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
281 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
284 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
286 sprintf(loc, "%s/%s", mediadir, mediafile);
288 strcpy(loc, mediafile);
293 /*****************************************************************************/
295 static inline Id dep2name(Pool *pool, Id dep)
297 while (ISRELDEP(dep))
299 Reldep *rd = rd = GETRELDEP(pool, dep);
305 static int providedbyinstalled_multiversion(Pool *pool, Map *installed, Id n, Id con)
308 Solvable *sn = pool->solvables + n;
310 FOR_PROVIDES(p, pp, sn->name)
312 Solvable *s = pool->solvables + p;
313 if (s->name != sn->name || s->arch != sn->arch)
315 if (!MAPTST(installed, p))
317 if (pool_match_nevr(pool, pool->solvables + p, con))
319 return 1; /* found installed package that doesn't conflict */
324 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep, int ispatch, Map *noobsoletesmap)
327 FOR_PROVIDES(p, pp, dep)
329 if (p == SYSTEMSOLVABLE)
331 if (ispatch && !pool_match_nevr(pool, pool->solvables + p, dep))
333 if (ispatch && noobsoletesmap && noobsoletesmap->size && MAPTST(noobsoletesmap, p) && ISRELDEP(dep))
334 if (providedbyinstalled_multiversion(pool, installed, p, dep))
336 if (MAPTST(installed, p))
343 * solvable_trivial_installable_map - anwers is a solvable is installable
344 * without any other installs/deinstalls.
345 * The packages considered to be installed are provided via the
346 * installedmap bitmap. A additional "conflictsmap" bitmap providing
347 * information about the conflicts of the installed packages can be
348 * used for extra speed up. Provide a NULL pointer if you do not
349 * have this information.
350 * Both maps can be created with pool_create_state_maps() or
351 * solver_create_state_maps().
354 * 1: solvable is installable without any other package changes
355 * 0: solvable is not installable
356 * -1: solvable is installable, but doesn't constrain any installed packages
359 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap, Map *noobsoletesmap)
361 Pool *pool = s->repo->pool;
366 int r, interesting = 0;
368 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
372 reqp = s->repo->idarraydata + s->requires;
373 while ((req = *reqp++) != 0)
375 if (req == SOLVABLE_PREREQMARKER)
377 r = providedbyinstalled(pool, installedmap, req, 0, 0);
388 if (!strncmp("patch:", pool_id2str(pool, s->name), 6))
390 conp = s->repo->idarraydata + s->conflicts;
391 while ((con = *conp++) != 0)
393 if (providedbyinstalled(pool, installedmap, con, ispatch, noobsoletesmap))
395 if (!interesting && ISRELDEP(con))
397 con = dep2name(pool, con);
398 if (providedbyinstalled(pool, installedmap, con, ispatch, noobsoletesmap))
408 if (s->obsoletes && s->repo != installed)
410 obsp = s->repo->idarraydata + s->obsoletes;
411 while ((obs = *obsp++) != 0)
413 if (providedbyinstalled(pool, installedmap, obs, 0, 0))
417 if (s->repo != installed)
420 FOR_PROVIDES(p, pp, s->name)
422 s2 = pool->solvables + p;
423 if (s2->repo == installed && s2->name == s->name)
433 p = s - pool->solvables;
434 for (i = 1; i < pool->nsolvables; i++)
436 if (!MAPTST(installedmap, i))
438 s2 = pool->solvables + i;
441 conp = s2->repo->idarraydata + s2->conflicts;
442 while ((con = *conp++) != 0)
444 dp = pool_whatprovides_ptr(pool, con);
451 return interesting ? 1 : -1;
455 * different interface for solvable_trivial_installable_map, where
456 * the information about the installed packages is provided
460 solvable_trivial_installable_queue(Solvable *s, Queue *installed, Map *noobsoletesmap)
462 Pool *pool = s->repo->pool;
468 map_init(&installedmap, pool->nsolvables);
469 for (i = 0; i < installed->count; i++)
471 p = installed->elements[i];
472 if (p > 0) /* makes it work with decisionq */
473 MAPSET(&installedmap, p);
475 r = solvable_trivial_installable_map(s, &installedmap, 0, noobsoletesmap);
476 map_free(&installedmap);
481 * different interface for solvable_trivial_installable_map, where
482 * the information about the installed packages is provided
483 * by a repo containing the installed solvables.
486 solvable_trivial_installable_repo(Solvable *s, Repo *installed, Map *noobsoletesmap)
488 Pool *pool = s->repo->pool;
494 map_init(&installedmap, pool->nsolvables);
495 FOR_REPO_SOLVABLES(installed, p, s2)
496 MAPSET(&installedmap, p);
497 r = solvable_trivial_installable_map(s, &installedmap, 0, noobsoletesmap);
498 map_free(&installedmap);
503 /*****************************************************************************/
506 * Create maps containing the state of each solvable. Input is a "installed" queue,
507 * it contains all solvable ids that are considered to be installed.
509 * The created maps can be used for solvable_trivial_installable_map(),
510 * pool_calc_duchanges(), pool_calc_installsizechange().
514 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
521 map_init(installedmap, pool->nsolvables);
523 map_init(conflictsmap, pool->nsolvables);
524 for (i = 0; i < installed->count; i++)
526 p = installed->elements[i];
527 if (p <= 0) /* makes it work with decisionq */
529 MAPSET(installedmap, p);
532 s = pool->solvables + p;
535 conp = s->repo->idarraydata + s->conflicts;
536 while ((con = *conp++) != 0)
538 dp = pool_whatprovides_ptr(pool, con);
540 MAPSET(conflictsmap, *dp);
545 /* Tests if two solvables have identical content. Currently
546 * both solvables need to come from the same pool
549 solvable_identical(Solvable *s1, Solvable *s2)
551 unsigned int bt1, bt2;
555 if (s1->name != s2->name)
557 if (s1->arch != s2->arch)
559 if (s1->evr != s2->evr)
561 /* map missing vendor to empty string */
562 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
565 /* looking good, try some fancier stuff */
566 /* might also look up the package checksum here */
567 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
568 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
576 /* look at requires in a last attempt to find recompiled packages */
579 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
582 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
590 /* return the self provide dependency of a solvable */
592 solvable_selfprovidedep(Solvable *s)
600 pool = s->repo->pool;
603 provp = s->repo->idarraydata + s->provides;
604 while ((prov = *provp++) != 0)
608 rd = GETRELDEP(pool, prov);
609 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
613 return pool_rel2id(pool, s->name, s->evr, REL_EQ, 1);
616 /* setter functions, simply call the repo variants */
618 solvable_set_id(Solvable *s, Id keyname, Id id)
620 repo_set_num(s->repo, s - s->repo->pool->solvables, keyname, id);
624 solvable_set_num(Solvable *s, Id keyname, unsigned int num)
626 repo_set_num(s->repo, s - s->repo->pool->solvables, keyname, num);
630 solvable_set_str(Solvable *s, Id keyname, const char *str)
632 repo_set_str(s->repo, s - s->repo->pool->solvables, keyname, str);
636 solvable_set_poolstr(Solvable *s, Id keyname, const char *str)
638 repo_set_poolstr(s->repo, s - s->repo->pool->solvables, keyname, str);
642 solvable_add_poolstr_array(Solvable *s, Id keyname, const char *str)
644 repo_add_poolstr_array(s->repo, s - s->repo->pool->solvables, keyname, str);
648 solvable_add_idarray(Solvable *s, Id keyname, Id id)
650 repo_add_idarray(s->repo, s - s->repo->pool->solvables, keyname, id);
654 solvable_add_deparray(Solvable *s, Id keyname, Id dep, Id marker)
656 repo_add_deparray(s->repo, s - s->repo->pool->solvables, keyname, dep, marker);
660 solvable_set_idarray(Solvable *s, Id keyname, Queue *q)
662 repo_set_idarray(s->repo, s - s->repo->pool->solvables, keyname, q);
666 solvable_set_deparray(Solvable *s, Id keyname, Queue *q, Id marker)
668 repo_set_deparray(s->repo, s - s->repo->pool->solvables, keyname, q, marker);