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
24 #include "poolvendor.h"
26 #include "linkedpkg.h"
29 pool_solvable2str(Pool *pool, Solvable *s)
31 const char *n, *e, *a;
34 n = pool_id2str(pool, s->name);
35 e = pool_id2str(pool, s->evr);
36 /* XXX: may want to skip the epoch here */
37 a = pool_id2str(pool, s->arch);
41 if (pool->havedistepoch)
43 /* strip the distepoch from the evr */
44 const char *de = strrchr(e, '-');
45 if (de && (de = strchr(de, ':')) != 0)
48 p = pool_alloctmpspace(pool, nl + el + al + 3);
53 strncpy(p + nl, e, el);
58 p[nl + el] = pool->disttype == DISTTYPE_HAIKU ? '-' : '.';
59 strcpy(p + nl + el + 1, a);
65 solvable_lookup_type(Solvable *s, Id keyname)
69 return repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname);
73 solvable_lookup_id(Solvable *s, Id keyname)
77 return repo_lookup_id(s->repo, s - s->repo->pool->solvables, keyname);
81 solvable_lookup_idarray(Solvable *s, Id keyname, Queue *q)
88 return repo_lookup_idarray(s->repo, s - s->repo->pool->solvables, keyname, q);
92 solvable_lookup_deparray(Solvable *s, Id keyname, Queue *q, Id marker)
99 return repo_lookup_deparray(s->repo, s - s->repo->pool->solvables, keyname, q, marker);
103 solvable_lookup_str_joinarray(Solvable *s, Id keyname, const char *joinstr)
109 queue_init_buffer(&q, qbuf, sizeof(qbuf)/sizeof(*qbuf));
110 if (solvable_lookup_idarray(s, keyname, &q) && q.count)
112 Pool *pool = s->repo->pool;
114 str = pool_tmpjoin(pool, pool_id2str(pool, q.elements[0]), 0, 0);
115 for (i = 1; i < q.count; i++)
116 str = pool_tmpappend(pool, str, joinstr, pool_id2str(pool, q.elements[i]));
123 solvable_lookup_str(Solvable *s, Id keyname)
128 str = repo_lookup_str(s->repo, s - s->repo->pool->solvables, keyname);
129 if (!str && (keyname == SOLVABLE_LICENSE || keyname == SOLVABLE_GROUP))
130 str = solvable_lookup_str_joinarray(s, keyname, ", ");
135 solvable_lookup_str_base(Solvable *s, Id keyname, Id basekeyname, int usebase)
138 const char *str, *basestr;
145 pool = s->repo->pool;
146 str = solvable_lookup_str(s, keyname);
147 if (str || keyname == basekeyname)
149 basestr = solvable_lookup_str(s, basekeyname);
152 /* search for a solvable with same name and same base that has the
154 if (!pool->whatprovides)
155 return usebase ? basestr : 0;
157 /* we do this in two passes, first same vendor, then all other vendors */
158 for (pass = 0; pass < 2; pass++)
160 FOR_PROVIDES(p, pp, name)
162 s2 = pool->solvables + p;
163 if (s2->name != name)
165 if ((s->vendor == s2->vendor) != (pass == 0))
167 str = solvable_lookup_str(s2, basekeyname);
168 if (!str || strcmp(str, basestr))
170 str = solvable_lookup_str(s2, keyname);
174 #ifdef ENABLE_LINKED_PKGS
175 /* autopattern/product translation magic */
178 const char *n = pool_id2str(pool, name);
181 if (!strncmp("pattern:", n, 8) && (name = find_autopattern_name(pool, s)) != 0)
183 if (!strncmp("product:", n, 8) && (name = find_autoproduct_name(pool, s)) != 0)
189 return usebase ? basestr : 0;
193 solvable_lookup_str_poollang(Solvable *s, Id keyname)
202 pool = s->repo->pool;
203 if (!pool->nlanguages)
204 return solvable_lookup_str(s, keyname);
205 cols = pool->nlanguages + 1;
206 if (!pool->languagecache)
208 pool->languagecache = solv_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
209 pool->languagecacheother = 0;
211 if (keyname >= ID_NUM_INTERNAL)
213 row = pool->languagecache + ID_NUM_INTERNAL * cols;
214 for (i = 0; i < pool->languagecacheother; i++, row += cols)
217 if (i >= pool->languagecacheother)
219 pool->languagecache = solv_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
220 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
225 row = pool->languagecache + keyname * cols;
226 row++; /* skip keyname */
227 for (i = 0; i < pool->nlanguages; i++, row++)
230 *row = pool_id2langid(pool, keyname, pool->languages[i], 1);
231 str = solvable_lookup_str_base(s, *row, keyname, 0);
235 return solvable_lookup_str(s, keyname);
239 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang, int usebase)
243 Id id = pool_id2langid(s->repo->pool, keyname, lang, 0);
245 return solvable_lookup_str_base(s, id, keyname, usebase);
249 return solvable_lookup_str(s, keyname);
253 solvable_lookup_num(Solvable *s, Id keyname, unsigned long long notfound)
257 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, notfound);
261 solvable_lookup_sizek(Solvable *s, Id keyname, unsigned int notfound)
263 unsigned long long size;
266 size = solvable_lookup_num(s, keyname, (unsigned long long)notfound << 10);
267 return (unsigned int)((size + 1023) >> 10);
271 solvable_lookup_void(Solvable *s, Id keyname)
275 return repo_lookup_void(s->repo, s - s->repo->pool->solvables, keyname);
279 solvable_lookup_bool(Solvable *s, Id keyname)
283 /* historic nonsense: there are two ways of storing a bool, as num == 1 or void. test both. */
284 if (repo_lookup_type(s->repo, s - s->repo->pool->solvables, keyname) == REPOKEY_TYPE_VOID)
286 return repo_lookup_num(s->repo, s - s->repo->pool->solvables, keyname, 0) == 1;
289 const unsigned char *
290 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
292 Repo *repo = s->repo;
299 return repo_lookup_bin_checksum(repo, s - repo->pool->solvables, keyname, typep);
303 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
305 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
306 return chk ? pool_bin2hex(s->repo->pool, chk, solv_chksum_len(*typep)) : 0;
309 static inline const char *
310 evrid2vrstr(Pool *pool, Id evrid)
312 const char *p, *evr = pool_id2str(pool, evrid);
315 for (p = evr; *p >= '0' && *p <= '9'; p++)
317 return p != evr && *p == ':' && p[1] ? p + 1 : evr;
321 solvable_lookup_location(Solvable *s, unsigned int *medianrp)
326 const char *mediadir, *mediafile;
332 pool = s->repo->pool;
334 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 0);
335 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
336 mediadir = pool_id2str(pool, s->arch);
338 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
340 l = strlen(mediadir) + 1;
341 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
343 const char *name, *evr, *arch;
344 name = pool_id2str(pool, s->name);
345 evr = evrid2vrstr(pool, s->evr);
346 arch = pool_id2str(pool, s->arch);
347 /* name-vr.arch.rpm */
348 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
350 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
352 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
356 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
359 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
361 sprintf(loc, "%s/%s", mediadir, mediafile);
363 strcpy(loc, mediafile);
369 solvable_get_location(Solvable *s, unsigned int *medianrp)
371 const char *loc = solvable_lookup_location(s, medianrp);
372 if (medianrp && *medianrp == 0)
373 *medianrp = 1; /* compat, to be removed */
378 solvable_lookup_sourcepkg(Solvable *s)
381 const char *evr, *name;
386 pool = s->repo->pool;
387 if (solvable_lookup_void(s, SOLVABLE_SOURCENAME))
388 name = pool_id2str(pool, s->name);
390 name = solvable_lookup_str(s, SOLVABLE_SOURCENAME);
393 archid = solvable_lookup_id(s, SOLVABLE_SOURCEARCH);
394 if (solvable_lookup_void(s, SOLVABLE_SOURCEEVR))
395 evr = evrid2vrstr(pool, s->evr);
397 evr = solvable_lookup_str(s, SOLVABLE_SOURCEEVR);
398 if (archid == ARCH_SRC || archid == ARCH_NOSRC)
401 str = pool_tmpjoin(pool, name, evr ? "-" : 0, evr);
402 str = pool_tmpappend(pool, str, ".", pool_id2str(pool, archid));
403 return pool_tmpappend(pool, str, ".rpm", 0);
406 return name; /* FIXME */
410 /*****************************************************************************/
413 * Create maps containing the state of each solvable. Input is a "installed" queue,
414 * it contains all solvable ids that are considered to be installed.
416 * The created maps can be used for * pool_calc_duchanges() and
417 * pool_calc_installsizechange().
421 pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap)
428 map_init(installedmap, pool->nsolvables);
430 map_init(conflictsmap, pool->nsolvables);
431 for (i = 0; i < installed->count; i++)
433 p = installed->elements[i];
434 if (p <= 0) /* makes it work with decisionq */
436 MAPSET(installedmap, p);
439 s = pool->solvables + p;
442 conp = s->repo->idarraydata + s->conflicts;
443 while ((con = *conp++) != 0)
445 dp = pool_whatprovides_ptr(pool, con);
447 MAPSET(conflictsmap, *dp);
452 /* Tests if two solvables have identical content. Currently
453 * both solvables need to come from the same pool
457 solvable_identical(Solvable *s1, Solvable *s2)
459 unsigned int bt1, bt2;
462 if (s1->name != s2->name)
464 if (s1->arch != s2->arch)
466 if (s1->evr != s2->evr)
469 /* check vendor, map missing vendor to empty string */
470 if ((s1->vendor ? s1->vendor : 1) != (s2->vendor ? s2->vendor : 1))
472 /* workaround for bug 881493 */
473 if (s1->repo && !strncmp(pool_id2str(s1->repo->pool, s1->name), "product:", 8))
478 /* looking good, try some fancier stuff */
479 /* might also look up the package checksum here */
480 bt1 = solvable_lookup_num(s1, SOLVABLE_BUILDTIME, 0);
481 bt2 = solvable_lookup_num(s2, SOLVABLE_BUILDTIME, 0);
491 /* workaround for bugs 881493 and 885830*/
492 const char *n = pool_id2str(s1->repo->pool, s1->name);
493 if (!strncmp(n, "product:", 8) || !strncmp(n, "application:", 12))
496 /* look at requires in a last attempt to find recompiled packages */
499 for (reqp = s1->repo->idarraydata + s1->requires; *reqp; reqp++)
502 for (reqp = s2->repo->idarraydata + s2->requires; *reqp; reqp++)
510 /* return the self provide dependency of a solvable */
512 solvable_selfprovidedep(Solvable *s)
520 pool = s->repo->pool;
523 provp = s->repo->idarraydata + s->provides;
524 while ((prov = *provp++) != 0)
528 rd = GETRELDEP(pool, prov);
529 if (rd->name == s->name && rd->evr == s->evr && rd->flags == REL_EQ)
533 return pool_rel2id(pool, s->name, s->evr, REL_EQ, 1);
536 /* setter functions, simply call the repo variants */
538 solvable_set_id(Solvable *s, Id keyname, Id id)
540 repo_set_id(s->repo, s - s->repo->pool->solvables, keyname, id);
544 solvable_set_num(Solvable *s, Id keyname, unsigned long long num)
546 repo_set_num(s->repo, s - s->repo->pool->solvables, keyname, num);
550 solvable_set_str(Solvable *s, Id keyname, const char *str)
552 repo_set_str(s->repo, s - s->repo->pool->solvables, keyname, str);
556 solvable_set_poolstr(Solvable *s, Id keyname, const char *str)
558 repo_set_poolstr(s->repo, s - s->repo->pool->solvables, keyname, str);
562 solvable_add_poolstr_array(Solvable *s, Id keyname, const char *str)
564 repo_add_poolstr_array(s->repo, s - s->repo->pool->solvables, keyname, str);
568 solvable_add_idarray(Solvable *s, Id keyname, Id id)
570 repo_add_idarray(s->repo, s - s->repo->pool->solvables, keyname, id);
574 solvable_add_deparray(Solvable *s, Id keyname, Id dep, Id marker)
576 repo_add_deparray(s->repo, s - s->repo->pool->solvables, keyname, dep, marker);
580 solvable_set_idarray(Solvable *s, Id keyname, Queue *q)
582 repo_set_idarray(s->repo, s - s->repo->pool->solvables, keyname, q);
586 solvable_set_deparray(Solvable *s, Id keyname, Queue *q, Id marker)
588 repo_set_deparray(s->repo, s - s->repo->pool->solvables, keyname, q, marker);
592 solvable_unset(Solvable *s, Id keyname)
594 repo_unset(s->repo, s - s->repo->pool->solvables, keyname);
597 /* return true if a dependency intersects dep in the keyname array */
599 solvable_matchesdep(Solvable *s, Id keyname, Id dep, int marker)
602 Pool *pool = s->repo->pool;
605 if (keyname == SOLVABLE_NAME)
606 return pool_match_nevr(pool, s, dep) ? 1 : 0; /* nevr match hack */
608 solvable_lookup_deparray(s, keyname, &q, marker);
609 for (i = 0; i < q.count; i++)
610 if (pool_match_dep(pool, q.elements[i], dep))
612 i = i == q.count ? 0 : 1;