2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
11 * Reads rpm database (and evtl. more, like product metadata) to build
12 * a .solv file of 'installed' solvables.
13 * Writes .solv to stdout
17 #include <sys/types.h>
27 #include "repo_rpmdb.h"
28 #include "repo_products.h"
29 #include "repo_solv.h"
30 #include "common_write.h"
35 fprintf(stderr, "\nUsage:\n"
36 "rpmdb2solv [-n] [-x] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
37 " -n : No packages, do not read rpmdb, useful to only parse products\n"
38 " -x : use extrapool\n"
39 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
40 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
41 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
48 main(int argc, char **argv)
50 Pool *pool = pool_create();
59 const char *basefile = 0;
60 const char *proddir = 0;
66 while ((c = getopt (argc, argv, "hnxb:r:p:")) >= 0)
98 refpool = pool_create();
101 if ((fp = fopen(argv[optind], "r")) == NULL)
103 perror(argv[optind]);
106 ref = repo_create(refpool, "ref");
107 repo_add_solv(ref, fp);
108 repo_disable_paging(ref);
113 * create 'installed' repository
119 repo = repo_create(pool, "installed");
120 repodata = repo_add_repodata(repo, 0);
123 repo_add_rpmdb(repo, repodata, ref, root);
125 if (proddir && *proddir)
127 /* if <root> given, not '/', and proddir does not start with <root> */
130 int rootlen = strlen(root);
131 if (strncmp(root, proddir, rootlen))
134 buf = (char *)sat_malloc(rootlen + strlen(proddir) + 2); /* + '/' + \0 */
136 if (root[rootlen-1] != '/'
139 strcpy(buf+rootlen, "/");
142 strcpy(buf+rootlen, proddir);
147 repo_add_products(repo, repodata, proddir, root);
151 repodata_internalize(repodata);
155 if (ref->pool != pool)
156 pool_free(ref->pool);
162 tool_write(repo, basefile, 0);