- do not try to open DB_CONFIG in current directory (I love berkeleydb...)
[platform/upstream/libsolv.git] / tools / rpmdb2solv.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * rpmdb2solv
10  * 
11  */
12
13 #include <sys/types.h>
14 #include <limits.h>
15 #include <fcntl.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20
21 #include "pool.h"
22 #include "repo.h"
23 #include "repo_rpmdb.h"
24 #include "repo_solv.h"
25 #include "common_write.h"
26
27 int
28 main(int argc, char **argv)
29 {
30   Pool *pool = pool_create();
31   Repo *repo, *ref = 0;
32   FILE *fp;
33   Pool *refpool;
34   int c;
35   int extrapool = 0;
36   const char *root = 0;
37   const char *basefile = 0;
38
39   while ((c = getopt (argc, argv, "xb:r:")) >= 0)
40     switch (c)
41       {
42       case 'r':
43         root = optarg;
44         break;
45       case 'b':
46         basefile = optarg;
47         break;
48       case 'x':
49         extrapool = 1;
50         break;
51       default:
52         exit(1);
53       }
54   
55   if (optind < argc)
56     {
57       if (extrapool)
58         refpool = pool_create();
59       else
60         refpool = pool;
61       if ((fp = fopen(argv[optind], "r")) == NULL)
62         {
63           perror(argv[optind]);
64           exit(1);
65         }
66       ref = repo_create(refpool, "ref");
67       repo_add_solv(ref, fp);
68       fclose(fp);
69     }
70
71   repo = repo_create(pool, "installed");
72   repo_add_rpmdb(repo, ref, root);
73   if (ref)
74     {
75       if (ref->pool != pool)
76         pool_free(ref->pool);
77       else
78         repo_free(ref, 1);
79       ref = 0;
80     }
81
82   tool_write(repo, basefile, 0);
83   pool_free(pool);
84
85   exit(0);
86 }