X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Frpmdb2solv.c;h=72e95ad19b0736024e446bd0afba77fea44f8647;hb=e47af19566c8138568d038562a7fff41e541cb5e;hp=0a6457ede26b8258d153103b1065dbd9fcf97741;hpb=2aff45a7728260421abf5271a08d58aa91d5305e;p=platform%2Fupstream%2Flibsolv.git diff --git a/tools/rpmdb2solv.c b/tools/rpmdb2solv.c index 0a6457e..72e95ad 100644 --- a/tools/rpmdb2solv.c +++ b/tools/rpmdb2solv.c @@ -25,21 +25,30 @@ #include "pool.h" #include "repo.h" #include "repo_rpmdb.h" +#ifdef ENABLE_PUBKEY +#include "repo_pubkey.h" +#endif #include "repo_products.h" #include "repo_solv.h" #include "common_write.h" +#ifdef ENABLE_APPDATA +#include "repo_appdata.h" +#endif +#ifdef SUSE +#include "repo_autopattern.h" +#endif + static void usage(int status) { fprintf(stderr, "\nUsage:\n" - "rpmdb2solv [-n] [-x] [-b ] [-p ] [-r ]\n" - " -a : Only print this attribute, no .solv generation. E.g. '-a distribution.target'\n" + "rpmdb2solv [-n] [-b ] [-p ] [-r ]\n" " -n : No packages, do not read rpmdb, useful to only parse products\n" - " -x : use extrapool\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); } @@ -48,32 +57,39 @@ usage(int status) int main(int argc, char **argv) { + FILE *reffp = 0; Pool *pool = pool_create(); - Repo *repo, *ref = 0; - Repodata *repodata; - 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 *proddir = 0; - const char *attribute = 0; + const char *refname = 0; +#ifdef ENABLE_SUSEREPO + char *proddir = 0; +#endif + char *outfile = 0; +#ifdef ENABLE_PUBKEY + int pubkeys = 0; +#endif +#ifdef ENABLE_APPDATA + int add_appdata = 0; +#endif +#ifdef SUSE + int add_auto = 0; +#endif /* * parse arguments */ - while ((c = getopt (argc, argv, "a:hnxb:r:p:")) >= 0) + while ((c = getopt(argc, argv, "APhnkxXb:r:p:o:")) >= 0) switch (c) { case 'h': usage(0); break; - case 'a': - attribute = optarg; - break; case 'r': root = optarg; break; @@ -83,35 +99,57 @@ main(int argc, char **argv) case 'n': nopacks = 1; break; + case 'P': + percent = 1; + break; case 'p': +#ifdef ENABLE_SUSEREPO proddir = optarg; +#endif break; case 'x': - extrapool = 1; + break; /* extrapool no longer supported */ + case 'X': +#ifdef SUSE + add_auto = 1; +#endif + break; + case 'A': +#ifdef ENABLE_APPDATA + add_appdata = 1; +#endif + break; + case 'o': + outfile = optarg; + break; +#ifdef ENABLE_PUBKEY + case 'k': + nopacks = 1; + pubkeys = 1; break; +#endif default: 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); } /* @@ -121,53 +159,68 @@ main(int argc, char **argv) * write .solv */ + if (root && *root) + pool_set_rootdir(pool, root); + repo = repo_create(pool, "installed"); - repodata = repo_add_repodata(repo, 0); + pool_set_installed(pool, repo); + data = repo_add_repodata(repo, 0); if (!nopacks) - repo_add_rpmdb(repo, repodata, ref, root); + { + 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_PUBKEY + if (pubkeys) + { + if (repo_add_rpmdb_pubkeys(repo, REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE | ADD_WITH_KEYSIGNATURES)) + { + fprintf(stderr, "rpmdb2solv: %s\n", pool_errstr(pool)); + exit(1); + } + } +#endif +#ifdef ENABLE_SUSEREPO if (proddir && *proddir) { - /* if given, not '/', and proddir does not start with */ if (root && *root) { int rootlen = strlen(root); - if (strncmp(root, proddir, rootlen)) + if (!strncmp(root, proddir, rootlen)) { - char *buf; - buf = (char *)sat_malloc(rootlen + strlen(proddir) + 2); /* + '/' + \0 */ - strcpy(buf, root); - if (root[rootlen-1] != '/' - && *proddir != '/') - { - strcpy(buf+rootlen, "/"); - ++rootlen; - } - strcpy(buf+rootlen, proddir); - proddir = buf; + proddir += rootlen; + if (*proddir != '/' && proddir[-1] == '/') + proddir--; } } - - repo_add_products(repo, repodata, proddir, root, attribute); + 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); + } } - - if (repodata) - repodata_internalize(repodata); +#endif - if (ref) - { - if (ref->pool != pool) - pool_free(ref->pool); - else - repo_free(ref, 1); - ref = 0; - } +#ifdef ENABLE_APPDATA + if (add_appdata) + repo_add_appdata_dir(repo, "/usr/share/appdata", REPO_USE_ROOTDIR | REPO_REUSE_REPODATA | REPO_NO_INTERNALIZE); +#endif + repodata_internalize(data); - if (!attribute) - tool_write(repo, basefile, 0); + if (reffp) + fclose(reffp); - pool_free(pool); +#ifdef SUSE + if (add_auto) + repo_add_autopattern(repo, 0); +#endif + tool_write(repo, basefile, 0); + pool_free(pool); exit(0); }