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_str(Solvable *s, Id keyname)
50 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
54 solvable_lookup_str_poollang(Solvable *s, Id keyname)
64 if (!pool->nlanguages)
65 return solvable_lookup_str(s, keyname);
66 cols = pool->nlanguages + 1;
67 if (!pool->languagecache)
69 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
70 pool->languagecacheother = 0;
72 if (keyname >= ID_NUM_INTERNAL)
74 row = pool->languagecache + ID_NUM_INTERNAL * cols;
75 for (i = 0; i < pool->languagecacheother; i++, row += cols)
78 if (i >= pool->languagecacheother)
80 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
81 pool->languagecacheother++;
82 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
86 row = pool->languagecache + keyname * cols;
87 row++; /* skip keyname */
88 for (i = 0; i < pool->nlanguages; i++, row++)
95 kn = id2str(pool, keyname);
96 p = sat_malloc(strlen(kn) + strlen(pool->languages[i]) + 2);
97 sprintf(p, "%s:%s", kn, pool->languages[i]);
98 *row = str2id(pool, p, 1);
101 str = solvable_lookup_str(s, *row);
105 return solvable_lookup_str(s, keyname);
109 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang)
114 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
115 if (id && (str = solvable_lookup_str(s, id)) != 0)
118 return solvable_lookup_str(s, keyname);
122 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
126 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
130 solvable_lookup_void(Solvable *s, Id keyname)
134 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
138 solvable_lookup_bool(Solvable *s, Id keyname)
140 Repo *repo = s->repo;
148 n = s - pool->solvables;
149 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
151 if (n < data->start || n >= data->end)
153 /* there are two ways of storing a bool, as num == 1 or void */
154 for (j = 1; j < data->nkeys; j++)
156 if (data->keys[j].name == keyname
157 && (data->keys[j].type == REPOKEY_TYPE_U32
158 || data->keys[j].type == REPOKEY_TYPE_NUM
159 || data->keys[j].type == REPOKEY_TYPE_CONSTANT
160 || data->keys[j].type == REPOKEY_TYPE_VOID))
163 if (repodata_lookup_num(data, n, keyname, &value))
165 if (repodata_lookup_void(data, n, keyname))
173 const unsigned char *
174 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
176 Repo *repo = s->repo;
183 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
187 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
189 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
190 /* we need the repodata just as a reference for a pool */
191 return chk ? repodata_chk2str(s->repo->repodata, *typep, chk) : 0;
194 static inline const char *
195 evrid2vrstr(Pool *pool, Id evrid)
197 const char *p, *evr = id2str(pool, evrid);
200 for (p = evr; *p >= '0' && *p <= '9'; p++)
202 return p != evr && *p == ':' ? p + 1 : evr;
206 solvable_get_location(Solvable *s, unsigned int *medianrp)
211 const char *mediadir, *mediafile;
216 pool = s->repo->pool;
217 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
218 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
219 mediadir = id2str(pool, s->arch);
221 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
223 l = strlen(mediadir) + 1;
224 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
226 const char *name, *evr, *arch;
227 name = id2str(pool, s->name);
228 evr = evrid2vrstr(pool, s->evr);
229 arch = id2str(pool, s->arch);
230 /* name-vr.arch.rpm */
231 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
233 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
235 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
239 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
242 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
244 sprintf(loc, "%s/%s", mediadir, mediafile);
246 strcpy(loc, mediafile);
251 /*****************************************************************************/
253 static inline Id dep2name(Pool *pool, Id dep)
255 while (ISRELDEP(dep))
257 Reldep *rd = rd = GETRELDEP(pool, dep);
263 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
266 FOR_PROVIDES(p, pp, dep)
268 if (p == SYSTEMSOLVABLE)
270 if (MAPTST(installed, p))
277 * solvable_trivial_installable_map - anwers is a solvable is installable
278 * without any other installs/deinstalls.
279 * The packages considered to be installed are provided via the
280 * installedmap bitmap. A additional "conflictsmap" bitmap providing
281 * information about the conflicts of the installed packages can be
282 * used for extra speed up. Provide a NULL pointer if you do not
283 * have this information.
284 * Both maps can be created with pool_create_state_maps() or
285 * solver_create_state_maps().
288 * 1: solvable is installable without any other package changes
289 * 0: solvable is not installable
290 * -1: solvable is installable, but doesn't constrain any installed packages
293 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap)
295 Pool *pool = s->repo->pool;
301 int r, interesting = 0;
303 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
307 reqp = s->repo->idarraydata + s->requires;
308 while ((req = *reqp++) != 0)
310 if (req == SOLVABLE_PREREQMARKER)
312 r = providedbyinstalled(pool, installedmap, req);
321 conp = s->repo->idarraydata + s->conflicts;
322 while ((con = *conp++) != 0)
324 if (providedbyinstalled(pool, installedmap, con))
326 if (!interesting && ISRELDEP(con))
328 con = dep2name(pool, con);
329 if (providedbyinstalled(pool, installedmap, con))
337 if (s->obsoletes && s->repo != installed)
339 obsp = s->repo->idarraydata + s->obsoletes;
340 while ((obs = *obsp++) != 0)
342 if (providedbyinstalled(pool, installedmap, obs))
346 if (s->repo != installed)
348 FOR_PROVIDES(p, pp, s->name)
350 s2 = pool->solvables + p;
351 if (s2->repo == installed && s2->name == s->name)
360 p = s - pool->solvables;
361 for (i = 1; i < pool->nsolvables; i++)
363 if (!MAPTST(installedmap, i))
365 s2 = pool->solvables + i;
368 conp = s2->repo->idarraydata + s2->conflicts;
369 while ((con = *conp++) != 0)
371 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
378 return interesting ? 1 : -1;
382 * different interface for solvable_trivial_installable_map, where
383 * the information about the installed packages is provided
387 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
389 Pool *pool = s->repo->pool;
395 map_init(&installedmap, pool->nsolvables);
396 for (i = 0; i < installed->count; i++)
398 p = installed->elements[i];
399 if (p > 0) /* makes it work with decisionq */
400 MAPSET(&installedmap, p);
402 r = solvable_trivial_installable_map(s, &installedmap, 0);
403 map_free(&installedmap);
408 * different interface for solvable_trivial_installable_map, where
409 * the information about the installed packages is provided
410 * by a repo containing the installed solvables.
413 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
415 Pool *pool = s->repo->pool;
421 map_init(&installedmap, pool->nsolvables);
422 FOR_REPO_SOLVABLES(installed, p, s2)
423 MAPSET(&installedmap, p);
424 r = solvable_trivial_installable_map(s, &installedmap, 0);
425 map_free(&installedmap);
430 /*****************************************************************************/
433 * Create maps containing the state of each solvable. Input is a "installed" queue,
434 * it contains all solvable ids that are considered to be installed.
436 * The created maps can be used for solvable_trivial_installable_map(),
437 * pool_calc_duchanges(), pool_calc_installsizechange().
441 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
448 map_init(installedmap, pool->nsolvables);
450 map_init(conflictsmap, pool->nsolvables);
451 for (i = 0; i < installed->count; i++)
453 p = installed->elements[i];
454 if (p <= 0) /* makes it work with decisionq */
456 MAPSET(installedmap, p);
459 s = pool->solvables + p;
462 conp = s->repo->idarraydata + s->conflicts;
463 while ((con = *conp++) != 0)
465 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
467 MAPSET(conflictsmap, *dp);
472 /* Tests if two solvables have identical content. Currently
473 * both solvables need to come from the same pool */
476 solvable_identical(Solvable *s1, Solvable *s2)
478 unsigned int bt1, bt2;
482 if (s1->name != s2->name)
484 if (s1->arch != s2->arch)
486 if (s1->evr != s2->evr)
488 if (s1->vendor != s2->vendor)
491 /* looking good, try some fancier stuff */
492 /* might also look up the package checksum here */
493 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
494 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
502 /* look at requires in a last attempt to find recompiled packages */
505 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
508 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)