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)
59 n = s - pool->solvables;
60 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
62 if (n < data->start || n >= data->end)
64 for (j = 1; j < data->nkeys; j++)
66 if (data->keys[j].name == keyname && (data->keys[j].type == REPOKEY_TYPE_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID))
68 Id id = repodata_lookup_id(data, n - data->start, j);
72 id = repodata_globalize_id(data, id);
82 solvable_lookup_str(Solvable *s, Id keyname)
96 return id2str(pool, s->name);
98 return id2str(pool, s->arch);
100 return id2str(pool, s->evr);
101 case SOLVABLE_VENDOR:
102 return id2str(pool, s->vendor);
104 n = s - pool->solvables;
105 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
107 if (n < data->start || n >= data->end)
109 for (j = 1; j < data->nkeys; j++)
111 if (data->keys[j].name == keyname && (data->keys[j].type == REPOKEY_TYPE_ID || data->keys[j].type == REPOKEY_TYPE_CONSTANTID || data->keys[j].type == REPOKEY_TYPE_STR))
113 str = repodata_lookup_str(data, n - data->start, j);
123 solvable_lookup_str_poollang(Solvable *s, Id keyname)
131 return repo_lookup_str(s, keyname);
132 pool = s->repo->pool;
133 if (!pool->nlanguages)
134 return repo_lookup_str(s, keyname);
135 cols = pool->nlanguages + 1;
136 if (!pool->languagecache)
138 pool->languagecache = sat_calloc(cols * ID_NUM_INTERNAL, sizeof(Id));
139 pool->languagecacheother = 0;
141 if (keyname >= ID_NUM_INTERNAL)
143 row = pool->languagecache + ID_NUM_INTERNAL * cols;
144 for (i = 0; i < pool->languagecacheother; i++, row += cols)
147 if (i >= pool->languagecacheother)
149 pool->languagecache = sat_realloc2(pool->languagecache, pool->languagecacheother + 1, cols * sizeof(Id));
150 pool->languagecacheother++;
151 row = pool->languagecache + cols * (ID_NUM_INTERNAL + pool->languagecacheother++);
155 row = pool->languagecache + keyname * cols;
156 row++; /* skip keyname */
157 for (i = 0; i < pool->nlanguages; i++, row++)
164 kn = id2str(pool, keyname);
165 p = sat_malloc(strlen(kn) + strlen(pool->languages[i]) + 2);
166 sprintf(p, "%s:%s", kn, pool->languages[i]);
167 *row = str2id(pool, p, 1);
170 str = repo_lookup_str(s, *row);
174 return repo_lookup_str(s, keyname);
178 solvable_lookup_str_lang(Solvable *s, Id keyname, const char *lang)
183 const char *kn, *str;
186 return repo_lookup_str(s, keyname);
187 pool = s->repo->pool;
188 kn = id2str(pool, keyname);
189 p = sat_malloc(strlen(kn) + strlen(lang) + 2);
190 sprintf(p, "%s:%s", kn, lang);
191 id = str2id(pool, p, 0);
195 str = repo_lookup_str(s, id);
199 return repo_lookup_str(s, keyname);
203 solvable_lookup_num(Solvable *s, Id keyname, unsigned int notfound)
205 Repo *repo = s->repo;
213 if (keyname == RPM_RPMDBID)
216 return repo->rpmdbid[(s - pool->solvables) - repo->start];
219 n = s - pool->solvables;
220 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
222 if (n < data->start || n >= data->end)
224 for (j = 1; j < data->nkeys; j++)
226 if (data->keys[j].name == keyname
227 && (data->keys[j].type == REPOKEY_TYPE_U32
228 || data->keys[j].type == REPOKEY_TYPE_NUM
229 || data->keys[j].type == REPOKEY_TYPE_CONSTANT))
232 if (repodata_lookup_num(data, n - data->start, j, &value))
241 solvable_lookup_bool(Solvable *s, Id keyname)
243 return solvable_lookup_num(s, keyname, 0) ? 1 : 0;
247 solvable_lookup_void(Solvable *s, Id keyname)
249 Repo *repo = s->repo;
257 n = s - pool->solvables;
258 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
260 if (n < data->start || n >= data->end)
262 for (j = 1; j < data->nkeys; j++)
264 if (data->keys[j].name == keyname
265 && (data->keys[j].type == REPOKEY_TYPE_VOID))
267 if (repodata_lookup_void(data, n - data->start, j))
275 const unsigned char *
276 solvable_lookup_bin_checksum(Solvable *s, Id keyname, Id *typep)
278 Repo *repo = s->repo;
287 n = s - pool->solvables;
288 for (i = 0, data = repo->repodata; i < repo->nrepodata; i++, data++)
290 if (n < data->start || n >= data->end)
292 for (j = 1; j < data->nkeys; j++)
294 if (data->keys[j].name == keyname
295 && (data->keys[j].type == REPOKEY_TYPE_MD5
296 || data->keys[j].type == REPOKEY_TYPE_SHA1
297 || data->keys[j].type == REPOKEY_TYPE_SHA256))
299 const unsigned char *chk = repodata_lookup_bin_checksum(data, n - data->start, j, typep);
309 solvable_lookup_checksum(Solvable *s, Id keyname, Id *typep)
311 const unsigned char *chk = solvable_lookup_bin_checksum(s, keyname, typep);
312 /* we need the repodata just as a reference for a pool */
313 return chk ? repodata_chk2str(s->repo->repodata, *typep, chk) : 0;
317 solvable_get_location(Solvable *s, unsigned int *medianrp)
322 const char *mediadir, *mediafile;
327 pool = s->repo->pool;
328 *medianrp = solvable_lookup_num(s, SOLVABLE_MEDIANR, 1);
329 if (solvable_lookup_void(s, SOLVABLE_MEDIADIR))
330 mediadir = id2str(pool, s->arch);
332 mediadir = solvable_lookup_str(s, SOLVABLE_MEDIADIR);
334 l = strlen(mediadir) + 1;
335 if (solvable_lookup_void(s, SOLVABLE_MEDIAFILE))
337 const char *name, *evr, *arch;
338 name = id2str(pool, s->name);
339 evr = id2str(pool, s->evr);
340 arch = id2str(pool, s->arch);
341 /* name-evr.arch.rpm */
342 loc = pool_alloctmpspace(pool, l + strlen(name) + strlen(evr) + strlen(arch) + 7);
344 sprintf(loc, "%s/%s-%s.%s.rpm", mediadir, name, evr, arch);
346 sprintf(loc, "%s-%s.%s.rpm", name, evr, arch);
350 mediafile = solvable_lookup_str(s, SOLVABLE_MEDIAFILE);
353 loc = pool_alloctmpspace(pool, l + strlen(mediafile) + 1);
355 sprintf(loc, "%s/%s", mediadir, mediafile);
357 strcpy(loc, mediafile);
363 static inline Id dep2name(Pool *pool, Id dep)
365 while (ISRELDEP(dep))
367 Reldep *rd = rd = GETRELDEP(pool, dep);
373 static inline int providedbyinstalled(Pool *pool, Repo *installed, Id dep)
377 FOR_PROVIDES(p, pp, dep)
379 if (p == SYSTEMSOLVABLE)
381 s = pool->solvables + p;
382 if (s->repo && s->repo == installed)
390 * 1: solvable is installable without any other package changes
391 * 0: solvable is not installable
392 * -1: solvable is installable, but doesn't constrain any installed packages
395 solvable_trivial_installable(Solvable *s, Repo *installed)
397 Pool *pool = s->repo->pool;
403 int r, interesting = 0;
407 reqp = s->repo->idarraydata + s->requires;
408 while ((req = *reqp++) != 0)
410 if (req == SOLVABLE_PREREQMARKER)
412 r = providedbyinstalled(pool, installed, req);
423 conp = s->repo->idarraydata + s->conflicts;
424 while ((con = *conp++) != 0)
426 if (providedbyinstalled(pool, installed, con))
428 if (!interesting && ISRELDEP(con))
430 con = dep2name(pool, con);
431 if (providedbyinstalled(pool, installed, con))
436 if (s->obsoletes && s->repo != installed)
438 obsp = s->repo->idarraydata + s->obsoletes;
439 while ((obs = *obsp++) != 0)
441 if (providedbyinstalled(pool, installed, obs))
445 if (s->repo != installed)
447 FOR_PROVIDES(p, pp, s->name)
449 s2 = pool->solvables + p;
450 if (s2->repo == installed && s2->name == s->name)
454 FOR_REPO_SOLVABLES(installed, p, s2)
458 conp = s->repo->idarraydata + s->conflicts;
459 while ((con = *conp++) != 0)
461 dp = pool_whatprovides(pool, con);
463 if (*dp == s - pool->solvables)
467 return interesting ? 1 : -1;