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)
55 dataiterator_init(&di, s->repo->pool, s->repo, s - s->repo->pool->solvables, keyname, 0, SEARCH_ARRAYSENTINEL);
56 while (dataiterator_step(&di))
58 if (di.key->type != REPOKEY_TYPE_IDARRAY && di.key->type != REPOKEY_TYPE_REL_IDARRAY)
63 queue_push(q, di.kv.id);
65 dataiterator_free(&di);
70 solvable_lookup_str(Solvable *s, Id keyname)
74 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
78 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname, int usebase)
81 const char *str, *basestr;
89 str = solvable_lookup_str(s, keyname);
90 if (str || keyname == basekeyname)
92 basestr = solvable_lookup_str(s, basekeyname);
95 /* search for a solvable with same name and same base that has the
97 if (!pool->whatprovides)
98 return usebase ? basestr : 0;
99 /* we do this in two passes, first same vendor, then all other vendors */
100 for (pass = 0; pass < 2; pass++)
102 FOR_PROVIDES(p, pp, s->name)
104 s2 = pool->solvables + p;
105 if (s2->name != s->name)
107 if ((s->vendor == s2->vendor) != (pass == 0))
109 str = solvable_lookup_str(s2, basekeyname);
110 if (!str || strcmp(str, basestr))
112 str = solvable_lookup_str(s2, keyname);
117 return usebase ? basestr : 0;
121 solvable_lookup_str_poollang(Solvable *s, Id keyname)
130 pool = s->repo->pool;
131 if (!pool->nlanguages)
132 return solvable_lookup_str(s, keyname);
133 cols = pool->nlanguages + 1;
134 if (!pool->languagecache)
136 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
137 pool->languagecacheother = 0;
139 if (keyname >= ID_NUM_INTERNAL)
141 row = pool->languagecache + ID_NUM_INTERNAL * cols;
142 for (i = 0; i < pool->languagecacheother; i++, row += cols)
145 if (i >= pool->languagecacheother)
147 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
148 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
153 row = pool->languagecache + keyname * cols;
154 row++; /* skip keyname */
155 for (i = 0; i < pool->nlanguages; i++, row++)
158 *row = pool_id2langid(pool, keyname, pool->languages[i], 1);
159 str = solvable_lookup_str_base(s, *row, keyname, 0);
163 return solvable_lookup_str(s, keyname);
167 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase)
171 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
173 return solvable_lookup_str_base(s, id, keyname, usebase);
177 return solvable_lookup_str(s, keyname);
181 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
185 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
189 solvable_lookup_void(Solvable *s, Id keyname)
193 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
197 solvable_lookup_bool(Solvable *s, Id keyname)
201 /* historic nonsense: there are two ways of storing a bool, as num == 1 or void. test both. */
202 if (repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname) == REPOKEY_TYPE_VOID)
204 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, 0) == 1;
207 const unsigned char *
208 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
210 Repo *repo = s->repo;
217 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
221 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
223 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
224 return chk ? pool_bin2hex(s->repo->pool, chk, sat_chksum_len(*typep)) : 0;
227 static inline const char *
228 evrid2vrstr(Pool *pool, Id evrid)
230 const char *p, *evr = id2str(pool, evrid);
233 for (p = evr; *p >= '0' && *p <= '9'; p++)
235 return p != evr && *p == ':' ? p + 1 : evr;
239 solvable_get_location(Solvable *s, unsigned int *medianrp)
244 const char *mediadir, *mediafile;
249 pool = s->repo->pool;
250 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
251 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
252 mediadir = id2str(pool, s->arch);
254 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
256 l = strlen(mediadir) + 1;
257 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
259 const char *name, *evr, *arch;
260 name = id2str(pool, s->name);
261 evr = evrid2vrstr(pool, s->evr);
262 arch = id2str(pool, s->arch);
263 /* name-vr.arch.rpm */
264 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
266 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
268 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
272 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
275 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
277 sprintf(loc, "%s/%s", mediadir, mediafile);
279 strcpy(loc, mediafile);
284 /*****************************************************************************/
286 static inline Id dep2name(Pool *pool, Id dep)
288 while (ISRELDEP(dep))
290 Reldep *rd = rd = GETRELDEP(pool, dep);
296 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
299 FOR_PROVIDES(p, pp, dep)
301 if (p == SYSTEMSOLVABLE)
303 if (MAPTST(installed, p))
310 * solvable_trivial_installable_map - anwers is a solvable is installable
311 * without any other installs/deinstalls.
312 * The packages considered to be installed are provided via the
313 * installedmap bitmap. A additional "conflictsmap" bitmap providing
314 * information about the conflicts of the installed packages can be
315 * used for extra speed up. Provide a NULL pointer if you do not
316 * have this information.
317 * Both maps can be created with pool_create_state_maps() or
318 * solver_create_state_maps().
321 * 1: solvable is installable without any other package changes
322 * 0: solvable is not installable
323 * -1: solvable is installable, but doesn't constrain any installed packages
326 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap)
328 Pool *pool = s->repo->pool;
334 int r, interesting = 0;
336 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
340 reqp = s->repo->idarraydata + s->requires;
341 while ((req = *reqp++) != 0)
343 if (req == SOLVABLE_PREREQMARKER)
345 r = providedbyinstalled(pool, installedmap, req);
354 conp = s->repo->idarraydata + s->conflicts;
355 while ((con = *conp++) != 0)
357 if (providedbyinstalled(pool, installedmap, con))
359 if (!interesting && ISRELDEP(con))
361 con = dep2name(pool, con);
362 if (providedbyinstalled(pool, installedmap, con))
370 if (s->obsoletes && s->repo != installed)
372 obsp = s->repo->idarraydata + s->obsoletes;
373 while ((obs = *obsp++) != 0)
375 if (providedbyinstalled(pool, installedmap, obs))
379 if (s->repo != installed)
381 FOR_PROVIDES(p, pp, s->name)
383 s2 = pool->solvables + p;
384 if (s2->repo == installed && s2->name == s->name)
393 p = s - pool->solvables;
394 for (i = 1; i < pool->nsolvables; i++)
396 if (!MAPTST(installedmap, i))
398 s2 = pool->solvables + i;
401 conp = s2->repo->idarraydata + s2->conflicts;
402 while ((con = *conp++) != 0)
404 dp = pool_whatprovides_ptr(pool, con);
411 return interesting ? 1 : -1;
415 * different interface for solvable_trivial_installable_map, where
416 * the information about the installed packages is provided
420 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
422 Pool *pool = s->repo->pool;
428 map_init(&installedmap, pool->nsolvables);
429 for (i = 0; i < installed->count; i++)
431 p = installed->elements[i];
432 if (p > 0) /* makes it work with decisionq */
433 MAPSET(&installedmap, p);
435 r = solvable_trivial_installable_map(s, &installedmap, 0);
436 map_free(&installedmap);
441 * different interface for solvable_trivial_installable_map, where
442 * the information about the installed packages is provided
443 * by a repo containing the installed solvables.
446 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
448 Pool *pool = s->repo->pool;
454 map_init(&installedmap, pool->nsolvables);
455 FOR_REPO_SOLVABLES(installed, p, s2)
456 MAPSET(&installedmap, p);
457 r = solvable_trivial_installable_map(s, &installedmap, 0);
458 map_free(&installedmap);
463 /*****************************************************************************/
466 * Create maps containing the state of each solvable. Input is a "installed" queue,
467 * it contains all solvable ids that are considered to be installed.
469 * The created maps can be used for solvable_trivial_installable_map(),
470 * pool_calc_duchanges(), pool_calc_installsizechange().
474 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
481 map_init(installedmap, pool->nsolvables);
483 map_init(conflictsmap, pool->nsolvables);
484 for (i = 0; i < installed->count; i++)
486 p = installed->elements[i];
487 if (p <= 0) /* makes it work with decisionq */
489 MAPSET(installedmap, p);
492 s = pool->solvables + p;
495 conp = s->repo->idarraydata + s->conflicts;
496 while ((con = *conp++) != 0)
498 dp = pool_whatprovides_ptr(pool, con);
500 MAPSET(conflictsmap, *dp);
505 /* Tests if two solvables have identical content. Currently
506 * both solvables need to come from the same pool */
509 solvable_identical(Solvable *s1, Solvable *s2)
511 unsigned int bt1, bt2;
515 if (s1->name != s2->name)
517 if (s1->arch != s2->arch)
519 if (s1->evr != s2->evr)
521 /* map missing vendor to empty string */
522 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
525 /* looking good, try some fancier stuff */
526 /* might also look up the package checksum here */
527 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
528 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
536 /* look at requires in a last attempt to find recompiled packages */
539 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
542 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
550 /* return the self provide dependency of a solvable */
552 solvable_selfprovidedep(Solvable *s)
560 pool = s->repo->pool;
563 provp = s->repo->idarraydata + s->provides;
564 while ((prov = *provp++) != 0)
568 rd = GETRELDEP(pool, prov);
569 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
573 return rel2id(pool, s->name, s->evr, REL_EQ, 1);