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"
42 " -o <solv> : Write .solv to file instead of stdout\n"
49 main(int argc, char **argv)
51 Pool *pool = pool_create();
58 const char *basefile = 0;
59 const char *refname = 0;
60 #ifdef ENABLE_SUSEREPO
69 while ((c = getopt(argc, argv, "Phnxb:r:p:o:")) >= 0)
88 #ifdef ENABLE_SUSEREPO
102 if (outfile && !freopen(outfile, "w", stdout))
109 * optional arg is old version of rpmdb solv file
110 * should make this a real option instead
114 refname = argv[optind];
116 if (refname && !nopacks)
119 if ((fp = fopen(refname, "r")) == NULL)
125 Pool *refpool = extrapool ? pool_create() : 0;
126 ref = repo_create(refpool ? refpool : pool, "ref");
127 if (repo_add_solv(ref, fp, 0) != 0)
129 fprintf(stderr, "%s: %s\n", refname, pool_errstr(ref->pool));
130 if (ref->pool != pool)
131 pool_free(ref->pool);
137 repo_disable_paging(ref);
143 * create 'installed' repository
150 pool_set_rootdir(pool, root);
152 repo = repo_create(pool, "installed");
153 data = repo_add_repodata(repo, 0);
157 if (repo_add_rpmdb(repo, ref, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0)))
159 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);
188 if (ref->pool != pool)
189 pool_free(ref->pool);
195 tool_write(repo, basefile, 0);