finish root support
[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 g;
35   const char *root = "/";
36
37   while ((g = getopt (argc, argv, "-r:")) >= 0)
38     switch (g)
39       {
40       case 'r': root = optarg; break;
41       case 1:
42         refpool = pool;
43         if ((fp = fopen(argv[1], "r")) == NULL)
44           {
45             perror(argv[1]);
46             exit(0);
47           }
48         ref = repo_create(refpool, "ref");
49         repo_add_solv(ref, fp);
50         fclose(fp);
51       }
52   
53   repo = repo_create(pool, "installed");
54   repo_add_rpmdb(repo, ref, root);
55   if (ref)
56     {
57       if (ref->pool != pool)
58         pool_free(ref->pool);
59       else
60         repo_free(ref, 1);
61       ref = 0;
62     }
63
64   tool_write(repo, 0, 0);
65   pool_free(pool);
66
67   exit(0);
68 }