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 " -b <basefile> : Write .solv to <basefile>.solv instead of stdout\n"
47 " -p <productsdir> : Scan <productsdir> for .prod files, representing installed products\n"
48 " -r <root> : Prefix rpmdb path and <productsdir> with <root>\n"
49 " -o <solv> : Write .solv to file instead of stdout\n"
50 " -P : print percentage done\n"
51 " -C : include the changelog\n"
58 main(int argc, char **argv)
61 Pool *pool = pool_create();
66 int add_changelog = 0;
68 const char *basefile = 0;
69 const char *refname = 0;
70 #ifdef ENABLE_SUSEREPO
88 while ((c = getopt(argc, argv, "ACPhnkxXb:r:p:o:")) >= 0)
107 #ifdef ENABLE_SUSEREPO
112 break; /* extrapool no longer supported */
119 #ifdef ENABLE_APPDATA
139 if (outfile && !freopen(outfile, "w", stdout))
146 * optional arg is old version of rpmdb solv file
147 * should make this a real option instead
151 refname = argv[optind];
153 if (refname && !nopacks)
155 if ((reffp = fopen(refname, "r")) == NULL)
160 * create 'installed' repository
167 pool_set_rootdir(pool, root);
169 repo = repo_create(pool, "installed");
170 data = repo_add_repodata(repo, 0);
174 int flags = REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE;
176 flags |= RPMDB_REPORT_PROGRESS;
178 flags |= RPM_ADD_WITH_CHANGELOG;
179 if (repo_add_rpmdb_reffp(repo, reffp, flags))
181 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
188 if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES))
190 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
196 #ifdef ENABLE_SUSEREPO
197 if (proddir && *proddir)
201 int rootlen = strlen(root);
202 if (!strncmp(root, proddir, rootlen))
205 if (*proddir != '/' && proddir[-1] == '/')
209 if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE))
211 fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool));
217 #ifdef ENABLE_APPDATA
220 repo_add_appdata_dir(repo, "/usr/share/metainfo", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
221 repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | APPDATA_SEARCH_UNINTERNALIZED_FILELIST);
224 repodata_internalize(data);
231 repo_add_autopattern(repo, ADD_NO_AUTOPRODUCTS);
234 tool_write(repo, basefile, 0);