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 solvable2str(Pool *pool, Solvable *s)
28 const char *n, *e, *a;
30 n = id2str(pool, s->name);
31 e = id2str(pool, s->evr);
32 a = 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_id(Solvable *s, Id keyname)
43 return repo_lookup_id(s->repo, s - s->repo->pool->solvables, keyname);
47 solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q)
54 return repo_lookup_idarray(s->repo, s - s->repo->pool->solvables, keyname, q);
58 solvable_lookup_str(Solvable *s, Id keyname)
62 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
66 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname, int usebase)
69 const char *str, *basestr;
77 str = solvable_lookup_str(s, keyname);
78 if (str || keyname == basekeyname)
80 basestr = solvable_lookup_str(s, basekeyname);
83 /* search for a solvable with same name and same base that has the
85 if (!pool->whatprovides)
86 return usebase ? basestr : 0;
87 /* we do this in two passes, first same vendor, then all other vendors */
88 for (pass = 0; pass < 2; pass++)
90 FOR_PROVIDES(p, pp, s->name)
92 s2 = pool->solvables + p;
93 if (s2->name != s->name)
95 if ((s->vendor == s2->vendor) != (pass == 0))
97 str = solvable_lookup_str(s2, basekeyname);
98 if (!str || strcmp(str, basestr))
100 str = solvable_lookup_str(s2, keyname);
105 return usebase ? basestr : 0;
109 solvable_lookup_str_poollang(Solvable *s, Id keyname)
118 pool = s->repo->pool;
119 if (!pool->nlanguages)
120 return solvable_lookup_str(s, keyname);
121 cols = pool->nlanguages + 1;
122 if (!pool->languagecache)
124 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
125 pool->languagecacheother = 0;
127 if (keyname >= ID_NUM_INTERNAL)
129 row = pool->languagecache + ID_NUM_INTERNAL * cols;
130 for (i = 0; i < pool->languagecacheother; i++, row += cols)
133 if (i >= pool->languagecacheother)
135 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
136 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
141 row = pool->languagecache + keyname * cols;
142 row++; /* skip keyname */
143 for (i = 0; i < pool->nlanguages; i++, row++)
146 *row = pool_id2langid(pool, keyname, pool->languages[i], 1);
147 str = solvable_lookup_str_base(s, *row, keyname, 0);
151 return solvable_lookup_str(s, keyname);
155 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase)
159 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
161 return solvable_lookup_str_base(s, id, keyname, usebase);
165 return solvable_lookup_str(s, keyname);
169 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
173 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
177 solvable_lookup_void(Solvable *s, Id keyname)
181 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
185 solvable_lookup_bool(Solvable *s, Id keyname)
189 /* historic nonsense: there are two ways of storing a bool, as num == 1 or void. test both. */
190 if (repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname) == REPOKEY_TYPE_VOID)
192 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, 0) == 1;
195 const unsigned char *
196 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
198 Repo *repo = s->repo;
205 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
209 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
211 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
212 return chk ? pool_bin2hex(s->repo->pool, chk, sat_chksum_len(*typep)) : 0;
215 static inline const char *
216 evrid2vrstr(Pool *pool, Id evrid)
218 const char *p, *evr = id2str(pool, evrid);
221 for (p = evr; *p >= '0' && *p <= '9'; p++)
223 return p != evr && *p == ':' ? p + 1 : evr;
227 solvable_get_location(Solvable *s, unsigned int *medianrp)
232 const char *mediadir, *mediafile;
238 pool = s->repo->pool;
240 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
241 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
242 mediadir = id2str(pool, s->arch);
244 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
246 l = strlen(mediadir) + 1;
247 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
249 const char *name, *evr, *arch;
250 name = id2str(pool, s->name);
251 evr = evrid2vrstr(pool, s->evr);
252 arch = id2str(pool, s->arch);
253 /* name-vr.arch.rpm */
254 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
256 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
258 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
262 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
265 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
267 sprintf(loc, "%s/%s", mediadir, mediafile);
269 strcpy(loc, mediafile);
274 /*****************************************************************************/
276 static inline Id dep2name(Pool *pool, Id dep)
278 while (ISRELDEP(dep))
280 Reldep *rd = rd = GETRELDEP(pool, dep);
286 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
289 FOR_PROVIDES(p, pp, dep)
291 if (p == SYSTEMSOLVABLE)
293 if (MAPTST(installed, p))
300 * solvable_trivial_installable_map - anwers is a solvable is installable
301 * without any other installs/deinstalls.
302 * The packages considered to be installed are provided via the
303 * installedmap bitmap. A additional "conflictsmap" bitmap providing
304 * information about the conflicts of the installed packages can be
305 * used for extra speed up. Provide a NULL pointer if you do not
306 * have this information.
307 * Both maps can be created with pool_create_state_maps() or
308 * solver_create_state_maps().
311 * 1: solvable is installable without any other package changes
312 * 0: solvable is not installable
313 * -1: solvable is installable, but doesn't constrain any installed packages
316 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap)
318 Pool *pool = s->repo->pool;
324 int r, interesting = 0;
326 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
330 reqp = s->repo->idarraydata + s->requires;
331 while ((req = *reqp++) != 0)
333 if (req == SOLVABLE_PREREQMARKER)
335 r = providedbyinstalled(pool, installedmap, req);
344 conp = s->repo->idarraydata + s->conflicts;
345 while ((con = *conp++) != 0)
347 if (providedbyinstalled(pool, installedmap, con))
349 if (!interesting && ISRELDEP(con))
351 con = dep2name(pool, con);
352 if (providedbyinstalled(pool, installedmap, con))
360 if (s->obsoletes && s->repo != installed)
362 obsp = s->repo->idarraydata + s->obsoletes;
363 while ((obs = *obsp++) != 0)
365 if (providedbyinstalled(pool, installedmap, obs))
369 if (s->repo != installed)
371 FOR_PROVIDES(p, pp, s->name)
373 s2 = pool->solvables + p;
374 if (s2->repo == installed && s2->name == s->name)
383 p = s - pool->solvables;
384 for (i = 1; i < pool->nsolvables; i++)
386 if (!MAPTST(installedmap, i))
388 s2 = pool->solvables + i;
391 conp = s2->repo->idarraydata + s2->conflicts;
392 while ((con = *conp++) != 0)
394 dp = pool_whatprovides_ptr(pool, con);
401 return interesting ? 1 : -1;
405 * different interface for solvable_trivial_installable_map, where
406 * the information about the installed packages is provided
410 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
412 Pool *pool = s->repo->pool;
418 map_init(&installedmap, pool->nsolvables);
419 for (i = 0; i < installed->count; i++)
421 p = installed->elements[i];
422 if (p > 0) /* makes it work with decisionq */
423 MAPSET(&installedmap, p);
425 r = solvable_trivial_installable_map(s, &installedmap, 0);
426 map_free(&installedmap);
431 * different interface for solvable_trivial_installable_map, where
432 * the information about the installed packages is provided
433 * by a repo containing the installed solvables.
436 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
438 Pool *pool = s->repo->pool;
444 map_init(&installedmap, pool->nsolvables);
445 FOR_REPO_SOLVABLES(installed, p, s2)
446 MAPSET(&installedmap, p);
447 r = solvable_trivial_installable_map(s, &installedmap, 0);
448 map_free(&installedmap);
453 /*****************************************************************************/
456 * Create maps containing the state of each solvable. Input is a "installed" queue,
457 * it contains all solvable ids that are considered to be installed.
459 * The created maps can be used for solvable_trivial_installable_map(),
460 * pool_calc_duchanges(), pool_calc_installsizechange().
464 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
471 map_init(installedmap, pool->nsolvables);
473 map_init(conflictsmap, pool->nsolvables);
474 for (i = 0; i < installed->count; i++)
476 p = installed->elements[i];
477 if (p <= 0) /* makes it work with decisionq */
479 MAPSET(installedmap, p);
482 s = pool->solvables + p;
485 conp = s->repo->idarraydata + s->conflicts;
486 while ((con = *conp++) != 0)
488 dp = pool_whatprovides_ptr(pool, con);
490 MAPSET(conflictsmap, *dp);
495 /* Tests if two solvables have identical content. Currently
496 * both solvables need to come from the same pool
499 solvable_identical(Solvable *s1, Solvable *s2)
501 unsigned int bt1, bt2;
505 if (s1->name != s2->name)
507 if (s1->arch != s2->arch)
509 if (s1->evr != s2->evr)
511 /* map missing vendor to empty string */
512 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
515 /* looking good, try some fancier stuff */
516 /* might also look up the package checksum here */
517 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
518 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
526 /* look at requires in a last attempt to find recompiled packages */
529 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
532 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
540 /* return the self provide dependency of a solvable */
542 solvable_selfprovidedep(Solvable *s)
550 pool = s->repo->pool;
553 provp = s->repo->idarraydata + s->provides;
554 while ((prov = *provp++) != 0)
558 rd = GETRELDEP(pool, prov);
559 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
563 return rel2id(pool, s->name, s->evr, REL_EQ, 1);