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;
195 solvable_get_location(Solvable *s, unsigned int *medianrp)
200 const char *mediadir, *mediafile;
205 pool = s->repo->pool;
206 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
207 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
208 mediadir = id2str(pool, s->arch);
210 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
212 l = strlen(mediadir) + 1;
213 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
215 const char *name, *evr, *arch;
216 name = id2str(pool, s->name);
217 evr = id2str(pool, s->evr);
218 arch = id2str(pool, s->arch);
219 /* name-evr.arch.rpm */
220 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
222 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
224 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
228 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
231 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
233 sprintf(loc, "%s/%s", mediadir, mediafile);
235 strcpy(loc, mediafile);
240 /*****************************************************************************/
242 static inline Id dep2name(Pool *pool, Id dep)
244 while (ISRELDEP(dep))
246 Reldep *rd = rd = GETRELDEP(pool, dep);
252 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
255 FOR_PROVIDES(p, pp, dep)
257 if (p == SYSTEMSOLVABLE)
259 if (MAPTST(installed, p))
266 * solvable_trivial_installable_map - anwers is a solvable is installable
267 * without any other installs/deinstalls.
268 * The packages considered to be installed are provided via the
269 * installedmap bitmap. A additional "conflictsmap" bitmap providing
270 * information about the conflicts of the installed packages can be
271 * used for extra speed up. Provide a NULL pointer if you do not
272 * have this information.
273 * Both maps can be created with pool_create_state_maps() or
274 * solver_create_state_maps().
277 * 1: solvable is installable without any other package changes
278 * 0: solvable is not installable
279 * -1: solvable is installable, but doesn't constrain any installed packages
282 solvable_trivial_installable_map(Solvable *s, Map *installedmap, Map *conflictsmap)
284 Pool *pool = s->repo->pool;
290 int r, interesting = 0;
292 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
296 reqp = s->repo->idarraydata + s->requires;
297 while ((req = *reqp++) != 0)
299 if (req == SOLVABLE_PREREQMARKER)
301 r = providedbyinstalled(pool, installedmap, req);
310 conp = s->repo->idarraydata + s->conflicts;
311 while ((con = *conp++) != 0)
313 if (providedbyinstalled(pool, installedmap, con))
315 if (!interesting && ISRELDEP(con))
317 con = dep2name(pool, con);
318 if (providedbyinstalled(pool, installedmap, con))
326 if (s->obsoletes && s->repo != installed)
328 obsp = s->repo->idarraydata + s->obsoletes;
329 while ((obs = *obsp++) != 0)
331 if (providedbyinstalled(pool, installedmap, obs))
335 if (s->repo != installed)
337 FOR_PROVIDES(p, pp, s->name)
339 s2 = pool->solvables + p;
340 if (s2->repo == installed && s2->name == s->name)
349 p = s - pool->solvables;
350 for (i = 1; i < pool->nsolvables; i++)
352 if (!MAPTST(installedmap, i))
354 s2 = pool->solvables + i;
357 conp = s2->repo->idarraydata + s2->conflicts;
358 while ((con = *conp++) != 0)
360 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
367 return interesting ? 1 : -1;
371 * different interface for solvable_trivial_installable_map, where
372 * the information about the installed packages is provided
376 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
378 Pool *pool = s->repo->pool;
384 map_init(&installedmap, pool->nsolvables);
385 for (i = 0; i < installed->count; i++)
387 p = installed->elements[i];
388 if (p > 0) /* makes it work with decisionq */
389 MAPSET(&installedmap, p);
391 r = solvable_trivial_installable_map(s, &installedmap, 0);
392 map_free(&installedmap);
397 * different interface for solvable_trivial_installable_map, where
398 * the information about the installed packages is provided
399 * by a repo containing the installed solvables.
402 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
404 Pool *pool = s->repo->pool;
410 map_init(&installedmap, pool->nsolvables);
411 FOR_REPO_SOLVABLES(installed, p, s2)
412 MAPSET(&installedmap, p);
413 r = solvable_trivial_installable_map(s, &installedmap, 0);
414 map_free(&installedmap);
419 /*****************************************************************************/
422 * Create maps containing the state of each solvable. Input is a "installed" queue,
423 * it contains all solvable ids that are considered to be installed.
425 * The created maps can be used for solvable_trivial_installable_map(),
426 * pool_calc_duchanges(), pool_calc_installsizechange().
430 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
437 map_init(installedmap, pool->nsolvables);
439 map_init(conflictsmap, pool->nsolvables);
440 for (i = 0; i < installed->count; i++)
442 p = installed->elements[i];
443 if (p <= 0) /* makes it work with decisionq */
445 MAPSET(installedmap, p);
448 s = pool->solvables + p;
451 conp = s->repo->idarraydata + s->conflicts;
452 while ((con = *conp++) != 0)
454 dp = pool->whatprovidesdata + pool_whatprovides(pool, con);
456 MAPSET(conflictsmap, *dp);
462 solvable_identical(Pool *pool, Solvable *s1, Solvable *s2)
464 unsigned int bt1, bt2;
468 if (s1->name != s2->name)
470 if (s1->arch != s2->arch)
472 if (s1->evr != s2->evr)
474 if (s1->vendor != s2->vendor)
477 /* looking good, try some fancier stuff */
478 /* might also look up the package checksum here */
479 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
480 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
488 /* look at requires in a last attempt to find recompiled packages */
491 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
494 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)