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
16 * rpmdb2solv [-n] [-x] [-b <basefile>] [-p <productsdir>] [-r <root>]
17 * -n : No packages, do not read rpmdb, useful to only parse products
19 * -b <basefile> : Write .solv to <basefile>.solv instead of stdout
20 * -p <productsdir> : Scan <productsdir> for .prod files, representing installed products
21 * -r <root> : Prefix rpmdb path and <productsdir> with <root>
25 #include <sys/types.h>
35 #include "repo_rpmdb.h"
36 #include "repo_products.h"
37 #include "repo_solv.h"
38 #include "common_write.h"
41 main(int argc, char **argv)
43 Pool *pool = pool_create();
52 const char *basefile = 0;
53 const char *proddir = 0;
59 while ((c = getopt (argc, argv, "nxb:r:p:")) >= 0)
88 refpool = pool_create();
91 if ((fp = fopen(argv[optind], "r")) == NULL)
96 ref = repo_create(refpool, "ref");
97 repo_add_solv(ref, fp);
98 repo_disable_paging(ref);
103 * create 'installed' repository
109 repo = repo_create(pool, "installed");
110 repodata = repo_add_repodata(repo, 0);
113 repo_add_rpmdb(repo, repodata, ref, root);
115 if (proddir && *proddir)
117 /* if <root> given, not '/', and proddir does not start with <root> */
120 int rootlen = strlen(root);
121 if (strncmp(root, proddir, rootlen))
124 buf = (char *)sat_malloc(rootlen + strlen(proddir) + 2); /* + '/' + \0 */
126 if (root[rootlen-1] != '/'
129 strcpy(buf+rootlen, "/");
132 strcpy(buf+rootlen, proddir);
137 repo_add_products(repo, repodata, proddir);
141 repodata_internalize(repodata);
145 if (ref->pool != pool)
146 pool_free(ref->pool);
152 tool_write(repo, basefile, 0);