1 /* vim: sw=2 et cino=>4,n-2,{1s
5 * Copyright (c) 2009, Novell Inc.
7 * This program is licensed under the BSD license, read LICENSE.BSD
8 * for further information
22 #include "repo_solv.h"
23 #ifdef ENABLE_SUSEREPO
24 #include "repo_susetags.h"
27 #include "repo_rpmmd.h"
33 #include "solv_xfopen.h"
39 printf("Usage:\n%s: <arch> [options..] repo [--nocheck repo]...\n"
40 "\t--exclude <pattern>\twhitespace-separated list of (sub-)"
41 "packagenames to ignore\n"
42 "\t--withobsoletes\t\tCheck for obsoletes on packages contained in repos\n"
43 "\t--nocheck\t\tDo not warn about all following repos (only use them to fulfill dependencies)\n"
44 "\t--withsrc\t\tAlso check dependencies of src.rpm\n\n"
51 main(int argc, char **argv)
59 char *arch, *exclude_pat;
70 int obsoletepkgcheck = 0;
78 pool_setarch(pool, arch);
79 noarchid = pool->solvables[SYSTEMSOLVABLE].arch;
80 for (i = 2; i < argc; i++)
85 if (!strcmp(argv[i], "--withsrc"))
90 if (!strcmp(argv[i], "--withobsoletes"))
95 if (!strcmp(argv[i], "--nocheck"))
98 nocheck = pool->nsolvables;
101 if (!strcmp(argv[i], "--exclude"))
105 printf("--exclude needs a whitespace separated list of substrings as parameter\n");
108 exclude_pat = argv[i + 1];
113 if (!strcmp(argv[i], "-"))
115 else if ((fp = solv_xfopen(argv[i], 0)) == 0)
120 repo = repo_create(pool, argv[i]);
125 #ifdef ENABLE_SUSEREPO
126 else if (l >= 8 && !strcmp(argv[i] + l - 8, "packages"))
128 r = repo_add_susetags(repo, fp, 0, 0, 0);
130 else if (l >= 11 && !strcmp(argv[i] + l - 11, "packages.gz"))
132 r = repo_add_susetags(repo, fp, 0, 0, 0);
136 else if (l >= 14 && !strcmp(argv[i] + l - 14, "primary.xml.gz"))
138 r = repo_add_rpmmd(repo, fp, 0, 0);
142 else if (l >= 8 && !strcmp(argv[i] + l - 8, "Packages"))
144 r = repo_add_debpackages(repo, fp, 0);
146 else if (l >= 11 && !strcmp(argv[i] + l - 11, "Packages.gz"))
148 r = repo_add_debpackages(repo, fp, 0);
152 r = repo_add_solv(repo, fp, 0);
155 fprintf(stderr, "could not add repo %s: %s\n", argv[i], pool_errstr(pool));
161 pool_addfileprovides(pool);
162 pool_createwhatprovides(pool);
163 archid = pool_str2id(pool, arch, 0);
165 rpmid = pool_str2id(pool, "rpm", 0);
169 for (p = 1; p < pool->nsolvables; p++)
171 Solvable *s = pool->solvables + p;
172 if (s->name == rpmid && s->arch == archid && pool_installable(pool, s))
175 if (p < pool->nsolvables)
176 rpmrel = pool_rel2id(pool, rpmid, archid, REL_ARCH, 1);
185 for (p = 1; p < (nocheck ? nocheck : pool->nsolvables); p++)
187 Solvable *s = pool->solvables + p;
190 if (withsrc && (s->arch == ARCH_SRC || s->arch == ARCH_NOSRC))
192 queue_push(&cand, p);
195 if (!pool_installable(pool, s))
197 if (archid && s->arch != archid && s->arch != noarchid)
199 /* check if we will conflict with a infarch rule, if yes,
200 * don't bother checking the package */
202 FOR_PROVIDES(rp, rpp, s->name)
204 if (pool->solvables[rp].name != s->name)
206 if (pool->solvables[rp].arch == archid)
212 queue_push(&cand, p);
214 if (obsoletepkgcheck)
216 int obsoleteusesprovides = pool_get_flag(pool, POOL_FLAG_OBSOLETEUSESPROVIDES);
217 int obsoleteusescolors = pool_get_flag(pool, POOL_FLAG_OBSOLETEUSESCOLORS);
219 for (i = 0; i < cand.count; i++)
222 s = pool->solvables + cand.elements[i];
226 Id obs, *obsp = s->repo->idarraydata + s->obsoletes;
228 while ((obs = *obsp++) != 0)
231 FOR_PROVIDES(op, opp, obs)
233 Solvable *os = pool->solvables + op;
234 if (nocheck && op >= nocheck)
236 if (solvable_identical(s, os))
238 if (!obsoleteusesprovides && !pool_match_nevr(pool, os, obs))
240 if (obsoleteusescolors && !pool_colormatch(pool, s, os))
243 printf("can't install %s:\n", pool_solvid2str(pool, op));
244 printf(" package is obsoleted by %s\n", pool_solvable2str(pool, s));
251 solv = solver_create(pool);
253 /* prune cand by doing weak installs */
257 for (i = 0; i < cand.count; i++)
259 p = cand.elements[i];
260 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE|SOLVER_WEAK, p);
263 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, rpmrel);
264 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
265 solver_solve(solv, &job);
267 for (i = j = 0; i < cand.count; i++)
269 p = cand.elements[i];
270 if (solver_get_decisionlevel(solv, p) <= 0)
272 cand.elements[j++] = p;
276 Solvable *s = pool->solvables + p;
277 if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
279 cand.elements[j++] = p;
289 /* now check every candidate */
290 for (i = 0; i < cand.count; i++)
295 p = cand.elements[i];
298 char *ptr, *save = 0, *pattern;
300 pattern = solv_strdup(exclude_pat);
302 for (ptr = strtok_r(pattern, " ", &save);
304 ptr = strtok_r(NULL, " ", &save))
306 if (*ptr && strstr(pool_solvid2str(pool, p), ptr))
316 s = pool->solvables + p;
318 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE, p);
320 queue_push2(&job, SOLVER_INSTALL|SOLVER_SOLVABLE_NAME, rpmrel);
321 solver_set_flag(solv, SOLVER_FLAG_IGNORE_RECOMMENDED, 1);
322 problemcount = solver_solve(solv, &job);
329 printf("can't install %s:\n", pool_solvable2str(pool, s));
330 while ((problem = solver_next_problem(solv, problem)) != 0)
332 solver_findallproblemrules(solv, problem, &rids);
333 for (j = 0; j < rids.count; j++)
335 Id probr = rids.elements[j];
340 solver_allruleinfos(solv, probr, &rinfo);
341 for (k = 0; k < rinfo.count; k += 4)
343 Id dep, source, target;
344 source = rinfo.elements[k + 1];
345 target = rinfo.elements[k + 2];
346 dep = rinfo.elements[k + 3];
347 switch (rinfo.elements[k])
349 case SOLVER_RULE_DISTUPGRADE:
351 case SOLVER_RULE_INFARCH:
352 s = pool_id2solvable(pool, source);
353 printf(" %s has inferior architecture\n", pool_solvable2str(pool, s));
355 case SOLVER_RULE_UPDATE:
356 s = pool_id2solvable(pool, source);
357 printf(" %s can not be updated\n", pool_solvable2str(pool, s));
359 case SOLVER_RULE_JOB:
360 case SOLVER_RULE_JOB_PROVIDED_BY_SYSTEM:
361 case SOLVER_RULE_JOB_UNKNOWN_PACKAGE:
362 case SOLVER_RULE_JOB_UNSUPPORTED:
364 case SOLVER_RULE_RPM:
365 printf(" some dependency problem\n");
367 case SOLVER_RULE_JOB_NOTHING_PROVIDES_DEP:
368 printf(" nothing provides requested %s\n", pool_dep2str(pool, dep));
370 case SOLVER_RULE_RPM_NOT_INSTALLABLE:
371 s = pool_id2solvable(pool, source);
372 printf(" package %s is not installable\n", pool_solvable2str(pool, s));
374 case SOLVER_RULE_RPM_NOTHING_PROVIDES_DEP:
375 s = pool_id2solvable(pool, source);
376 printf(" nothing provides %s needed by %s\n", pool_dep2str(pool, dep), pool_solvable2str(pool, s));
379 Reldep *rd = GETRELDEP(pool, dep);
380 if (!ISRELDEP(rd->name))
383 FOR_PROVIDES(rp, rpp, rd->name)
384 printf(" (we have %s)\n", pool_solvable2str(pool, pool->solvables + rp));
388 case SOLVER_RULE_RPM_SAME_NAME:
389 s = pool_id2solvable(pool, source);
390 s2 = pool_id2solvable(pool, target);
391 printf(" cannot install both %s and %s\n", pool_solvable2str(pool, s), pool_solvable2str(pool, s2));
393 case SOLVER_RULE_RPM_PACKAGE_CONFLICT:
394 s = pool_id2solvable(pool, source);
395 s2 = pool_id2solvable(pool, target);
396 printf(" package %s conflicts with %s provided by %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep), pool_solvable2str(pool, s2));
398 case SOLVER_RULE_RPM_PACKAGE_OBSOLETES:
399 s = pool_id2solvable(pool, source);
400 s2 = pool_id2solvable(pool, target);
401 printf(" package %s obsoletes %s provided by %s\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep), pool_solvable2str(pool, s2));
403 case SOLVER_RULE_RPM_PACKAGE_REQUIRES:
404 s = pool_id2solvable(pool, source);
405 printf(" package %s requires %s, but none of the providers can be installed\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep));
407 case SOLVER_RULE_RPM_SELF_CONFLICT:
408 s = pool_id2solvable(pool, source);
409 printf(" package %s conflicts with %s provided by itself\n", pool_solvable2str(pool, s), pool_dep2str(pool, dep));
419 if (!strcmp(pool_id2str(pool, s->name), "libusb-compat-devel"))
421 solver_printdecisions(solv);