X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Fmergesolv.c;h=6719c8c607a457487d3019159d0eb16d0f92c362;hb=982625a0b9d4b97a8074bac320c23471e1cfb1b9;hp=c8d6f62da5fa2e51706ebf895fb6c36cc3662b41;hpb=dc242b8aa0fe56ec3e06e46bee698f5184d18f76;p=platform%2Fupstream%2Flibsolv.git diff --git a/tools/mergesolv.c b/tools/mergesolv.c index c8d6f62..6719c8c 100644 --- a/tools/mergesolv.c +++ b/tools/mergesolv.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -20,70 +21,103 @@ #include "pool.h" #include "repo_solv.h" -#include "repo_write.h" - -static char *verticals[] = { - "authors", - "description", - "messagedel", - "messageins", - "eula", - "diskusage", - 0 -}; - -static unsigned char *filter; -static int nfilter; +#ifdef SUSE +#include "repo_autopattern.h" +#endif +#include "common_write.h" static void -create_filter(Pool *pool) +usage() { - char **s; - Id id; - for (s = verticals; *s; s++) - { - id = str2id(pool, *s, 1); - if (id >= nfilter) - { - filter = sat_realloc(filter, id + 16); - memset(filter + nfilter, 0, id + 16 - nfilter); - nfilter = id + 16; - } - filter[id] = 1; - } + fprintf(stderr, "\nUsage:\n" + "mergesolv [file] [file] [...]\n" + " merges multiple solv files into one and writes it to stdout\n" + ); + exit(0); } static int -keyfilter(Repo *data, Repokey *key, void *kfdata) +loadcallback (Pool *pool, Repodata *data, void *vdata) { - if (key->name < nfilter && filter[key->name]) - return KEY_STORAGE_VERTICAL_OFFSET; - return KEY_STORAGE_INCORE; + FILE *fp; + const char *location = repodata_lookup_str(data, SOLVID_META, REPOSITORY_LOCATION); + int r; + + if (!location) + return 0; + fprintf(stderr, "Loading SOLV file %s\n", location); + fp = fopen (location, "r"); + if (!fp) + { + perror(location); + return 0; + } + r = repo_add_solv(data->repo, fp, REPO_USE_LOADING|REPO_LOCALPOOL); + fclose(fp); + return r ? 0 : 1; } int main(int argc, char **argv) { - Pool *pool = pool_create(); + Pool *pool; Repo *repo; + const char *basefile = 0; + int with_attr = 0; +#ifdef SUSE + int add_auto = 0; +#endif + int c; + + pool = pool_create(); + repo = repo_create(pool, ""); + + while ((c = getopt(argc, argv, "ahb:X")) >= 0) + { + switch (c) + { + case 'h': + usage(); + break; + case 'a': + with_attr = 1; + break; + case 'b': + basefile = optarg; + break; + case 'X': +#ifdef SUSE + add_auto = 1; +#endif + break; + default: + usage(); + exit(1); + } + } + if (with_attr) + pool_setloadcallback(pool, loadcallback, 0); - repo = repo_create(pool, ""); - while (argc-- > 1) + for (; optind < argc; optind++) { FILE *fp; - argv++; - if ((fp = fopen(*argv, "r")) == NULL) + if ((fp = fopen(argv[optind], "r")) == NULL) { - perror(argv[1]); - exit(0); + perror(argv[optind]); + exit(1); + } + if (repo_add_solv(repo, fp, 0)) + { + fprintf(stderr, "repo %s: %s\n", argv[optind], pool_errstr(pool)); + exit(1); } - repo_add_solv(repo, fp); fclose(fp); } - - create_filter(pool); - repo_write(repo, stdout, keyfilter, 0, 0, 0); +#ifdef SUSE + if (add_auto) + repo_add_autopattern(repo, 0); +#endif + tool_write(repo, basefile, 0); pool_free(pool); - return 0; }