- add solver_private.h, make repo_ functions return an int, make solver_solv return...
[platform/upstream/libsolv.git] / tools / findfileconflicts.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include "pool.h"
5 #include "repo.h"
6 #include "solver.h"
7 #include "solverdebug.h"
8 #include "hash.h"
9 #include "repo_rpmdb.h"
10 #include "pool_fileconflicts.h"
11
12 static void *
13 iterate_handle(Pool *pool, Id p, void *cbdata)
14 {
15   Solvable *s = pool->solvables + p;
16   Id rpmdbid;
17   
18   if (!p)
19     {
20       rpm_byrpmdbid(0, 0, (void **)cbdata);
21       return 0;
22     }
23   if (!s->repo->rpmdbid)
24     return 0;
25   rpmdbid = s->repo->rpmdbid[p - s->repo->start];
26   if (!rpmdbid)
27     return 0;
28   return rpm_byrpmdbid(rpmdbid, 0, (void **)cbdata);
29 }
30
31 int main()
32 {
33   Pool *pool;
34   Repo *installed;
35   Solvable *s;
36   Id p;
37   int i;
38   Queue todo, conflicts;
39   void *state = 0;
40  
41   pool = pool_create();
42   pool_setdebuglevel(pool, 1);
43   installed = repo_create(pool, "@System");
44   pool_set_installed(pool, installed);
45   repo_add_rpmdb(installed, 0, 0, 0);
46   queue_init(&todo);
47   queue_init(&conflicts);
48   FOR_REPO_SOLVABLES(installed, p, s)
49     queue_push(&todo, p);
50   pool_findfileconflicts(pool, &todo, 0, &conflicts, &iterate_handle, (void *)&state);
51   queue_free(&todo);
52   for (i = 0; i < conflicts.count; i += 5)
53     printf("%s: %s[%s] %s[%s]\n", pool_id2str(pool, conflicts.elements[i]), pool_solvid2str(pool, conflicts.elements[i + 1]), pool_id2str(pool, conflicts.elements[i + 2]), pool_solvid2str(pool, conflicts.elements[i + 3]), pool_id2str(pool, conflicts.elements[i + 4]));
54   if (conflicts.count)
55     {
56       Queue job;
57       int problemcnt;
58
59       queue_init(&job);
60       pool_add_fileconflicts_deps(pool, &conflicts);
61       pool_addfileprovides(pool);
62       pool_createwhatprovides(pool);
63       pool_setdebuglevel(pool, 0);
64       Solver *solv = solver_create(pool);
65       queue_push2(&job, SOLVER_VERIFY|SOLVER_SOLVABLE_ALL, 0);
66 #if 0
67       solv->allowuninstall = 1;
68 #endif
69       problemcnt = solver_solve(solv, &job);
70       if (problemcnt)
71         solver_printallsolutions(solv);
72       else
73         solver_printtransaction(solv);
74       queue_free(&job);
75       solver_free(solv);
76     }
77   queue_free(&conflicts);
78   exit(0);
79 }