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 " -a <attr> : Only print this attribute, no .solv generation. E.g. '-a distribution.target'\n"
38 " -n : No packages, do not read rpmdb, useful to only parse products\n"
39 " -x : use extrapool\n"
40 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
41 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
42 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
43 " -o <solv> : Write .solv to file instead of stdout\n"
50 main(int argc, char **argv)
52 Pool *pool = pool_create();
61 const char *basefile = 0;
63 const char *attribute = 0;
70 while ((c = getopt(argc, argv, "Pa:hnxb:r:p:o:")) >= 0)
104 if (outfile && !freopen(outfile, "w", stdout))
117 refpool = pool_create();
120 if ((fp = fopen(argv[optind], "r")) == NULL)
122 perror(argv[optind]);
125 ref = repo_create(refpool, "ref");
126 repo_add_solv(ref, fp);
127 repo_disable_paging(ref);
132 * create 'installed' repository
138 repo = repo_create(pool, "installed");
139 data = repo_add_repodata(repo, 0);
142 repo_add_rpmdb(repo, ref, root, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0));
144 if (proddir && *proddir)
147 /* if <root> given, not '/', and proddir does not start with <root> */
150 int rootlen = strlen(root);
151 if (strncmp(root, proddir, rootlen))
153 buf = (char *)sat_malloc(rootlen + strlen(proddir) + 2); /* + '/' + \0 */
155 if (root[rootlen - 1] != '/' && *proddir != '/')
156 buf[rootlen++] = '/';
157 strcpy(buf + rootlen, proddir);
160 repo_add_products(repo, proddir, root, attribute, REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE);
165 repodata_internalize(data);
169 if (ref->pool != pool)
170 pool_free(ref->pool);
177 tool_write(repo, basefile, 0);