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 #ifdef ENABLE_RPMDB_PUBKEY
29 #include "repo_rpmdb_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] [-x] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
40 " -n : No packages, do not read rpmdb, useful to only parse products\n"
41 " -x : use extrapool\n"
42 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
43 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
44 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
45 " -o <solv> : Write .solv to file instead of stdout\n"
52 main(int argc, char **argv)
54 Pool *pool = pool_create();
61 const char *basefile = 0;
62 const char *refname = 0;
63 #ifdef ENABLE_SUSEREPO
67 #ifdef ENABLE_RPMDB_PUBKEY
75 while ((c = getopt(argc, argv, "Phnkxb:r:p:o:")) >= 0)
94 #ifdef ENABLE_SUSEREPO
104 #ifdef ENABLE_RPMDB_PUBKEY
114 if (outfile && !freopen(outfile, "w", stdout))
121 * optional arg is old version of rpmdb solv file
122 * should make this a real option instead
126 refname = argv[optind];
128 if (refname && !nopacks)
131 if ((fp = fopen(refname, "r")) == NULL)
137 Pool *refpool = extrapool ? pool_create() : 0;
138 ref = repo_create(refpool ? refpool : pool, "ref");
139 if (repo_add_solv(ref, fp, 0) != 0)
141 fprintf(stderr, "%s: %s\n", refname, pool_errstr(ref->pool));
142 if (ref->pool != pool)
143 pool_free(ref->pool);
149 repo_disable_paging(ref);
155 * create 'installed' repository
162 pool_set_rootdir(pool, root);
164 repo = repo_create(pool, "installed");
165 data = repo_add_repodata(repo, 0);
169 if (repo_add_rpmdb(repo, ref, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
171 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
175 #ifdef ENABLE_RPMDB_PUBKEY
178 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
180 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
186 #ifdef ENABLE_SUSEREPO
187 if (proddir && *proddir)
191 int rootlen = strlen(root);
192 if (!strncmp(root, proddir, rootlen))
195 if (*proddir != '/' && proddir[-1] == '/')
199 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
201 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
206 repodata_internalize(data);
210 if (ref->pool != pool)
211 pool_free(ref->pool);
217 tool_write(repo, basefile, 0);