exit if there is an error opening the old solv
[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       default:
42         exit(1);
43       }
44   
45   if (optind < argc)
46     {
47       refpool = pool;
48       if ((fp = fopen(argv[optind], "r")) == NULL)
49         {
50           perror(argv[optind]);
51           exit(1);
52         }
53       ref = repo_create(refpool, "ref");
54       repo_add_solv(ref, fp);
55       fclose(fp);
56     }
57
58   repo = repo_create(pool, "installed");
59   repo_add_rpmdb(repo, ref, root);
60   if (ref)
61     {
62       if (ref->pool != pool)
63         pool_free(ref->pool);
64       else
65         repo_free(ref, 1);
66       ref = 0;
67     }
68
69   tool_write(repo, 0, 0);
70   pool_free(pool);
71
72   exit(0);
73 }