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_idarray(Solvable *s, Id keyname, Queue *q)
54 dataiterator_init(&di, s->repo->pool, s->repo, s - s->repo->pool->solvables, keyname, 0, SEARCH_ARRAYSENTINEL);
55 while (dataiterator_step(&di))
57 if (di.key->type != REPOKEY_TYPE_IDARRAY && di.key->type != REPOKEY_TYPE_REL_IDARRAY)
62 queue_push(q, di.kv.id);
64 dataiterator_free(&di);
69 solvable_lookup_str(Solvable *s, Id keyname)
73 return repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
77 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname)
80 const char *str, *basestr;
88 str = solvable_lookup_str(s, keyname);
89 if (str || keyname == basekeyname)
91 basestr = solvable_lookup_str(s, basekeyname);
94 /* search for a solvable with same name and same base that has the
96 if (!pool->whatprovides)
98 /* we do this in two passes, first same vendor, then all other vendors */
99 for (pass = 0; pass < 2; pass++)
101 FOR_PROVIDES(p, pp, s->name)
103 s2 = pool->solvables + p;
104 if (s2->name != s->name)
106 if ((s->vendor == s2->vendor) != (pass == 0))
108 str = solvable_lookup_str(s2, basekeyname);
109 if (!str || strcmp(str, basestr))
111 str = solvable_lookup_str(s2, keyname);
120 solvable_lookup_str_poollang(Solvable *s, Id keyname)
129 pool = s->repo->pool;
130 if (!pool->nlanguages)
131 return solvable_lookup_str(s, keyname);
132 cols = pool->nlanguages + 1;
133 if (!pool->languagecache)
135 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
136 pool->languagecacheother = 0;
138 if (keyname >= ID_NUM_INTERNAL)
140 row = pool->languagecache + ID_NUM_INTERNAL * cols;
141 for (i = 0; i < pool->languagecacheother; i++, row += cols)
144 if (i >= pool->languagecacheother)
146 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
147 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
152 row = pool->languagecache + keyname * cols;
153 row++; /* skip keyname */
154 for (i = 0; i < pool->nlanguages; i++, row++)
161 kn = id2str(pool, keyname);
162 p = sat_malloc(strlen(kn) + strlen(pool->languages[i]) + 2);
163 sprintf(p, "%s:%s", kn, pool->languages[i]);
164 *row = str2id(pool, p, 1);
167 str = solvable_lookup_str_base(s, *row, keyname);
171 return solvable_lookup_str(s, keyname);
175 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang)
180 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
181 if (id && (str = solvable_lookup_str_base(s, id, keyname)) != 0)
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)
206 Repo *repo = s->repo;
214 n = s - pool->solvables;
215 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
217 if (n < data->start || n >= data->end)
219 /* there are two ways of storing a bool, as num == 1 or void */
220 for (j = 1; j < data->nkeys; j++)
222 if (data->keys[j].name == keyname
223 && (data->keys[j].type == REPOKEY_TYPE_U32
224 || data->keys[j].type == REPOKEY_TYPE_NUM
225 || data->keys[j].type == REPOKEY_TYPE_CONSTANT
226 || data->keys[j].type == REPOKEY_TYPE_VOID))
229 if (repodata_lookup_num(data, n, keyname, &value))
231 if (repodata_lookup_void(data, n, keyname))
239 const unsigned char *
240 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
242 Repo *repo = s->repo;
249 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
253 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
255 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
256 /* we need the repodata just as a reference for a pool */
257 return chk ? repodata_chk2str(s->repo->repodata, *typep, chk) : 0;
260 static inline const char *
261 evrid2vrstr(Pool *pool, Id evrid)
263 const char *p, *evr = id2str(pool, evrid);
266 for (p = evr; *p >= '0' && *p <= '9'; p++)
268 return p != evr && *p == ':' ? p + 1 : evr;
272 solvable_get_location(Solvable *s, unsigned int *medianrp)
277 const char *mediadir, *mediafile;
282 pool = s->repo->pool;
283 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
284 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
285 mediadir = id2str(pool, s->arch);
287 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
289 l = strlen(mediadir) + 1;
290 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
292 const char *name, *evr, *arch;
293 name = id2str(pool, s->name);
294 evr = evrid2vrstr(pool, s->evr);
295 arch = id2str(pool, s->arch);
296 /* name-vr.arch.rpm */
297 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
299 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
301 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
305 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
308 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
310 sprintf(loc, "%s/%s", mediadir, mediafile);
312 strcpy(loc, mediafile);
317 /*****************************************************************************/
319 static inline Id dep2name(Pool *pool, Id dep)
321 while (ISRELDEP(dep))
323 Reldep *rd = rd = GETRELDEP(pool, dep);
329 static inline int providedbyinstalled(Pool *pool, Map *installed, Id dep)
332 FOR_PROVIDES(p, pp, dep)
334 if (p == SYSTEMSOLVABLE)
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)
361 Pool *pool = s->repo->pool;
367 int r, interesting = 0;
369 if (conflictsmap && MAPTST(conflictsmap, s - pool->solvables))
373 reqp = s->repo->idarraydata + s->requires;
374 while ((req = *reqp++) != 0)
376 if (req == SOLVABLE_PREREQMARKER)
378 r = providedbyinstalled(pool, installedmap, req);
387 conp = s->repo->idarraydata + s->conflicts;
388 while ((con = *conp++) != 0)
390 if (providedbyinstalled(pool, installedmap, con))
392 if (!interesting && ISRELDEP(con))
394 con = dep2name(pool, con);
395 if (providedbyinstalled(pool, installedmap, con))
403 if (s->obsoletes && s->repo != installed)
405 obsp = s->repo->idarraydata + s->obsoletes;
406 while ((obs = *obsp++) != 0)
408 if (providedbyinstalled(pool, installedmap, obs))
412 if (s->repo != installed)
414 FOR_PROVIDES(p, pp, s->name)
416 s2 = pool->solvables + p;
417 if (s2->repo == installed && s2->name == s->name)
426 p = s - pool->solvables;
427 for (i = 1; i < pool->nsolvables; i++)
429 if (!MAPTST(installedmap, i))
431 s2 = pool->solvables + i;
434 conp = s2->repo->idarraydata + s2->conflicts;
435 while ((con = *conp++) != 0)
437 dp = pool_whatprovides_ptr(pool, con);
444 return interesting ? 1 : -1;
448 * different interface for solvable_trivial_installable_map, where
449 * the information about the installed packages is provided
453 solvable_trivial_installable_queue(Solvable *s, Queue *installed)
455 Pool *pool = s->repo->pool;
461 map_init(&installedmap, pool->nsolvables);
462 for (i = 0; i < installed->count; i++)
464 p = installed->elements[i];
465 if (p > 0) /* makes it work with decisionq */
466 MAPSET(&installedmap, p);
468 r = solvable_trivial_installable_map(s, &installedmap, 0);
469 map_free(&installedmap);
474 * different interface for solvable_trivial_installable_map, where
475 * the information about the installed packages is provided
476 * by a repo containing the installed solvables.
479 solvable_trivial_installable_repo(Solvable *s, Repo *installed)
481 Pool *pool = s->repo->pool;
487 map_init(&installedmap, pool->nsolvables);
488 FOR_REPO_SOLVABLES(installed, p, s2)
489 MAPSET(&installedmap, p);
490 r = solvable_trivial_installable_map(s, &installedmap, 0);
491 map_free(&installedmap);
496 /*****************************************************************************/
499 * Create maps containing the state of each solvable. Input is a "installed" queue,
500 * it contains all solvable ids that are considered to be installed.
502 * The created maps can be used for solvable_trivial_installable_map(),
503 * pool_calc_duchanges(), pool_calc_installsizechange().
507 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
514 map_init(installedmap, pool->nsolvables);
516 map_init(conflictsmap, pool->nsolvables);
517 for (i = 0; i < installed->count; i++)
519 p = installed->elements[i];
520 if (p <= 0) /* makes it work with decisionq */
522 MAPSET(installedmap, p);
525 s = pool->solvables + p;
528 conp = s->repo->idarraydata + s->conflicts;
529 while ((con = *conp++) != 0)
531 dp = pool_whatprovides_ptr(pool, con);
533 MAPSET(conflictsmap, *dp);
538 /* Tests if two solvables have identical content. Currently
539 * both solvables need to come from the same pool */
542 solvable_identical(Solvable *s1, Solvable *s2)
544 unsigned int bt1, bt2;
548 if (s1->name != s2->name)
550 if (s1->arch != s2->arch)
552 if (s1->evr != s2->evr)
554 /* map missing vendor to empty string */
555 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
558 /* looking good, try some fancier stuff */
559 /* might also look up the package checksum here */
560 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
561 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
569 /* look at requires in a last attempt to find recompiled packages */
572 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
575 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
583 /* return the self provide dependency of a solvable */
585 solvable_selfprovidedep(Solvable *s)
593 pool = s->repo->pool;
596 provp = s->repo->idarraydata + s->provides;
597 while ((prov = *provp++) != 0)
601 rd = GETRELDEP(pool, prov);
602 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
606 return rel2id(pool, s->name, s->evr, REL_EQ, 1);