END_TEST START_TEST (test_var) { char buf[PATH_MAX], tmp[PATH_MAX]; const char *s; tn_hash *vars; n_snprintf(buf, sizeof(buf), "%{1}%{2}"); vars = n_hash_new(16, NULL); n_hash_insert(vars, "1", "pol"); n_hash_insert(vars, "2", "dek"); s = poldek_util_expand_vars(tmp, sizeof(tmp), buf, '%', vars, 0); fail_if(s == NULL, "expand_vars failed"); fail_if(n_str_ne(s, "poldek"), "expand_vars() failed: %s -> %s", buf, s); fail_if(n_str_ne(tmp, "poldek"), "expand_vars() failed: %s -> %s", buf, tmp); n_snprintf(buf, sizeof(buf), "foobar"); s = poldek_util_expand_vars(tmp, sizeof(tmp), buf, '%', vars, 0); fail_if(s == NULL, "expand_vars failed"); fail_if(n_str_ne(s, buf), "expand_vars() failed: %s -> %s", buf, s); }
static tn_hash *do_load_repomd(xmlNode *node) { tn_hash *repomd; repomd = n_hash_new(16, (tn_fn_free)repomd_ent_free); n_hash_ctl(repomd, TN_HASH_NOCPKEY); for (; node; node = node->next) { struct repomd_ent *ent; if (node->type != XML_ELEMENT_NODE || strcmp((char *) node->name, "data") != 0) continue; if ((ent = load_repomd_ent(node))) { n_hash_insert(repomd, ent->type, ent); //printf("type = %s, loc = %s, ts = %ld\n", ent->type, ent->location, ent->ts); } } if (n_hash_size(repomd) == 0 || !n_hash_exists(repomd, "primary")) { logn(LOGERR, "repomd: empty or missing 'primary' entry"); n_hash_free(repomd); repomd = NULL; } return repomd; }
static tn_hash *loadconf(void) { char path[PATH_MAX], localpath[PATH_MAX]; tn_hash *htcnf = NULL, *local_htcnf = NULL; if (!config_path(path, localpath, sizeof(path))) return NULL; if (*path) htcnf = poldek_conf_load(path, POLDEK_LDCONF_FOREIGN); if (*localpath) local_htcnf = poldek_conf_load(localpath, POLDEK_LDCONF_FOREIGN); if (htcnf == NULL) { htcnf = local_htcnf; local_htcnf = NULL; } if (htcnf && local_htcnf) { tn_array *aliases = poldek_conf_get_sections(htcnf, "aliases"); if (aliases) /* XXX: yep, hacky a bit; sections should be movable via conf API */ n_hash_insert(local_htcnf, "global_aliases", n_ref(aliases)); n_hash_free(htcnf); htcnf = local_htcnf; local_htcnf = NULL; } return htcnf; }
int pkgmark_set(struct pkgmark_set *pmark, struct pkg *pkg, int set, uint32_t flag) { struct pkg_mark *pkg_mark; char idbuf[512]; const char *id; id = package_id(idbuf, sizeof(idbuf), pmark, pkg); pkg_mark = n_hash_get(pmark->ht, id); if (pkg_mark == NULL) { if (!set) return 1; pkg_mark = pmark->na->na_malloc(pmark->na, sizeof(*pkg_mark)); pkg_mark->pkg = pkg_link(pkg); pkg_mark->flags = 0; n_hash_insert(pmark->ht, id, pkg_mark); } if (set) pkg_mark->flags |= flag; else pkg_mark->flags &= ~flag; return 1; }
int pkguinf_restore_i18n(struct pkguinf *pkgu, tn_buf_it *it, const char *lang) { struct pkguinf_i18n *inf; char *summary, *description, *key; size_t slen = 0, dlen = 0, len = 0; if (pkgu->_ht == NULL) pkgu->_ht = n_hash_new(3, NULL); else if (n_hash_exists(pkgu->_ht, lang)) return 1; key = n_buf_it_getz(it, &len); if (*key != PKGUINF_SUMMARY) return 0; summary = n_buf_it_getz(it, &slen); key = n_buf_it_getz(it, &len); if (*key != PKGUINF_DESCRIPTION) return 0; description = n_buf_it_getz(it, &dlen); inf = pkguinf_i18n_new(pkgu->_na, summary, description); n_hash_insert(pkgu->_ht, lang, inf); pkgu_set_recodable(pkgu, PKGUINF_SUMMARY, inf->summary, lang); pkgu_set_recodable(pkgu, PKGUINF_DESCRIPTION, inf->description, lang); return 1; }
void test_hash_rpmqal(void) { tn_hash *h; char buf[1024]; FILE *f; if ((h = n_hash_new(300000, NULL)) == NULL) exit(1); //n_hash_ctl(h, TN_HASH_REHASH); f = popen("rpm -qal | sort -u", "r"); while (fgets(buf, sizeof(buf), f)) { buf[sizeof(buf) - 1] = '\0'; n_hash_insert(h, buf, "ma kota i psa"); if (!n_hash_exists(h, buf)) printf("ERROR %s not exists\n", buf); } pclose(f); // sleep(5); // n_hash_map(h, hash_map_func); n_hash_stats(h); n_hash_free(h); }
void test_hash(void) { int i, nn = 400000; tn_hash *h; if ((h = n_hash_new(1000000, NULL)) == NULL) exit(1); //n_hash_ctl(h, TN_HASH_REHASH); for (i = 0; i < nn; i++) { char str[40]; sprintf(str, "key%d", i); if (i % 10000 == 0) printf("%s\n", str); n_hash_insert(h, str, "ma kota i psa"); if (!n_hash_exists(h, str)) printf("ERROR %s not exists\n", str); } for (i = 0; i < nn; i++) { char str[40]; sprintf(str, "key%d", i); if (i % 10000 == 0) printf("get %s\n", str); if (!n_hash_exists(h, str)) printf("ERROR %s not exists\n", str); } n_hash_stats(h); n_hash_free(h); }
static int verify_list(tn_array *list, int maxno, const char *op) { tn_hash *dict = n_hash_new(64, NULL); int no; fail_if(n_array_size(list) != 3 * maxno, "%s: have %d, expected %d - some values lost", op, n_array_size(list), 3 * maxno); for (no = maxno - 1; no >= 0; no--) { /* from max to 0, to test param overwriting (test_config_lists_excl) */ int i = 0; while (values_list[i]) { char buf[64]; n_snprintf(buf, sizeof(buf), "%s%d", values_list[i], no); n_hash_insert(dict, buf, NULL); i++; } } while (n_array_size(list) > 0) { const char *op = n_array_pop(list); fail_ifnot(n_hash_exists(dict, op), "missing list element %s", op); } return 1; }
static tn_hash *build_mtime_index(tn_array *pkgs) { tn_hash *ht; int i; ht = n_hash_new(n_array_size(pkgs), NULL); for (i=0; i < n_array_size(pkgs); i++) { struct pkg *pkg = n_array_nth(pkgs, i); char key[2048]; if (pkg->fmtime && pkg->fsize) { n_snprintf(key, sizeof(key), "%s-%d-%d", pkg_filename_s(pkg), pkg->fmtime, pkg->fsize); n_hash_insert(ht, key, pkg); } } if (n_hash_size(ht) == 0) { n_hash_free(ht); return NULL; } return ht; }
static int pkgset_add_unreq(struct pkgset *ps, struct pkg *pkg, struct capreq *req, int mismatch) { tn_array *unreqs; if ((unreqs = n_hash_get(ps->_vrfy_unreqs, pkg_id(pkg))) == NULL) { unreqs = n_array_new(2, free, NULL); n_hash_insert(ps->_vrfy_unreqs, pkg_id(pkg), unreqs); } n_array_push(unreqs, pkg_unreq_new(req, mismatch)); return 1; }
static const char *get_rpm_capreq(const char *name) { static tn_hash *rpm_capreq_ht = NULL; const char *s; if (rpm_capreq_ht == NULL) rpm_capreq_ht = n_hash_new(21, free); if ((s = n_hash_get(rpm_capreq_ht, name)) == NULL) { n_hash_insert(rpm_capreq_ht, name, name); s = n_hash_get(rpm_capreq_ht, name); } return s; }
static void setup_langs(struct source *src) { const char **langs_tokl, **p, *lang; char lc_lang[256]; tn_hash *langs = NULL; int n; if (src->dscr) lang = src->dscr; else lang = lc_messages_lang(); if (lang == NULL || *lang == '\0' || strcasecmp(lang, "none") == 0) return; langs_tokl = n_str_tokl(lang, ":"); langs = n_hash_new(7, NULL); n_hash_ctl(langs, TN_HASH_NOCPKEY); n = 0; p = langs_tokl; while (*p) { if (n_hash_exists(langs, *p)) { p++; continue; } n += n_snprintf(&lc_lang[n], sizeof(lc_lang) - n, "%s:", *p); n_hash_insert(langs, *p, *p); p++; } if (!n_hash_exists(langs, "C")) n += n_snprintf(&lc_lang[n], sizeof(lc_lang) - n, "C:"); if (n) lc_lang[n - 1] = '\0'; /* eat last ':' */ src->lc_lang = n_strdupl(lc_lang, n - 1); //printf("source_setup_lc %s: %s -> %s\n", src->path, lang, lc_lang); n_hash_free(langs); n_str_tokl_free(langs_tokl); }
static loc_node *room_find_or_create(glui32 location, BOOL is_real) { loc_node *r; const char *preface = is_real ? "" : "fake"; const char *key = n_static_number(preface, location); r = (loc_node *) n_hash_lookup(key, &rooms); if(r == NULL) { unsigned n; r = (loc_node *) n_malloc(sizeof(loc_node)); r->number = location; r->found = FALSE; r->real = is_real; r->touched = FALSE; for(n = 0; n < NUM_EXITS; n++) { r->exits[n] = NULL; if(n < NUM_DIRS) r->outgoing[n] = NULL; } n_hash_insert(key, r, &rooms); } return r; }
static inline char *register_capreq_name(const char *name, int len) { char *nname; if (capreqname_h == NULL) { capreqname_na = n_alloc_new(128, TN_ALLOC_OBSTACK); capreqname_h = n_hash_new_na(capreqname_na, 1024 * 64, NULL); n_hash_ctl(capreqname_h, TN_HASH_NOCPKEY); } capreqname_cnt++; if (capreqname_cnt % 10000 == 0) DBGF_F("cnt %d\n", capreqname_cnt); DBGF("%s\n", name); if ((nname = n_hash_get(capreqname_h, name))) return nname; if (len == 0) len = strlen(name); nname = capreqname_na->na_malloc(capreqname_na, len + 1); memcpy(nname, name, len + 1); n_hash_insert(capreqname_h, nname, nname); return nname; }
/* hides duplicate options as interactive and cmdl opt set may contain same options TODO: !O(n^2) */ static void hide_child_options(const struct argp *parent, const struct argp *child) { int i = 0; while (1) { int j, key; const struct argp_option *opt = &parent->options[i++]; if (opt->name == NULL && opt->key == 0 && opt->doc == NULL) break; DBGF("%d) %d %s\n", i + 1, opt->key, opt->name); if (opt->key == 0) continue; key = opt->key; j = 0; while (1) { struct argp_option *opt = (struct argp_option *)&child->options[j++]; if (opt->name == NULL && opt->key == 0 && opt->doc == NULL) break; DBGF(" %d. %d %s\n", j + 1, opt->key, opt->name); if (key && key == opt->key) { DBGF("Hide %d %s (%s)\n", opt->key, opt->name, opt->doc); opt->flags |= OPTION_HIDDEN; } } } } static void argp_prepare_child_options(const struct argp *argp, int hide_child_opts) { int i; const struct argp *child; if (argp->children == NULL) return; i = 0; while ((child = argp->children[i++].argp)) { if (hide_child_opts) hide_child_options(argp, child); argp_prepare_child_options(child, hide_child_opts); } } static int load_conf(struct args *argsp) { unsigned flags = 0; if (argsp->cnflags & OPT_AS_FLAG(OPT_NOCONF)) flags |= POLDEK_LOADCONF_NOCONF; else if (argsp->cnflags & OPT_AS_FLAG(OPT_UPCONF)) flags |= POLDEK_LOADCONF_UPCONF; if ((flags & POLDEK_LOADCONF_NOCONF) && argsp->addon_cnflines == NULL) return 1; return poldek_load_config(argsp->ctx, argsp->path_conf, argsp->addon_cnflines, flags); } static void args_init(struct poclidek_ctx *cctx, struct poldek_ts *ts, int argc, char **argv, int mode) { memset(&args, 0, sizeof(args)); args.ctx = cctx->ctx; args.cctx = cctx; args.argc = 0; args.argv = n_malloc(sizeof(*argv) * argc); args.argv[0] = NULL; args.mode = mode; args.ts = ts; args.opctx = poclidek_op_ctx_new(); } static void parse_options(struct poclidek_ctx *cctx, struct poldek_ts *ts, int argc, char **argv, int mode) { struct argp argp = { common_options, parse_opt, args_doc, poldek_BANNER, 0, 0, 0}; int n, i, index, hide_child_opts = 0; struct argp_child *child; args_init(cctx, ts, argc, argv, mode); n = 0; while (poclidek_opgroup_tab[n]) n++; child = alloca((n + 2) * sizeof(*child)); args.opgroup_rts = n_array_new(n, NULL, NULL); for (i=0; i < n; i++) { struct poclidek_opgroup_rt *rt; child[i] = *(poclidek_opgroup_tab[i]->argp_child); rt = poclidek_opgroup_rt_new(args.ts, args.opctx); rt->run = poclidek_opgroup_tab[i]->run; n_array_push(args.opgroup_rts, rt); } child[i].argp = NULL; argp.children = child; if (poclidek_argv_is_help(argc, (const char **)argv)) hide_child_opts = 1; #if GENDOCBOOK hide_child_opts = 1; #endif argp_prepare_child_options(&argp, hide_child_opts); poldek_set_verbose(0); index = 0; argp_parse(&argp, argc, argv, ARGP_IN_ORDER, &index, &args); if (!poclidek_op_ctx_verify_major_mode(args.opctx)) exit(EXIT_FAILURE); if (!load_conf(&args)) exit(EXIT_FAILURE); #if GENDOCBOOK if (args.cnflags & OPT_AS_FLAG(OPT_DOCB)) { argp_as_docbook(&argp); exit(EXIT_SUCCESS); } #endif return; } int do_run(void) { int i, all_rc = OPGROUP_RC_NIL; n_assert(args.opgroup_rts); for (i=0; i < n_array_size(args.opgroup_rts); i++) { struct poclidek_opgroup_rt *rt = n_array_nth(args.opgroup_rts, i); int rc; if (rt->run == NULL) continue; rc = rt->run(rt); all_rc |= rc; if (rc & OPGROUP_RC_ERROR) break; } n_array_free(args.opgroup_rts); args.opgroup_rts = NULL; return all_rc; } extern int poldek_su(const char *user); static int do_su(int argc, char **argv) { const char *oprunas = "--runas"; char *user = NULL; int rc, i, n, is_runas = 0, oprunas_len, verbose = 0, noautosu = 0; char *nosu_opts[] = { "--mkidx", "--makeidx", NULL }; int nosu_opts_len[] = { 0, 0, 0 }; n = 0; while (nosu_opts[n]) { nosu_opts_len[n] = strlen(nosu_opts[n]); n++; } oprunas_len = strlen(oprunas); for (i=1; i < argc; i++) { n = 0; while (noautosu == 0 && nosu_opts[n]) { if (strncmp(argv[i], nosu_opts[n], nosu_opts_len[n]) == 0) noautosu = 1; n++; } if (strncmp(argv[i], "-v", 2) == 0) { char *p = argv[i] + 1; while (*p) { if (*p == 'v') verbose++; else if (*p) { /* non-'v' => is is not -v[v...] option */ verbose = 0; break; } p++; } } if (!is_runas && strncmp(argv[i], oprunas, oprunas_len) == 0) { char *p = argv[i] + oprunas_len; if (*p == '=') { p++; user = n_strdup(p); } else { /* next arg? */ if (i < argc - 1) user = n_strdup(argv[i + 1]); } is_runas = 1; } } if (is_runas) { if (user == NULL) { logn(LOGERR, _("%s: option '%s' requires an argument\n"), n_basenam(argv[0]), oprunas); return 0; } else if (getuid() != 0) { logn(LOGERR, _("%s: option '%s' gives no effect if program executed" " by ordinary user"), n_basenam(argv[0]), oprunas); return 0; } } else if (noautosu == 0 && getuid() == 0) { /* check config's runas */ tn_hash *cnf; cnf = poldek_conf_load_default(POLDEK_LDCONF_GLOBALONLY | POLDEK_LDCONF_NOVALIDATE); if (cnf) { tn_hash *global; const char *u; global = poldek_conf_get_section(cnf, "global"); if (global && (u = poldek_conf_get(global, "run_as", NULL))) { user = n_strdup(u); is_runas = 1; } n_hash_free(cnf); } } if (!is_runas) return 1; n_assert(user); if (*user == '\0' || strcmp(user, "none") == 0) /* empty or 'none' => ret */ return 1; verbose = poldek_set_verbose(verbose); rc = poldek_su(user); free(user); poldek_set_verbose(verbose); return rc; } static int load_packages(struct poclidek_ctx *cctx, unsigned cnflags) { unsigned ldflags = POCLIDEK_LOAD_AVAILABLE; if ((cnflags & OPT_AS_FLAG(OPT_SKIPINSTALLED)) == 0) ldflags |= POCLIDEK_LOAD_INSTALLED; if (!poclidek_load_packages(cctx, ldflags)) return 0; return 1; } static int run_poldek(struct poclidek_ctx *cctx) { int rc; if (!load_packages(cctx, args.cnflags)) return 0; if (args.shcmd) rc = poclidek_execline(cctx, args.ts, args.shcmd); else rc = poclidek_shell(cctx); return rc; } static int run_ipoldek(struct poclidek_ctx *cctx) { int rc = 1; #if ENABLE_TRACE i = 0; DBGF("verbose %d, argc = %d\n", verbose, args.argc); while (args.argv[i]) printf(" %s", args.argv[i++]); printf("\n"); #endif if (args.argc > 0) rc = poclidek_exec(cctx, args.ts, args.argc, (const char **)args.argv); else /* lonely ipoldek -> run shell as poldek does */ rc = run_poldek(cctx); return rc; } int main(int argc, char **argv) { struct poldek_ctx *ctx; struct poclidek_ctx *cctx; struct poldek_ts *ts; int rc = 1, rrc, mode = RUNMODE_POLDEK; const char *bn; if (!poldeklib_init()) return 1; if (!do_su(argc, argv)) return 1; setlocale(LC_MESSAGES, ""); setlocale(LC_CTYPE, ""); bn = n_basenam(argv[0]); if (strcmp(bn, "apoldek") == 0 || strcmp(bn, "ipoldek") == 0) mode = RUNMODE_APT; DBGF("mode %d %s %s\n", mode, n_basenam(argv[0]), argv[0]); ctx = poldek_new(0); ts = poldek_ts_new(ctx, 0); cctx = poclidek_new(ctx); parse_options(cctx, ts, argc, argv, mode); if (!poldek_setup(ctx)) exit(EXIT_FAILURE); if (poldek_VERBOSE == 0) poldek_set_verbose(1); rrc = do_run(); if (rrc & OPGROUP_RC_ERROR) exit(EXIT_FAILURE); if ((args.cnflags & OPT_AS_FLAG(OPT_SHELL)) == 0) { /*no explicit --shell*/ if (rrc & OPGROUP_RC_OK) /* something minor cmd was executed */ goto out; if (args.cnflags & OPT_AS_FLAG(OPT_UPCONF)) /*UPCONF is major mode*/ goto out; } if (args.mode == RUNMODE_POLDEK) rc = run_poldek(cctx); else if (args.mode == RUNMODE_APT) rc = run_ipoldek(cctx); out: poldek_ts_free(ts); poclidek_free(cctx); poldek_free(ctx); poldeklib_destroy(); return rc ? 0 : -1; } #if GENDOCBOOK #define GENDOCBOOK_SECT 1 /* gen <sect2> */ static void docbook_opt(tn_hash *idh, FILE **st, struct argp_option *opt, tn_array *aliases) { FILE *stream = *st; char *id = NULL, docfile[PATH_MAX], *doc; int c; if (opt->doc && opt->name == NULL && opt->key == 0) { /* group */ char *name, *p, path[PATH_MAX], doc[PATH_MAX], idsect[256]; int n; if (stream) { fprintf(stream, "</variablelist>\n"); #if GENDOCBOOK_SECT fprintf(stream, "</sect2>\n"); #endif //printf("->CLOSE\n"); fclose(stream); } n_strdupap(opt->doc, &name); p = name; while (*p) { if (isspace(*p)) *p = '_'; if (*p == ':') *p = '\0'; if (*p == '/') *p = '-'; *p = tolower(*p); p++; } n_snprintf(idsect, sizeof(idsect), "ref.cmdl.%s", name); n_snprintf(path, sizeof(path), "manual/ref%.4d-%s.xml", opt->group, name); stream = fopen(path, "w"); //printf("->OPEN %s\n", path); if (stream == NULL) { //printf("->OPEN %s\n", path); n_assert(stream); } fprintf(stream, "<!-- This file is autogenerated, DO NOT modify it -->\n\n"); *st = stream; n = n_snprintf(doc, sizeof(doc), "%s", opt->doc); if (doc[n - 1] == ':') doc[n - 1] = '\0'; #if GENDOCBOOK_SECT fprintf(stream, "<sect2 id=\"%s\"><title>%s</title>\n", idsect, doc); fprintf(stream, "<variablelist><title></title>\n", doc); #else fprintf(stream, "<variablelist><title>%s</title>\n", doc); #endif return; } n_assert(stream); fprintf(stream, "<varlistentry><term><option"); id = alloca(256); if (opt->name) strcpy(id, opt->name); else { c = opt->key; n_assert (c > 0 && c < 255 && isascii(c)); n_snprintf(id, 256, "%c", c); } //printf("id = %s\n", id); if (!n_hash_exists(idh, id)) n_hash_insert(idh, id, NULL); else { /* suffix with id_group, not so nice */ n_snprintf(&id[strlen(id)], 200, "%d", opt->group); n_hash_insert(idh, id, NULL); } fprintf(stream, " id=\"ref.cmdl.%s\"", id); fprintf(stream, ">"); c = opt->key; if (c > 0 && c < 255 && isascii(c)) fprintf(stream, "-%c", c); else c = 0; if (opt->name) fprintf(stream, "%s--%s", c ? ", " : "", opt->name); fprintf(stream, "%s%s%s%s", (opt->flags & OPTION_ARG_OPTIONAL) ? "[" : "", opt->arg ? "=" : "", opt->arg ? opt->arg : "", (opt->flags & OPTION_ARG_OPTIONAL) ? "]" : ""); fprintf(stream, " </option></term>\n"); fprintf(stream, " <listitem>\n"); n_snprintf(docfile, sizeof(docfile), "manual/ref.cmdl.%s.xml", id); doc = opt->doc ? (char*)opt->doc : "-"; if (access(docfile, R_OK) != 0) { fprintf(stream, " <para>\n %s\n", doc); fprintf(stream, " </para>\n"); } else { fprintf(stream, "<xi:include href=\"%s\" " "xmlns:xi=\"http://www.w3.org/2001/XInclude\" />", docfile); } fprintf(stream, " </listitem>\n"); fprintf(stream, "</varlistentry>\n"); }
int pkguinf_set(struct pkguinf *pkgu, int tag, const char *val, const char *lang) { int len; len = strlen(val); switch (tag) { case PKGUINF_LICENSE: set_member(pkgu, &pkgu->license, val, len); break; case PKGUINF_URL: set_member(pkgu, &pkgu->url, val, len); break; case PKGUINF_VENDOR: set_member(pkgu, &pkgu->vendor, val, len); break; case PKGUINF_BUILDHOST: set_member(pkgu, &pkgu->buildhost, val, len); break; case PKGUINF_DISTRO: set_member(pkgu, &pkgu->distro, val, len); break; case PKGUINF_LEGACY_SOURCERPM: n_die("SOURCERPM"); break; case PKGUINF_SUMMARY: case PKGUINF_DESCRIPTION: { struct pkguinf_i18n *inf; if (pkgu->_ht == NULL) pkgu->_ht = n_hash_new(3, NULL); if (lang == NULL) lang = "C"; if ((inf = n_hash_get(pkgu->_ht, lang)) == NULL) { inf = pkguinf_i18n_new(pkgu->_na, NULL, NULL); n_hash_insert(pkgu->_ht, lang, inf); } if (tag == PKGUINF_SUMMARY) { inf->summary = na_strdup(pkgu->_na, val, len); pkgu_set_recodable(pkgu, PKGUINF_SUMMARY, inf->summary, lang); } else { inf->description = na_strdup(pkgu->_na, val, len); pkgu_set_recodable(pkgu, PKGUINF_DESCRIPTION, inf->description, lang); } } default: if (poldek_VERBOSE > 2) logn(LOGERR, "%d: unknown tag", tag); return 0; break; } return 1; }
/* check if cnfl conflicts with db */ static int find_db_conflicts_cnfl_with_db(int indent, struct i3ctx *ictx, struct pkg *pkg, const struct capreq *cnfl) { int i, ncnfl = 0; tn_hash *ht = NULL; tn_array *dbpkgs = NULL; pkgdb_search(ictx->ts->db, &dbpkgs, PMTAG_CAP, capreq_name(cnfl), iset_packages_by_recno(ictx->unset), PKG_LDWHOLE_FLDEPDIRS); if (dbpkgs == NULL) return 0; msgn_i(4, indent, "Processing conflict %s:%s...", pkg_id(pkg), capreq_stra(cnfl)); if (ictx->ts->getop(ictx->ts, POLDEK_OP_ALLOWDUPS) && n_array_size(dbpkgs) > 1) { ht = n_hash_new(21, NULL); n_hash_ctl(ht, TN_HASH_NOCPKEY); for (i=0; i<n_array_size(dbpkgs); i++) { struct pkg *dbpkg = n_array_nth(dbpkgs, i); if (n_hash_exists(ht, dbpkg->name)) continue; if (!pkg_match_req(dbpkg, cnfl, 1)) { msgn_i(5, indent, "%s: conflict disarmed by %s", capreq_stra(cnfl), pkg_id(dbpkg)); n_hash_insert(ht, dbpkg->name, pkg); } } } for (i=0; i < n_array_size(dbpkgs); i++) { struct pkg *dbpkg = n_array_nth(dbpkgs, i); msg_i(6, indent, "%d. %s (%s) <-> %s ?\n", i, pkg_id(pkg), capreq_stra(cnfl), pkg_id(dbpkg)); if (ht && n_hash_exists(ht, dbpkg->name)) continue; if (!pkg_is_colored_like(pkg, dbpkg)) continue; if (pkg_match_req(dbpkg, cnfl, 1)) { if (!resolve_conflict(indent, ictx, pkg, cnfl, dbpkg)) { i3_error(ictx, pkg, I3ERR_DBCONFLICT, _("%s (cnfl %s) conflicts with installed %s"), pkg_id(pkg), capreq_stra(cnfl), pkg_id(dbpkg)); logn(LOGERR, _("%s (cnfl %s) conflicts with installed %s"), pkg_id(pkg), capreq_stra(cnfl), pkg_id(dbpkg)); ncnfl++; } } } if (ht) n_hash_free(ht); n_array_free(dbpkgs); return ncnfl; }
int iset_provides(struct iset *iset, const struct capreq *cap) { char *dirname, *basename, path[PATH_MAX]; char *capnvr = NULL, *capname = NULL; int i, is_file = 0; struct pkg *pkg = NULL; if (!capreq_has_ver(cap)) { capname = (char*)capreq_name(cap); } else { capname = capnvr = alloca(256); capreq_snprintf(capnvr, 256, cap); } if ((pkg = n_hash_get(iset->capcache, capname))) { DBGF("cache hit %s\n", capreq_stra(cap)); return 1; } if (capreq_is_file(cap)) { is_file = 1; strncpy(path, capreq_name(cap), sizeof(path)); path[PATH_MAX - 1] = '\0'; n_basedirnam(path, &dirname, &basename); n_assert(dirname); if (*dirname == '\0') { /* path = "/foo" */ char *tmp; n_strdupap("/", &tmp); dirname = tmp; } n_assert(*dirname); if (*dirname == '/' && *(dirname + 1) != '\0') dirname++; } pkg = NULL; for (i=0; i < n_array_size(iset->pkgs); i++) { struct pkg *p = n_array_nth(iset->pkgs, i); if (is_file && pkg_has_path(p, dirname, basename)) pkg = p; else if (pkg_match_req(p, cap, 1)) pkg = p; DBGF(" - %s provides %s -> %s\n", pkg_id(p), capreq_stra(cap), pkg ? "YES" : "NO"); if (pkg) break; } if (pkg != NULL) { DBGF("addto cache %s\n", capnvr ? capnvr : capname); if (capnvr == NULL) { n_hash_insert(iset->capcache, capname, pkg); } else { n_hash_insert(iset->capcache, capnvr, pkg); if (!n_hash_exists(iset->capcache, capname)) n_hash_insert(iset->capcache, capname, pkg); } } DBGF("%s -> %s\n", capreq_stra(cap), pkg ? pkg_id(pkg) : "NO"); return pkg != NULL; }
int pkgset_verify_deps(struct pkgset *ps, int strict) { unsigned int i,j; int nerrors = 0; struct pkgmark_set *pms; tn_hash *cache; cache = n_hash_new(n_array_size(ps->pkgs), (tn_fn_free)n_array_free); n_assert(ps->_vrfy_unreqs == NULL); ps->_vrfy_unreqs = n_hash_new(127, (tn_fn_free)n_array_free); pms = pkgmark_set_new(n_array_size(ps->pkgs) / 10, 0); msgn(4, _("\nVerifying dependencies...")); for (i=0; i < n_array_size(ps->pkgs); i++) { struct pkg *pkg; pkg = n_array_nth(ps->pkgs, i); if (pkg->reqs == NULL) continue; n_assert(n_array_size(pkg->reqs)); pkg->reqpkgs = n_array_new(n_array_size(pkg->reqs)/2+2, NULL, (tn_fn_cmp)reqpkg_cmp); msgn(4, "%d. %s", i+1, pkg_id(pkg)); for (j=0; j < n_array_size(pkg->reqs); j++) { struct capreq *req = n_array_nth(pkg->reqs, j); char streq[256]; tn_array *matches = NULL; capreq_snprintf(streq, sizeof(streq), req); if (n_hash_exists(cache, streq)) { matches = n_hash_get(cache, streq); if (!matches) msgn(4, _(" req %-35s --> NOT FOUND"), streq); else if (n_array_size(matches) > 0) { unsigned int ii; msg(4, " req %-35s --> ", streq); for (ii=0; ii < n_array_size(matches); ii++) msg(4, "_%s, ", pkg_id(n_array_nth(matches, ii))); msg(4, "_\n"); } } else { int found = pkgset_find_match_packages(ps, pkg, req, &matches, strict); if (found && matches == NULL) matches = pkgs_array_new(2); n_hash_insert(cache, streq, matches); } if (matches == NULL) /* not found / unmatched */ goto l_err_notfound; if (n_array_size(matches) == 0) /* selfmatches */ continue; if (setup_required_pkgs(pkg, req, matches)) continue; goto l_err_match; /* found but not fit */ l_err_notfound: nerrors++; if (poldek_VERBOSE > 3) msgn(4, _(" req %-35s --> NOT FOUND"), capreq_snprintf_s(req)); pkgset_add_unreq(ps, pkg, req, 0); pkg_set_unmetdeps(pms, pkg); continue; l_err_match: nerrors++; pkgset_add_unreq(ps, pkg, req, 1); pkg_set_unmetdeps(pms, pkg); } } if (nerrors) mark_badreqs(pms); else msgn(4, _("No unsatisfied dependencies detected -- OK")); if (nerrors) msgn(4, _("%d unsatisfied dependencies, %d packages cannot be installed"), nerrors, ps->nerrors); n_hash_free(cache); pkgmark_set_free(pms); return nerrors == 0; }
struct pkguinf *pkguinf_ldrpmhdr(tn_alloc *na, void *hdr, tn_array *loadlangs) { tn_array *langs = NULL; char **summs, **descrs; int nsumms, ndescrs; int i, n; struct pkguinf *pkgu; Header h = hdr; pkgu = pkguinf_new(na); pkgu->_ht = n_hash_new(3, NULL); if ((langs = pm_rpmhdr_langs(h))) { tn_array *sl_langs = NULL; char *lc_lang = NULL, *sl_lang = NULL; pm_rpmhdr_get_raw_entry(h, RPMTAG_SUMMARY, (void*)&summs, &nsumms); pm_rpmhdr_get_raw_entry(h, RPMTAG_DESCRIPTION, (void*)&descrs, &ndescrs); n = nsumms; if (n > ndescrs) n = ndescrs; pkgu->_langs_rpmhdr = n_array_new(4, free, NULL); for (i=0; i < n; i++) { struct pkguinf_i18n *inf; const char *lang; if (n_array_size(langs) < i) break; lang = n_array_nth(langs, i); n_array_push(pkgu->_langs_rpmhdr, n_strdup(lang)); inf = pkguinf_i18n_new(pkgu->_na, summs[i], descrs[i]); n_hash_insert(pkgu->_ht, lang, inf); } /* langs which weren't added to the pkgu->_ht have to be removed, otherwise lc_lang_select() may return value which doesn't exist in the hash table */ if (n < n_array_size (langs)) { for (i = n_array_size(langs); i > n; i--) langs = n_array_remove_nth(langs, i - 1); } if (loadlangs) { for (i = 0; i < n_array_size(loadlangs); i++) { const char *loadlang = n_array_nth(loadlangs, i); if (loadlang == NULL) continue; if (lc_lang == NULL) lc_lang = n_strdup(loadlang); else { lc_lang = n_str_concat(lc_lang, ":", loadlang, NULL); } } } else lc_lang = n_strdup(lc_messages_lang()); sl_langs = lc_lang_select(langs, lc_lang); if (sl_langs == NULL) sl_lang = "C"; else sl_lang = n_array_nth(sl_langs, 0); if (sl_lang) { struct pkguinf_i18n *inf; inf = n_hash_get(pkgu->_ht, sl_lang); n_assert(inf); pkgu_set_recodable(pkgu, PKGUINF_SUMMARY, inf->summary, sl_lang); pkgu_set_recodable(pkgu, PKGUINF_DESCRIPTION, inf->description, sl_lang); } n_array_free(langs); n_array_cfree(&sl_langs); free(lc_lang); free(summs); free(descrs); } pkgu->vendor = cp_tag(pkgu->_na, h, RPMTAG_VENDOR); pkgu->license = cp_tag(pkgu->_na, h, PM_RPMTAG_LICENSE); pkgu->url = cp_tag(pkgu->_na, h, RPMTAG_URL); pkgu->distro = cp_tag(pkgu->_na, h, RPMTAG_DISTRIBUTION); pkgu->buildhost = cp_tag(pkgu->_na, h, RPMTAG_BUILDHOST); pkgu->legacy_sourcerpm = NULL; pkgu->changelog = load_changelog_from_rpmhdr(pkgu->_na, h); return pkgu; }