static int do_show(struct pkg *pkg, const char *tag) { const pkg_object *annotations, *note; pkg_iter it = NULL; int ret = EPKG_OK; pkg_get(pkg, PKG_ANNOTATIONS, &annotations); while ((note = pkg_object_iterate(annotations, &it)) != NULL) { if (strcmp(tag, pkg_object_key(note)) == 0) { if (quiet) printf("%s\n", pkg_object_string(note)); else pkg_printf("%n-%v: Tag: %S Value: %S\n", pkg, pkg, pkg_object_key(note), pkg_object_string(note)); } } return (ret); }
static int pkg_repo_binary_add_pkg(struct pkg *pkg, const char *pkg_path, sqlite3 *sqlite, bool forced) { const char *name, *version, *origin, *comment, *desc; const char *arch, *maintainer, *www, *prefix, *sum, *rpath; const char *olddigest, *manifestdigest; int64_t flatsize, pkgsize; int64_t licenselogic; int ret; struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_shlib *shlib = NULL; const pkg_object *obj, *licenses, *categories, *annotations; pkg_iter it; int64_t package_id; pkg_get(pkg, PKG_ORIGIN, &origin, PKG_NAME, &name, PKG_VERSION, &version, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_ARCH, &arch, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_PREFIX, &prefix, PKG_FLATSIZE, &flatsize, PKG_LICENSE_LOGIC, &licenselogic, PKG_CKSUM, &sum, PKG_PKGSIZE, &pkgsize, PKG_REPOPATH, &rpath, PKG_LICENSES, &licenses, PKG_CATEGORIES, &categories, PKG_ANNOTATIONS, &annotations, PKG_OLD_DIGEST, &olddigest, PKG_DIGEST, &manifestdigest); try_again: if ((ret = pkg_repo_binary_run_prstatement(PKG, origin, name, version, comment, desc, arch, maintainer, www, prefix, pkgsize, flatsize, (int64_t)licenselogic, sum, rpath, manifestdigest, olddigest)) != SQLITE_DONE) { if (ret == SQLITE_CONSTRAINT) { switch(pkg_repo_binary_delete_conflicting(origin, version, pkg_path, forced)) { case EPKG_FATAL: /* sqlite error */ ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(PKG)); return (EPKG_FATAL); break; case EPKG_END: /* repo already has newer */ return (EPKG_END); break; default: /* conflict cleared, try again */ goto try_again; break; } } else { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(PKG)); return (EPKG_FATAL); } } package_id = sqlite3_last_insert_rowid(sqlite); if (pkg_repo_binary_run_prstatement (FTS_APPEND, package_id, name, version, origin) != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(FTS_APPEND)); return (EPKG_FATAL); } dep = NULL; while (pkg_deps(pkg, &dep) == EPKG_OK) { if (pkg_repo_binary_run_prstatement(DEPS, pkg_dep_origin(dep), pkg_dep_name(dep), pkg_dep_version(dep), package_id) != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(DEPS)); return (EPKG_FATAL); } } it = NULL; while ((obj = pkg_object_iterate(categories, &it))) { ret = pkg_repo_binary_run_prstatement(CAT1, pkg_object_string(obj)); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(CAT2, package_id, pkg_object_string(obj)); if (ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(CAT2)); return (EPKG_FATAL); } } it = NULL; while ((obj = pkg_object_iterate(licenses, &it))) { ret = pkg_repo_binary_run_prstatement(LIC1, pkg_object_string(obj)); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(LIC2, package_id, pkg_object_string(obj)); if (ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(LIC2)); return (EPKG_FATAL); } } option = NULL; while (pkg_options(pkg, &option) == EPKG_OK) { ret = pkg_repo_binary_run_prstatement(OPT1, pkg_option_opt(option)); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(OPT2, pkg_option_opt(option), pkg_option_value(option), package_id); if(ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(OPT2)); return (EPKG_FATAL); } } shlib = NULL; while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) { const char *shlib_name = pkg_shlib_name(shlib); ret = pkg_repo_binary_run_prstatement(SHLIB1, shlib_name); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(SHLIB_REQD, package_id, shlib_name); if (ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(SHLIB_REQD)); return (EPKG_FATAL); } } shlib = NULL; while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) { const char *shlib_name = pkg_shlib_name(shlib); ret = pkg_repo_binary_run_prstatement(SHLIB1, shlib_name); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(SHLIB_PROV, package_id, shlib_name); if (ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(SHLIB_PROV)); return (EPKG_FATAL); } } it = NULL; while ((obj = pkg_object_iterate(annotations, &it))) { const char *note_tag = pkg_object_key(obj); const char *note_val = pkg_object_string(obj); ret = pkg_repo_binary_run_prstatement(ANNOTATE1, note_tag); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(ANNOTATE1, note_val); if (ret == SQLITE_DONE) ret = pkg_repo_binary_run_prstatement(ANNOTATE2, package_id, note_tag, note_val); if (ret != SQLITE_DONE) { ERROR_SQLITE(sqlite, pkg_repo_binary_sql_prstatement(ANNOTATE2)); return (EPKG_FATAL); } } return (EPKG_OK); }
int exec_alias(int argc, char **argv) { const pkg_object *all_aliases; const pkg_object *alias; pkg_iter it = NULL; int ch; int ret = EX_OK; bool list = false; struct option longopts[] = { { "quiet", no_argument, NULL, 'q' }, { "list", no_argument, NULL, 'l' }, { NULL, 0, NULL, 0 }, }; while ((ch = getopt_long(argc, argv, "+ql", longopts, NULL)) != -1) { switch (ch) { case 'q': quiet = true; break; case 'l': list = true; break; default: usage_alias(); return (EX_USAGE); } } argc -= optind; argv += optind; all_aliases = pkg_config_get("ALIAS"); if (argc == 0) { if (!quiet && list) printf("%s\n", "ALIAS"); else if (!quiet) printf("%-20s %s\n", "ALIAS", "ARGUMENTS"); while ((alias = pkg_object_iterate(all_aliases, &it))) { if (list) printf("%s\n", pkg_object_key(alias)); else printf("%-20s '%s'\n", pkg_object_key(alias), pkg_object_string(alias)); } return (ret); } for (int i = 0; i < argc; i++) { it = NULL; while ((alias = pkg_object_iterate(all_aliases, &it))) { if (strcmp(argv[i], pkg_object_key(alias)) == 0) break; } if (alias) { if (list) printf("%s\n", argv[i]); else printf("%-20s '%s'\n", argv[i], pkg_object_string(alias)); } else { warnx("No such alias: '%s'", argv[i]); ret = EX_UNAVAILABLE; } } return (ret); }