X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Frpmdb2solv.c;h=c0a2fc3eb295507d927b6f38499c97e339a66346;hb=843dc7e190acc4e55c3613a8ae05b43dd73bfa33;hp=f46b30f813b2ee4c4232d4f673f7c9db1e6ab91a;hpb=379f90a0f8f1ab70f1a6e27d16cb2dbca4b8a087;p=platform%2Fupstream%2Flibsolv.git diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index f46b30f..c0a2fc3 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -8,6 +8,10 @@ /* * rpmdb2solv * + * Reads rpm database (and evtl. more, like product metadata) to build + * a .solv file of 'installed' solvables. + * Writes .solv to stdout + * */ #include @@ -21,67 +25,168 @@ #include "pool.h" #include "repo.h" #include "repo_rpmdb.h" +#ifdef ENABLE_RPMDB_PUBKEY +#include "repo_rpmdb_pubkey.h" +#endif +#include "repo_products.h" #include "repo_solv.h" #include "common_write.h" +static void +usage(int status) +{ + fprintf(stderr, "\nUsage:\n" + "rpmdb2solv [-n] [-b ] [-p ] [-r ]\n" + " -n : No packages, do not read rpmdb, useful to only parse products\n" + " -b : Write .solv to .solv instead of stdout\n" + " -p : Scan for .prod files, representing installed products\n" + " -r : Prefix rpmdb path and with \n" + " -o : Write .solv to file instead of stdout\n" + ); + exit(status); +} + + int main(int argc, char **argv) { + FILE *reffp = 0; Pool *pool = pool_create(); - Repo *repo, *ref = 0; - FILE *fp; - Pool *refpool; - int c; - int extrapool = 0; + Repo *repo; + Repodata *data; + int c, percent = 0; + int nopacks = 0; const char *root = 0; const char *basefile = 0; + const char *refname = 0; +#ifdef ENABLE_SUSEREPO + char *proddir = 0; +#endif + char *outfile = 0; +#ifdef ENABLE_RPMDB_PUBKEY + int pubkeys = 0; +#endif - while ((c = getopt (argc, argv, "xb:r:")) >= 0) + /* + * parse arguments + */ + + while ((c = getopt(argc, argv, "Phnkxb:r:p:o:")) >= 0) switch (c) { + case 'h': + usage(0); + break; case 'r': root = optarg; break; case 'b': basefile = optarg; break; + case 'n': + nopacks = 1; + break; + case 'P': + percent = 1; + break; + case 'p': +#ifdef ENABLE_SUSEREPO + proddir = optarg; +#endif + break; case 'x': - extrapool = 1; break; + case 'o': + outfile = optarg; + break; +#ifdef ENABLE_RPMDB_PUBKEY + case 'k': + nopacks = 1; + pubkeys = 1; + break; +#endif default: - exit(1); + usage(1); } + if (outfile && !freopen(outfile, "w", stdout)) + { + perror(outfile); + exit(1); + } + + /* + * optional arg is old version of rpmdb solv file + * should make this a real option instead + */ + if (optind < argc) + refname = argv[optind]; + + if (refname && !nopacks) { - if (extrapool) - refpool = pool_create(); - else - refpool = pool; - if ((fp = fopen(argv[optind], "r")) == NULL) - { - perror(argv[optind]); - exit(1); - } - ref = repo_create(refpool, "ref"); - repo_add_solv(ref, fp); - repo_disable_paging(ref); - fclose(fp); + if ((reffp = fopen(refname, "r")) == NULL) + perror(refname); } + /* + * create 'installed' repository + * add products + * add rpmdb + * write .solv + */ + + if (root && *root) + pool_set_rootdir(pool, root); + repo = repo_create(pool, "installed"); - repo_add_rpmdb(repo, ref, root); - if (ref) + data = repo_add_repodata(repo, 0); + + if (!nopacks) + { + if (repo_add_rpmdb_reffp(repo, reffp, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | (percent ? RPMDB_REPORT_PROGRESS : 0))) + { + fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool)); + exit(1); + } + } +#ifdef ENABLE_RPMDB_PUBKEY + if (pubkeys) { - if (ref->pool != pool) - pool_free(ref->pool); - else - repo_free(ref, 1); - ref = 0; + if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) + { + fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool)); + exit(1); + } } +#endif + +#ifdef ENABLE_SUSEREPO + if (proddir && *proddir) + { + if (root && *root) + { + int rootlen = strlen(root); + if (!strncmp(root, proddir, rootlen)) + { + proddir += rootlen; + if (*proddir != '/' && proddir[-1] == '/') + proddir--; + } + } + if (repo_add_products(repo, proddir, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE)) + { + fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool)); + exit(1); + } + } +#endif + repodata_internalize(data); + + if (reffp) + fclose(reffp); tool_write(repo, basefile, 0); pool_free(pool); - exit(0); }