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"
29 #include "repo_pubkey.h"
31 #include "repo_products.h"
32 #include "repo_solv.h"
33 #include "common_write.h"
38 fprintf(stderr, "\nUsage:\n"
39 "rpmdb2solv [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
40 " -n : No packages, do not read rpmdb, useful to only parse products\n"
41 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
42 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
43 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
44 " -o <solv> : Write .solv to file instead of stdout\n"
51 main(int argc, char **argv)
54 Pool *pool = pool_create();
60 const char *basefile = 0;
61 const char *refname = 0;
62 #ifdef ENABLE_SUSEREPO
74 while ((c = getopt(argc, argv, "Phnkxb:r:p:o:")) >= 0)
93 #ifdef ENABLE_SUSEREPO
112 if (outfile && !freopen(outfile, "w", stdout))
119 * optional arg is old version of rpmdb solv file
120 * should make this a real option instead
124 refname = argv[optind];
126 if (refname && !nopacks)
128 if ((reffp = fopen(refname, "r")) == NULL)
133 * create 'installed' repository
140 pool_set_rootdir(pool, root);
142 repo = repo_create(pool, "installed");
143 data = repo_add_repodata(repo, 0);
147 if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
149 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
156 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
158 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
164 #ifdef ENABLE_SUSEREPO
165 if (proddir && *proddir)
169 int rootlen = strlen(root);
170 if (!strncmp(root, proddir, rootlen))
173 if (*proddir != '/' && proddir[-1] == '/')
177 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
179 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
184 repodata_internalize(data);
189 tool_write(repo, basefile, 0);