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>
25 #include "repo_rpmdb.h"
27 #include "repo_pubkey.h"
29 #include "repo_products.h"
30 #include "repo_solv.h"
31 #include "common_write.h"
33 #include "repo_appdata.h"
36 #include "repo_autopattern.h"
43 fprintf(stderr, "\nUsage:\n"
44 "rpmdb2solv [-P] [-C] [-n] [-b <basefile>] [-p <productsdir>] [-r <root>]\n"
45 " -n : No packages, do not read rpmdb, useful to only parse products\n"
46 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
47 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
48 " -o <solv> : Write .solv to file instead of stdout\n"
49 " -P : print percentage done\n"
50 " -C : include the changelog\n"
57 main(int argc, char **argv)
60 Pool *pool = pool_create();
65 int add_changelog = 0;
67 const char *refname = 0;
68 #ifdef ENABLE_SUSEREPO
86 while ((c = getopt(argc, argv, "ACPhnkxXr:p:o:")) >= 0)
102 #ifdef ENABLE_SUSEREPO
107 break; /* extrapool no longer supported */
114 #ifdef ENABLE_APPDATA
134 if (outfile && !freopen(outfile, "w", stdout))
141 * optional arg is old version of rpmdb solv file
142 * should make this a real option instead
146 refname = argv[optind];
148 if (refname && !nopacks)
150 if ((reffp = fopen(refname, "r")) == NULL)
155 * create 'installed' repository
162 pool_set_rootdir(pool, root);
164 repo = repo_create(pool, "installed");
165 data = repo_add_repodata(repo, 0);
169 int flags = REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE;
171 flags |= RPMDB_REPORT_PROGRESS;
173 flags |= RPM_ADD_WITH_CHANGELOG;
174 if (repo_add_rpmdb_reffp(repo, reffp, flags))
176 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
183 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
185 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
191 #ifdef ENABLE_SUSEREPO
192 if (proddir && *proddir)
196 int rootlen = strlen(root);
197 if (!strncmp(root, proddir, rootlen))
200 if (*proddir != '/' && proddir[-1] == '/')
204 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
206 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
212 #ifdef ENABLE_APPDATA
215 repo_add_appdata_dir(repo, "/usr/share/metainfo", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
216 repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
219 repodata_internalize(data);
226 repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
229 tool_write(repo, stdout);