static void print_recursive_rdeps(kh_pkgs_t *head, struct pkg *p, struct sbuf *sb, kh_pkgs_t *seen, bool top) { struct pkg_dep *dep = NULL; int ret; khint_t k, h; while(pkg_rdeps(p, &dep) == EPKG_OK) { const char *name = pkg_dep_get(dep, PKG_DEP_NAME); k = kh_get_pkgs(seen, name); if (k == kh_end(seen)) { h = kh_get_pkgs(head, name); if (h != kh_end(head)) { kh_put_pkgs(seen, name, &ret); if (!top) sbuf_cat(sb, ", "); sbuf_cat(sb, name); print_recursive_rdeps(head, kh_val(head, h), sb, seen, false); top = false; } } } }
int pkg_delete(struct pkg *pkg, struct pkgdb *db, int force) { struct pkg **rdeps; int i, ret; struct sbuf *rdep_msg; if (pkg == NULL) return (ERROR_BAD_ARG("pkg")); if (db == NULL) return (ERROR_BAD_ARG("db")); /* * Ensure that we have all the informations we need */ if ((ret = pkgdb_loadrdeps(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadfiles(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadscripts(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadmtree(db, pkg)) != EPKG_OK) return (ret); rdeps = pkg_rdeps(pkg); if (rdeps[0] != NULL) { rdep_msg = sbuf_new_auto(); sbuf_printf(rdep_msg, "%s-%s is required by other packages:", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION)); for (i = 0;rdeps[i] != NULL; i++) { sbuf_cat(rdep_msg, " "); sbuf_printf(rdep_msg, "%s-%s", pkg_get(rdeps[i], PKG_NAME), pkg_get(rdeps[i], PKG_VERSION)); } if (!force) { sbuf_finish(rdep_msg); ret = pkg_error_set(EPKG_REQUIRED, "%s", sbuf_get(rdep_msg)); sbuf_free(rdep_msg); return ret; } sbuf_cat(rdep_msg, ", deleting anyway"); sbuf_finish(rdep_msg); fprintf(stderr, "%s\n", sbuf_get(rdep_msg)); sbuf_free(rdep_msg); } if ((ret = pkg_script_pre_deinstall(pkg)) != EPKG_OK) return (ret); if ((ret = pkg_delete_files(pkg, force)) != EPKG_OK) return (ret); if ((ret = pkg_script_post_deinstall(pkg)) != EPKG_OK) return (ret); return (pkgdb_unregister_pkg(db, pkg_get(pkg, PKG_ORIGIN))); }
static void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_category *cat = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_license *lic = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_script *scripts = NULL; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); break; } case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); } break; case 'C': while (pkg_categories(pkg, &cat) == EPKG_OK) { format_str(pkg, output, qstr, cat); printf("%s\n", sbuf_get(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_get(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_get(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_get(output)); } break; case 'L': while (pkg_licenses(pkg, &lic) == EPKG_OK) { format_str(pkg, output, qstr, lic); printf("%s\n", sbuf_get(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_get(output)); } break; case 'G': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_get(output)); } break; case 'S': while (pkg_scripts(pkg, &scripts) == EPKG_OK) { format_str(pkg, output, qstr, scripts); printf("%s\n", sbuf_get(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_get(output)); break; } sbuf_delete(output); }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; char *buf; struct pkg_kv *kv; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': buf = NULL; while (pkg_categories(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': buf = NULL; while (pkg_licenses(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'U': buf = NULL; while (pkg_users(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'G': buf = NULL; while (pkg_groups(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'B': buf = NULL; while (pkg_shlibs_required(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'b': buf = NULL; while (pkg_shlibs_provided(pkg, &buf) == EPKG_OK) { format_str(pkg, output, qstr, buf); printf("%s\n", sbuf_data(output)); } break; case 'A': pkg_get(pkg, PKG_ANNOTATIONS, &kv); while (kv != NULL) { format_str(pkg, output, qstr, kv); printf("%s\n", sbuf_data(output)); kv = kv->next; } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }
static int convert_to_old(const char *pkg_add_dbdir, bool dry_run) { struct pkgdb *db = NULL; struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; struct pkgdb_it *it = NULL; char *content, *name, *version, *buf; const char *tmp; int ret = EX_OK; char path[MAXPATHLEN]; int query_flags = PKG_LOAD_DEPS | PKG_LOAD_FILES | PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS | PKG_LOAD_MTREE | PKG_LOAD_USERS | PKG_LOAD_GROUPS | PKG_LOAD_RDEPS; FILE *fp, *rq; struct sbuf *install_script = sbuf_new_auto(); struct sbuf *deinstall_script = sbuf_new_auto(); if (mkdir(pkg_add_dbdir, 0755) != 0 && errno != EEXIST) err(EX_CANTCREAT, "%s", pkg_add_dbdir); if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) { pkgdb_close(db); return (EX_IOERR); } if ((it = pkgdb_query(db, NULL, MATCH_ALL)) == NULL) { ret = EPKG_FATAL; goto cleanup; } while (pkgdb_it_next(it, &pkg, query_flags) == EPKG_OK) { rq = NULL; pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); printf("Converting %s-%s...", name, version); if (dry_run) { printf("\n"); continue; } pkg_to_old(pkg); pkg_old_emit_content(pkg, &content); snprintf(path, MAXPATHLEN, "%s/%s-%s", pkg_add_dbdir, name, version); mkdir(path, 0755); snprintf(path, MAXPATHLEN, "%s/%s-%s/+CONTENTS", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(content, fp); fclose(fp); pkg_get(pkg, PKG_DESC, &buf); snprintf(path, MAXPATHLEN, "%s/%s-%s/+DESC", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(buf, fp); fclose(fp); pkg_get(pkg, PKG_COMMENT, &buf); snprintf(path, MAXPATHLEN, "%s/%s-%s/+COMMENT", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fprintf(fp, "%s\n", buf); fclose(fp); pkg_get(pkg, PKG_MESSAGE, &buf); if (buf != NULL && buf[0] != '\0') { snprintf(path, MAXPATHLEN, "%s/%s-%s/+DISPLAY", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(buf, fp); fclose(fp); } pkg_get(pkg, PKG_MTREE, &buf); if (buf != NULL && buf[0] != '\0') { snprintf(path, MAXPATHLEN, "%s/%s-%s/+MTREE_DIRS", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(buf, fp); fclose(fp); } sbuf_clear(install_script); tmp = pkg_script_get(pkg, PKG_SCRIPT_PRE_INSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(install_script) == 0) sbuf_cat(install_script, "#!/bin/sh\n\n"); sbuf_printf(install_script, "if [ \"$2\" = \"PRE-INSTALL\" ]; then\n" "%s\n" "fi\n", tmp); } tmp = pkg_script_get(pkg, PKG_SCRIPT_INSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(install_script) == 0) sbuf_cat(install_script, "#!/bin/sh\n\n"); sbuf_cat(install_script, tmp); } tmp = pkg_script_get(pkg, PKG_SCRIPT_POST_INSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(install_script) == 0) sbuf_cat(install_script, "#!/bin/sh\n\n"); sbuf_printf(install_script, "if [ \"$2\" = \"POST-INSTALL\" ]; then\n" "%s\n" "fi\n", tmp); } if (sbuf_len(install_script) > 0) { sbuf_finish(install_script); snprintf(path, MAXPATHLEN, "%s/%s-%s/+INSTALL", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(sbuf_data(install_script), fp); fclose(fp); } sbuf_clear(deinstall_script); tmp = pkg_script_get(pkg, PKG_SCRIPT_PRE_DEINSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(deinstall_script) == 0) sbuf_cat(deinstall_script, "#!/bin/sh\n\n"); sbuf_printf(deinstall_script, "if [ \"$2\" = \"DEINSTALL\" ]; then\n" "%s\n" "fi\n", tmp); } tmp = pkg_script_get(pkg, PKG_SCRIPT_DEINSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(deinstall_script) == 0) sbuf_cat(deinstall_script, "#!/bin/sh\n\n"); sbuf_cat(deinstall_script, tmp); } tmp = pkg_script_get(pkg, PKG_SCRIPT_POST_DEINSTALL); if (tmp != NULL && tmp[0] != '\0') { if (sbuf_len(deinstall_script) == 0) sbuf_cat(deinstall_script, "#!/bin/sh\n\n"); sbuf_printf(deinstall_script, "if [ \"$2\" = \"POST-DEINSTALL\" ]; then\n" "%s\n" "fi\n", tmp); } if (sbuf_len(deinstall_script) > 0) { sbuf_finish(deinstall_script); snprintf(path, MAXPATHLEN, "%s/%s-%s/+DEINSTALL", pkg_add_dbdir, name, version); fp = fopen(path, "w"); fputs(sbuf_data(deinstall_script), fp); fclose(fp); } snprintf(path, MAXPATHLEN, "%s/%s-%s/+REQUIRED_BY", pkg_add_dbdir, name, version); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { if (rq == NULL) rq = fopen(path, "w"); fprintf(rq, "%s-%s\n", pkg_dep_name(dep), pkg_dep_version(dep)); } if (rq != NULL) fclose(rq); printf("done.\n"); free(content); } sbuf_delete(install_script); sbuf_delete(deinstall_script); cleanup: pkg_free(pkg); pkgdb_it_free(it); pkgdb_close(db); return (ret); }
int print_info(struct pkg * const pkg, unsigned int opt) { struct pkg_dep *dep = NULL; struct pkg_file *file = NULL; struct pkg_category *cat = NULL; struct pkg_license *lic = NULL; struct pkg_option *option = NULL; bool multirepos_enabled = false; char *m; char size[7]; const char *name, *version, *prefix, *origin, *reponame, *repourl; const char *maintainer, *www, *comment, *desc; int64_t flatsize, newflatsize, newpkgsize; lic_t licenselogic; pkg_config_bool(PKG_CONFIG_MULTIREPOS, &multirepos_enabled); pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_PREFIX, &prefix, PKG_ORIGIN, &origin, PKG_REPONAME, &reponame, PKG_REPOURL, &repourl, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &newpkgsize, PKG_LICENSE_LOGIC, &licenselogic); if (opt & INFO_RAW) { pkg_emit_manifest(pkg, &m); printf("%s\n", m); free(m); } else if (opt & INFO_FULL) { printf("%-15s: %s\n", "Name", name); printf("%-15s: %s\n", "Version", version); printf("%-15s: %s\n", "Origin", origin); printf("%-15s: %s\n", "Prefix", prefix); if ((pkg_type(pkg) == PKG_REMOTE) && multirepos_enabled) printf("%-15s: %s [%s]\n", "Repository", reponame, repourl); if (!pkg_list_is_empty(pkg, PKG_CATEGORIES)) { printf("%-15s:", "Categories"); while (pkg_categories(pkg, &cat) == EPKG_OK) printf(" %s", pkg_category_name(cat)); printf("\n"); } if (!pkg_list_is_empty(pkg, PKG_LICENSES)) { printf("%-15s:", "Licenses"); while (pkg_licenses(pkg, &lic) == EPKG_OK) { printf(" %s", pkg_license_name(lic)); if (licenselogic != 1) printf(" %c", licenselogic); else printf(" "); } printf("\b \n"); } printf("%-15s: %s\n", "Maintainer", maintainer); printf("%-15s: %s\n", "WWW", www); printf("%-15s: %s\n", "Comment", comment); if (!pkg_list_is_empty(pkg, PKG_OPTIONS)) { printf("%-15s: \n", "Options"); while (pkg_options(pkg, &option) == EPKG_OK) printf("\t%s: %s\n", pkg_option_opt(option), pkg_option_value(option)); } if (pkg_type(pkg) == PKG_INSTALLED || pkg_type(pkg) == PKG_FILE) { humanize_number(size, sizeof(size), flatsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Flat size", size); } else { humanize_number(size, sizeof(size), newflatsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Flat size", size); humanize_number(size, sizeof(size), newpkgsize, "B", HN_AUTOSCALE, 0); printf("%-15s: %s\n", "Pkg size", size); } printf("%-15s: \n%s\n", "Description", desc); printf("\n"); } else if (opt & INFO_PRINT_DEP) { if (!(opt & INFO_QUIET)) printf("%s-%s depends on:\n", name, version); while (pkg_deps(pkg, &dep) == EPKG_OK) { printf("%s-%s\n", pkg_dep_get(dep, PKG_DEP_NAME), pkg_dep_get(dep, PKG_DEP_VERSION)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_PRINT_RDEP) { if (!(opt & INFO_QUIET)) printf("%s-%s is required by:\n", name, version); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { printf("%s-%s\n", pkg_dep_get(dep, PKG_DEP_NAME), pkg_dep_get(dep, PKG_DEP_VERSION)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_LIST_FILES) { if (!(opt & INFO_QUIET)) printf("%s-%s owns the following files:\n", name, version); while (pkg_files(pkg, &file) == EPKG_OK) { printf("%s\n", pkg_file_get(file, PKG_FILE_PATH)); } if (!(opt & INFO_QUIET)) printf("\n"); } else if (opt & INFO_SIZE) { if (pkg_type(pkg) == PKG_INSTALLED) { humanize_number(size, sizeof(size), flatsize, "B", HN_AUTOSCALE, 0); printf("%s-%s size is: %s\n", name, version, size); } else { humanize_number(size, sizeof(size), newflatsize, "B", HN_AUTOSCALE, 0); printf("%s-%s flat size is: %s\n", name, version, size); humanize_number(size, sizeof(size), newpkgsize, "B", HN_AUTOSCALE, 0); printf("%s-%s package size is: %s\n", name, version, size); } } else if (opt & INFO_ORIGIN) { if (opt & INFO_QUIET) printf("%s\n", origin); else printf("%s-%s: %s\n", name, version, origin); } else if (opt & INFO_PREFIX) { if (opt & INFO_QUIET) printf("%s\n", prefix); else printf("%s-%s: %s\n", name, version, prefix); } else { if (opt & INFO_QUIET) printf("%s-%s\n", name, version); else { if ((pkg_type(pkg) == PKG_REMOTE) && multirepos_enabled) printf("%s-%s [repository: %s]: %s\n", name, version, reponame, comment); else printf("%s-%s: %s\n", name, version, comment); } } return (0); }
static void pipeevent(struct pkg_event *ev) { int i; struct pkg_dep *dep = NULL; struct sbuf *msg, *buf; struct pkg_event_conflict *cur_conflict; if (eventpipe < 0) return; msg = sbuf_new_auto(); buf = sbuf_new_auto(); switch(ev->type) { case PKG_EVENT_ERRNO: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {" "\"msg\": \"%s(%s): %s\"," "\"errno\": %d}}", sbuf_json_escape(buf, ev->e_errno.func), sbuf_json_escape(buf, ev->e_errno.arg), sbuf_json_escape(buf, strerror(ev->e_errno.no)), ev->e_errno.no); break; case PKG_EVENT_ERROR: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {\"msg\": \"%s\"}}", sbuf_json_escape(buf, ev->e_pkg_error.msg)); break; case PKG_EVENT_NOTICE: sbuf_printf(msg, "{ \"type\": \"NOTICE\", " "\"data\": {\"msg\": \"%s\"}}", sbuf_json_escape(buf, ev->e_pkg_notice.msg)); break; case PKG_EVENT_DEVELOPER_MODE: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {\"msg\": \"DEVELOPER_MODE: %s\"}}", sbuf_json_escape(buf, ev->e_pkg_error.msg)); break; case PKG_EVENT_UPDATE_ADD: sbuf_printf(msg, "{ \"type\": \"INFO_UPDATE_ADD\", " "\"data\": { " "\"fetched\": %d, " "\"total\": %d" "}}", ev->e_upd_add.done, ev->e_upd_add.total ); break; case PKG_EVENT_UPDATE_REMOVE: sbuf_printf(msg, "{ \"type\": \"INFO_UPDATE_REMOVE\", " "\"data\": { " "\"fetched\": %d, " "\"total\": %d" "}}", ev->e_upd_remove.done, ev->e_upd_remove.total ); break; case PKG_EVENT_FETCH_BEGIN: sbuf_printf(msg, "{ \"type\": \"INFO_FETCH_BEGIN\", " "\"data\": { " "\"url\": \"%s\" " "}}", sbuf_json_escape(buf, ev->e_fetching.url) ); break; case PKG_EVENT_FETCH_FINISHED: sbuf_printf(msg, "{ \"type\": \"INFO_FETCH_FINISHED\", " "\"data\": { " "\"url\": \"%s\" " "}}", sbuf_json_escape(buf, ev->e_fetching.url) ); break; case PKG_EVENT_INSTALL_BEGIN: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_INSTALL_BEGIN\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_install_begin.pkg, ev->e_install_begin.pkg); break; case PKG_EVENT_EXTRACT_BEGIN: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_EXTRACT_BEGIN\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_extract_begin.pkg, ev->e_extract_begin.pkg); break; case PKG_EVENT_EXTRACT_FINISHED: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_EXTRACT_FINISHED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_extract_finished.pkg, ev->e_extract_finished.pkg); break; case PKG_EVENT_INSTALL_FINISHED: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_INSTALL_FINISHED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\", " "\"message\": \"%S\"" "}}", ev->e_install_finished.pkg, ev->e_install_finished.pkg, ev->e_install_finished.pkg->message ? sbuf_json_escape(buf, ev->e_install_finished.pkg->message->str) : ""); break; case PKG_EVENT_INTEGRITYCHECK_BEGIN: sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_BEGIN\", " "\"data\": {}}"); break; case PKG_EVENT_INTEGRITYCHECK_CONFLICT: sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_CONFLICT\"," "\"data\": { " "\"pkguid\": \"%s\", " "\"pkgpath\": \"%s\", " "\"conflicts\": [", ev->e_integrity_conflict.pkg_uid, ev->e_integrity_conflict.pkg_path); cur_conflict = ev->e_integrity_conflict.conflicts; while (cur_conflict != NULL) { if (cur_conflict->next != NULL) { sbuf_printf(msg, "{\"uid\":\"%s\"},", cur_conflict->uid); } else { sbuf_printf(msg, "{\"uid\":\"%s\"}", cur_conflict->uid); break; } cur_conflict = cur_conflict->next; } sbuf_cat(msg, "]}}"); break; case PKG_EVENT_INTEGRITYCHECK_FINISHED: sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_FINISHED\", " "\"data\": {\"conflicting\": %d}}", ev->e_integrity_finished.conflicting); break; case PKG_EVENT_DEINSTALL_BEGIN: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_DEINSTALL_BEGIN\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_deinstall_begin.pkg, ev->e_deinstall_begin.pkg); break; case PKG_EVENT_DEINSTALL_FINISHED: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_DEINSTALL_FINISHED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_deinstall_finished.pkg, ev->e_deinstall_finished.pkg); break; case PKG_EVENT_UPGRADE_BEGIN: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_UPGRADE_BEGIN\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\" ," "\"pkgnewversion\": \"%v\"" "}}", ev->e_upgrade_begin.o, ev->e_upgrade_begin.o, ev->e_upgrade_begin.n); break; case PKG_EVENT_UPGRADE_FINISHED: pkg_sbuf_printf(msg, "{ \"type\": \"INFO_UPGRADE_FINISHED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\" ," "\"pkgnewversion\": \"%v\"" "}}", ev->e_upgrade_finished.o, ev->e_upgrade_finished.o, ev->e_upgrade_finished.n); break; case PKG_EVENT_LOCKED: pkg_sbuf_printf(msg, "{ \"type\": \"ERROR_LOCKED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%n\"" "}}", ev->e_locked.pkg, ev->e_locked.pkg); break; case PKG_EVENT_REQUIRED: pkg_sbuf_printf(msg, "{ \"type\": \"ERROR_REQUIRED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\", " "\"force\": %S, " "\"required_by\": [", ev->e_required.pkg, ev->e_required.pkg, ev->e_required.force == 1 ? "true": "false"); while (pkg_rdeps(ev->e_required.pkg, &dep) == EPKG_OK) sbuf_printf(msg, "{ \"pkgname\": \"%s\", " "\"pkgversion\": \"%s\" }, ", dep->name, dep->version); sbuf_setpos(msg, sbuf_len(msg) - 2); sbuf_cat(msg, "]}}"); break; case PKG_EVENT_ALREADY_INSTALLED: pkg_sbuf_printf(msg, "{ \"type\": \"ERROR_ALREADY_INSTALLED\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\"" "}}", ev->e_already_installed.pkg, ev->e_already_installed.pkg); break; case PKG_EVENT_MISSING_DEP: sbuf_printf(msg, "{ \"type\": \"ERROR_MISSING_DEP\", " "\"data\": { " "\"depname\": \"%s\", " "\"depversion\": \"%s\"" "}}" , ev->e_missing_dep.dep->name, ev->e_missing_dep.dep->version); break; case PKG_EVENT_NOREMOTEDB: sbuf_printf(msg, "{ \"type\": \"ERROR_NOREMOTEDB\", " "\"data\": { " "\"url\": \"%s\" " "}}" , ev->e_remotedb.repo); break; case PKG_EVENT_NOLOCALDB: sbuf_printf(msg, "{ \"type\": \"ERROR_NOLOCALDB\", " "\"data\": {} "); break; case PKG_EVENT_NEWPKGVERSION: sbuf_printf(msg, "{ \"type\": \"INFO_NEWPKGVERSION\", " "\"data\": {} "); break; case PKG_EVENT_FILE_MISMATCH: pkg_sbuf_printf(msg, "{ \"type\": \"ERROR_FILE_MISMATCH\", " "\"data\": { " "\"pkgname\": \"%n\", " "\"pkgversion\": \"%v\", " "\"path\": \"%S\"" "}}", ev->e_file_mismatch.pkg, ev->e_file_mismatch.pkg, sbuf_json_escape(buf, ev->e_file_mismatch.file->path)); break; case PKG_EVENT_PLUGIN_ERRNO: sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s(%s): %s\"," "\"errno\": %d" "}}", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_errno.func), sbuf_json_escape(buf, ev->e_plugin_errno.arg), sbuf_json_escape(buf, strerror(ev->e_plugin_errno.no)), ev->e_plugin_errno.no); break; case PKG_EVENT_PLUGIN_ERROR: sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s\"" "}}", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_error.msg)); break; case PKG_EVENT_PLUGIN_INFO: sbuf_printf(msg, "{ \"type\": \"INFO_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s\"" "}}", pkg_plugin_get(ev->e_plugin_info.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_info.msg)); break; case PKG_EVENT_INCREMENTAL_UPDATE: sbuf_printf(msg, "{ \"type\": \"INFO_INCREMENTAL_UPDATE\", " "\"data\": {" "\"name\": \"%s\", " "\"processed\": %d" "}}", ev->e_incremental_update.reponame, ev->e_incremental_update.processed); break; case PKG_EVENT_QUERY_YESNO: sbuf_printf(msg, "{ \"type\": \"QUERY_YESNO\", " "\"data\": {" "\"msg\": \"%s\"," "\"default\": \"%d\"" "}}", ev->e_query_yesno.msg, ev->e_query_yesno.deft); break; case PKG_EVENT_QUERY_SELECT: sbuf_printf(msg, "{ \"type\": \"QUERY_SELECT\", " "\"data\": {" "\"msg\": \"%s\"," "\"ncnt\": \"%d\"," "\"default\": \"%d\"," "\"items\": [" , ev->e_query_select.msg, ev->e_query_select.ncnt, ev->e_query_select.deft); for (i = 0; i < ev->e_query_select.ncnt - 1; i++) { sbuf_printf(msg, "{ \"text\": \"%s\" },", ev->e_query_select.items[i]); } sbuf_printf(msg, "{ \"text\": \"%s\" } ] }}", ev->e_query_select.items[i]); break; case PKG_EVENT_PROGRESS_START: sbuf_printf(msg, "{ \"type\": \"INFO_PROGRESS_START\", " "\"data\": {}}"); break; case PKG_EVENT_PROGRESS_TICK: sbuf_printf(msg, "{ \"type\": \"INFO_PROGRESS_TICK\", " "\"data\": { \"current\": %ld, \"total\" : %ld}}", ev->e_progress_tick.current, ev->e_progress_tick.total); break; case PKG_EVENT_BACKUP: case PKG_EVENT_RESTORE: break; default: break; } sbuf_finish(msg); dprintf(eventpipe, "%s\n", sbuf_data(msg)); sbuf_delete(msg); sbuf_delete(buf); }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_category *cat = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_license *lic = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_shlib *shlib = NULL; struct pkg_note *note = NULL; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': while (pkg_categories(pkg, &cat) == EPKG_OK) { format_str(pkg, output, qstr, cat); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': while (pkg_licenses(pkg, &lic) == EPKG_OK) { format_str(pkg, output, qstr, lic); printf("%s\n", sbuf_data(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_data(output)); } break; case 'G': while (pkg_groups(pkg, &group) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_data(output)); } break; case 'B': while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'b': while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'A': while (pkg_annotations(pkg, ¬e) == EPKG_OK) { format_str(pkg, output, qstr, note); printf("%s\n", sbuf_data(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }
int event_callback(void *data, struct pkg_event *ev) { struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; const char *message; int *debug = data; (void) debug; const char *name, *version, *newversion; const char *filename; struct pkg_event_conflict *cur_conflict; switch(ev->type) { case PKG_EVENT_ERRNO: warnx("%s(%s): %s", ev->e_errno.func, ev->e_errno.arg, strerror(ev->e_errno.no)); break; case PKG_EVENT_ERROR: warnx("%s", ev->e_pkg_error.msg); break; case PKG_EVENT_NOTICE: if (!quiet) warnx("%s", ev->e_pkg_notice.msg); break; case PKG_EVENT_DEVELOPER_MODE: warnx("DEVELOPER_MODE: %s", ev->e_pkg_error.msg); break; case PKG_EVENT_FETCHING: if (quiet || !isatty(fileno(stdin))) break; if (fetched == 0) { filename = strrchr(ev->e_fetching.url, '/'); if (filename != NULL) { filename++; } else { /* * We failed at being smart, so display * the entire url. */ filename = ev->e_fetching.url; } strlcpy(url, filename, sizeof(url)); start_progress_meter(url, ev->e_fetching.total, &fetched); } fetched = ev->e_fetching.done; if (ev->e_fetching.done == ev->e_fetching.total) { stop_progress_meter(); fetched = 0; } break; case PKG_EVENT_INSTALL_BEGIN: if (quiet) break; pkg_get(ev->e_install_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); nbdone++; if (nbactions > 0) printf("[%d/%d] ", nbdone, nbactions); printf("Installing %s-%s...", name, version); /* print to the terminal title*/ printf("%c]0;[%d/%d] Installing %s-%s%c", '\033', nbdone, nbactions, name, version, '\007'); break; case PKG_EVENT_INSTALL_FINISHED: if (quiet) break; printf(" done\n"); pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message); if (message != NULL && message[0] != '\0') { if (messages == NULL) messages = sbuf_new_auto(); sbuf_printf(messages, "%s\n", message); } break; case PKG_EVENT_INTEGRITYCHECK_BEGIN: if (quiet) break; printf("Checking integrity..."); break; case PKG_EVENT_INTEGRITYCHECK_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_INTEGRITYCHECK_CONFLICT: printf("\nConflict found on path %s between %s-%s(%s) and ", ev->e_integrity_conflict.pkg_path, ev->e_integrity_conflict.pkg_name, ev->e_integrity_conflict.pkg_version, ev->e_integrity_conflict.pkg_origin); cur_conflict = ev->e_integrity_conflict.conflicts; while (cur_conflict) { if (cur_conflict->next) printf("%s-%s(%s), ", cur_conflict->name, cur_conflict->version, cur_conflict->origin); else printf("%s-%s(%s)", cur_conflict->name, cur_conflict->version, cur_conflict->origin); cur_conflict = cur_conflict->next; } printf("\n"); break; case PKG_EVENT_DEINSTALL_BEGIN: if (quiet) break; pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); nbdone++; if (nbactions > 0) printf("[%d/%d] ", nbdone, nbactions); printf("Deleting %s-%s...", name, version); printf("%c]0;[%d/%d] Deleting %s-%s%c", '\033', nbdone, nbactions, name, version, '\007'); break; case PKG_EVENT_DEINSTALL_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_UPGRADE_BEGIN: if (quiet) break; pkg_get(ev->e_upgrade_begin.pkg, PKG_NAME, &name, PKG_VERSION, &newversion, PKG_OLD_VERSION, &version); nbdone++; if (nbactions > 0) printf("[%d/%d] ", nbdone, nbactions); switch (pkg_version_cmp(version, newversion)) { case 1: printf("Downgrading %s from %s to %s...", name, version, newversion); printf("%c]0;[%d/%d] Downgrading %s from %s to %s%c", '\033', nbdone, nbactions, name, version, newversion, '\007'); break; case 0: printf("Reinstalling %s-%s", name, version); printf("%c]0;[%d/%d] Reinstalling %s-%s%c", '\033', nbdone, nbactions, name, version, '\007'); break; case -1: printf("Upgrading %s from %s to %s...", name, version, newversion); printf("%c]0;[%d/%d] Upgrading %s from %s to %s%c", '\033', nbdone, nbactions, name, version, newversion, '\007'); break; } break; case PKG_EVENT_UPGRADE_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_LOCKED: pkg = ev->e_locked.pkg; pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); fprintf(stderr, "\n%s-%s is locked and may not be modified\n", name, version); break; case PKG_EVENT_REQUIRED: pkg = ev->e_required.pkg; pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); fprintf(stderr, "\n%s-%s is required by:", name, version); while (pkg_rdeps(pkg, &dep) == EPKG_OK) fprintf(stderr, " %s-%s", pkg_dep_name(dep), pkg_dep_version(dep)); if (ev->e_required.force == 1) fprintf(stderr, ", deleting anyway\n"); else fprintf(stderr, "\n"); break; case PKG_EVENT_ALREADY_INSTALLED: if (quiet) break; pkg_get(ev->e_already_installed.pkg, PKG_NAME, &name, PKG_VERSION, &version); printf("%s-%s already installed\n", name, version); break; case PKG_EVENT_NOT_FOUND: printf("Package '%s' was not found in " "the repositories\n", ev->e_not_found.pkg_name); break; case PKG_EVENT_MISSING_DEP: fprintf(stderr, "missing dependency %s-%s\n", pkg_dep_name(ev->e_missing_dep.dep), pkg_dep_version(ev->e_missing_dep.dep)); break; case PKG_EVENT_NOREMOTEDB: fprintf(stderr, "Unable to open remote database \"%s\". " "Try running '%s update' first.\n", ev->e_remotedb.repo, getprogname()); break; case PKG_EVENT_NOLOCALDB: fprintf(stderr, "Local package database nonexistent!\n"); break; case PKG_EVENT_NEWPKGVERSION: printf("New version of pkg detected; it needs to be " "installed first.\nAfter this upgrade it is recommended " "that you do a full upgrade using: 'pkg upgrade'\n\n"); break; case PKG_EVENT_FILE_MISMATCH: pkg_get(ev->e_file_mismatch.pkg, PKG_NAME, &name, PKG_VERSION, &version); fprintf(stderr, "%s-%s: checksum mismatch for %s\n", name, version, pkg_file_path(ev->e_file_mismatch.file)); break; case PKG_EVENT_PLUGIN_ERRNO: warnx("%s: %s(%s): %s", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME), ev->e_plugin_errno.func, ev->e_plugin_errno.arg, strerror(ev->e_plugin_errno.no)); break; case PKG_EVENT_PLUGIN_ERROR: warnx("%s: %s", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), ev->e_plugin_error.msg); break; case PKG_EVENT_PLUGIN_INFO: if (quiet) break; printf("%s: %s\n", pkg_plugin_get(ev->e_plugin_info.plugin, PKG_PLUGIN_NAME), ev->e_plugin_info.msg); break; case PKG_EVENT_INCREMENTAL_UPDATE: if (!quiet) printf("Incremental update completed, %d packages processed:\n" "%d packages updated, %d removed and %d added.\n", ev->e_incremental_update.processed, ev->e_incremental_update.updated, ev->e_incremental_update.removed, ev->e_incremental_update.added); break; default: break; } return 0; }
int pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade) { struct pkg_dep *rdep = NULL; int ret; assert(pkg != NULL); assert(db != NULL); /* * Do not trust the existing entries as it may have changed if we * delete packages in batch. */ pkg_list_free(pkg, PKG_RDEPS); /* * Ensure that we have all the informations we need */ if ((ret = pkgdb_loadrdeps(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadfiles(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loaddirs(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadscripts(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_loadmtree(db, pkg)) != EPKG_OK) return (ret); if (!upgrade) pkg_emit_deinstall_begin(pkg); else pkg_emit_upgrade_begin(pkg); /* If there are dependencies */ if (pkg_rdeps(pkg, &rdep) == EPKG_OK) { pkg_emit_required(pkg, force); if (!force) return (EPKG_REQUIRED); } if (upgrade) { if (( ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE)) != EPKG_OK ) return (ret); } else { if ((ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL)) != EPKG_OK) return (ret); } if ((ret = pkg_delete_files(pkg, force)) != EPKG_OK) return (ret); if (!upgrade) if ((ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL)) != EPKG_OK) return (ret); if ((ret = pkg_delete_dirs(db, pkg, force)) != EPKG_OK) return (ret); if (!upgrade) pkg_emit_deinstall_finished(pkg); return (pkgdb_unregister_pkg(db, pkg_get(pkg, PKG_ORIGIN))); }
static void pipeevent(struct pkg_event *ev) { struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; struct sbuf *msg, *buf; const char *message; const char *name, *version, *newversion; if (eventpipe < 0) return; msg = sbuf_new_auto(); buf = sbuf_new_auto(); switch(ev->type) { case PKG_EVENT_ERRNO: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {" "\"msg\": \"%s(%s): %s\"," "\"errno\": %d}}", sbuf_json_escape(buf, ev->e_errno.func), sbuf_json_escape(buf, ev->e_errno.arg), sbuf_json_escape(buf, strerror(ev->e_errno.no)), ev->e_errno.no); break; case PKG_EVENT_ERROR: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {\"msg\": \"%s\"}}", sbuf_json_escape(buf, ev->e_pkg_error.msg)); break; case PKG_EVENT_DEVELOPER_MODE: sbuf_printf(msg, "{ \"type\": \"ERROR\", " "\"data\": {\"msg\": \"DEVELOPER_MODE: %s\"}}", sbuf_json_escape(buf, ev->e_pkg_error.msg)); break; case PKG_EVENT_FETCHING: sbuf_printf(msg, "{ \"type\": \"INFO_FETCH\", " "\"data\": { " "\"url\": \"%s\", " "\"fetched\": %" PRId64 ", " "\"total\": %" PRId64 "}}", sbuf_json_escape(buf, ev->e_fetching.url), ev->e_fetching.done, ev->e_fetching.total ); break; case PKG_EVENT_INSTALL_BEGIN: pkg_get(ev->e_install_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"INFO_INSTALL_BEGIN\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\"" "}}", name, version ); break; case PKG_EVENT_INSTALL_FINISHED: pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"INFO_INSTALL_FINISHED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\", " "\"message\": \"%s\"" "}}", name, version, sbuf_json_escape(buf, message)); break; case PKG_EVENT_INTEGRITYCHECK_BEGIN: sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_BEGIN\", " "\"data\": {}}"); break; case PKG_EVENT_INTEGRITYCHECK_FINISHED: sbuf_printf(msg, "{ \"type\": \"INFO_INTEGRITYCHECK_FINISHED\", " "\"data\": {}}"); break; case PKG_EVENT_DEINSTALL_BEGIN: pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"INFO_DEINSTALL_BEGIN\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\"" "}}", name, version); break; case PKG_EVENT_DEINSTALL_FINISHED: pkg_get(ev->e_deinstall_finished.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"INFO_DEINSTALL_FINISHED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\"" "}}", name, version); break; case PKG_EVENT_UPGRADE_BEGIN: pkg_get(ev->e_upgrade_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_NEWVERSION, &newversion); sbuf_printf(msg, "{ \"type\": \"INFO_UPGRADE_BEGIN\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\" ," "\"pkgnewversion\": \"%s\"" "}}", name, version, newversion); break; case PKG_EVENT_UPGRADE_FINISHED: pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_NEWVERSION, &newversion); sbuf_printf(msg, "{ \"type\": \"INFO_UPGRADE_FINISHED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\" ," "\"pkgnewversion\": \"%s\"" "}}", name, version, newversion); break; case PKG_EVENT_LOCKED: pkg_get(ev->e_locked.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"ERROR_LOCKED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\"" "}}", name, version); break; case PKG_EVENT_REQUIRED: pkg_get(ev->e_required.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"ERROR_REQUIRED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\", " "\"force\": %s, " "\"required_by\": [", name, version, ev->e_required.force == 1 ? "true": "false"); while (pkg_rdeps(pkg, &dep) == EPKG_OK) sbuf_printf(msg, "{ \"pkgname\": \"%s\", " "\"pkgversion\": \"%s\" }, ", pkg_dep_name(dep), pkg_dep_version(dep)); sbuf_setpos(msg, sbuf_len(msg) - 2); sbuf_cat(msg, "]}}"); break; case PKG_EVENT_ALREADY_INSTALLED: pkg_get(ev->e_already_installed.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"ERROR_ALREADY_INSTALLED\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\"" "}}", name, version); break; case PKG_EVENT_MISSING_DEP: sbuf_printf(msg, "{ \"type\": \"ERROR_MISSING_DEP\", " "\"data\": { " "\"depname\": \"%s\", " "\"depversion\": \"%s\"" "}}" , pkg_dep_name(ev->e_missing_dep.dep), pkg_dep_version(ev->e_missing_dep.dep)); break; case PKG_EVENT_NOREMOTEDB: sbuf_printf(msg, "{ \"type\": \"ERROR_NOREMOTEDB\", " "\"data\": { " "\"url\": \"%s\" " "}}" , ev->e_remotedb.repo); break; case PKG_EVENT_NOLOCALDB: sbuf_printf(msg, "{ \"type\": \"ERROR_NOLOCALDB\", " "\"data\": {} "); break; case PKG_EVENT_NEWPKGVERSION: sbuf_printf(msg, "{ \"type\": \"INFO_NEWPKGVERSION\", " "\"data\": {} "); break; case PKG_EVENT_FILE_MISMATCH: pkg_get(ev->e_file_mismatch.pkg, PKG_NAME, &name, PKG_VERSION, &version); sbuf_printf(msg, "{ \"type\": \"ERROR_FILE_MISMATCH\", " "\"data\": { " "\"pkgname\": \"%s\", " "\"pkgversion\": \"%s\", " "\"path\": \"%s\"" "}}", name, version, sbuf_json_escape(buf, pkg_file_path(ev->e_file_mismatch.file))); break; case PKG_EVENT_PLUGIN_ERRNO: sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s(%s): %s\"," "\"errno\": %d" "}}", pkg_plugin_get(ev->e_plugin_errno.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_errno.func), sbuf_json_escape(buf, ev->e_plugin_errno.arg), sbuf_json_escape(buf, strerror(ev->e_plugin_errno.no)), ev->e_plugin_errno.no); break; case PKG_EVENT_PLUGIN_ERROR: sbuf_printf(msg, "{ \"type\": \"ERROR_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s\"" "}}", pkg_plugin_get(ev->e_plugin_error.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_error.msg)); break; case PKG_EVENT_PLUGIN_INFO: sbuf_printf(msg, "{ \"type\": \"INFO_PLUGIN\", " "\"data\": {" "\"plugin\": \"%s\", " "\"msg\": \"%s\"" "}}", pkg_plugin_get(ev->e_plugin_info.plugin, PKG_PLUGIN_NAME), sbuf_json_escape(buf, ev->e_plugin_info.msg)); break; default: break; } sbuf_finish(msg); dprintf(eventpipe, "%s\n", sbuf_data(msg)); sbuf_delete(msg); sbuf_delete(buf); }
int event_callback(void *data, struct pkg_event *ev) { struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; const char *message; int *debug = data; (void) debug; const char *name, *version, *newversion; const char *filename; switch(ev->type) { case PKG_EVENT_ERRNO: warn("%s(%s)", ev->e_errno.func, ev->e_errno.arg); break; case PKG_EVENT_ERROR: warnx("%s", ev->e_pkg_error.msg); break; case PKG_EVENT_FETCHING: if (quiet) break; if (fetched == 0) { filename = strrchr(ev->e_fetching.url, '/'); if (filename != NULL) { filename++; } else { /* * We failed at being smart, so display * the entire url. */ filename = ev->e_fetching.url; } strlcpy(url, filename, sizeof(url)); start_progress_meter(url, ev->e_fetching.total, &fetched); } fetched = ev->e_fetching.done; if (ev->e_fetching.done == ev->e_fetching.total) { stop_progress_meter(); fetched = 0; } break; case PKG_EVENT_INSTALL_BEGIN: if (quiet) break; pkg_get(ev->e_install_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); printf("Installing %s-%s...", name, version); break; case PKG_EVENT_INSTALL_FINISHED: if (quiet) break; printf(" done\n"); pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message); if (message != NULL && message[0] != '\0') { if (messages == NULL) messages = sbuf_new_auto(); sbuf_printf(messages, "%s\n", message); } break; case PKG_EVENT_INTEGRITYCHECK_BEGIN: if (quiet) break; printf("Checking integrity..."); break; case PKG_EVENT_INTEGRITYCHECK_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_DEINSTALL_BEGIN: if (quiet) break; pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version); printf("Deinstalling %s-%s...", name, version); break; case PKG_EVENT_DEINSTALL_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_UPGRADE_BEGIN: if (quiet) break; pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_NEWVERSION, &newversion); switch (pkg_version_cmp(version, newversion)) { case 1: printf("Downgrading %s from %s to %s...", name, version, newversion); break; case 0: printf("Reinstalling %s-%s", name, version); break; case -1: printf("Upgrading %s from %s to %s...", name, version, newversion); break; } break; case PKG_EVENT_UPGRADE_FINISHED: if (quiet) break; printf(" done\n"); break; case PKG_EVENT_REQUIRED: pkg = ev->e_required.pkg; pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version); fprintf(stderr, "%s-%s is required by:", name, version); while (pkg_rdeps(pkg, &dep) == EPKG_OK) fprintf(stderr, " %s-%s", pkg_dep_name(dep), pkg_dep_version(dep)); if (ev->e_required.force == 1) fprintf(stderr, ", deleting anyway\n"); else fprintf(stderr, "\n"); break; case PKG_EVENT_ALREADY_INSTALLED: if (quiet) break; pkg_get(ev->e_already_installed.pkg, PKG_NAME, &name, PKG_VERSION, &version); printf("%s-%s already installed\n", name, version); break; case PKG_EVENT_MISSING_DEP: fprintf(stderr, "missing dependency %s-%s", pkg_dep_name(ev->e_missing_dep.dep), pkg_dep_version(ev->e_missing_dep.dep)); break; case PKG_EVENT_NOREMOTEDB: fprintf(stderr, "Unable to open remote database \"%s\". " "Try running '%s update' first.\n", ev->e_remotedb.repo, getprogname()); break; case PKG_EVENT_NOLOCALDB: /* only cares if run as root */ if (geteuid() == 0) fprintf(stderr, "Unable to create local database!\n"); break; case PKG_EVENT_NEWPKGVERSION: printf("New version of pkg detected; it needs to be " "installed first.\nAfter this upgrade it is recommended" "that you do a full upgrade using: 'pkg upgrade'\n\n"); break; case PKG_EVENT_FILE_MISMATCH: pkg_get(ev->e_file_mismatch.pkg, PKG_NAME, &name, PKG_VERSION, &version); fprintf(stderr, "%s-%s: checksum mismatch for %s\n", name, version, pkg_file_path(ev->e_file_mismatch.file)); default: break; } return 0; }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_kv *kv; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': pkg_printf("%C%{%Cn\n%|%}", pkg); break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': pkg_printf("%D", pkg); break; case 'L': pkg_printf("%L%{%Ln\n%|%}", pkg); break; case 'U': pkg_printf("%U", pkg); break; case 'G': pkg_printf("%G", pkg); break; case 'B': pkg_printf("%B", pkg); break; case 'b': pkg_printf("%b", pkg); break; case 'A': pkg_get(pkg, PKG_ANNOTATIONS, &kv); while (kv != NULL) { format_str(pkg, output, qstr, kv); printf("%s\n", sbuf_data(output)); kv = kv->next; } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }
void print_info(struct pkg * const pkg, unsigned int options) { struct pkg_category *cat = NULL; struct pkg_dep *dep = NULL; struct pkg_dir *dir = NULL; struct pkg_file *file = NULL; struct pkg_group *group = NULL; struct pkg_license *lic = NULL; struct pkg_option *option = NULL; struct pkg_shlib *shlib = NULL; struct pkg_user *user = NULL; bool multirepos_enabled = false; bool print_tag = false; bool show_locks = false; char size[7]; const char *name, *version, *prefix, *origin, *reponame, *repourl; const char *maintainer, *www, *comment, *desc, *message, *arch; const char *repopath; const char *tab; char *m; unsigned opt; int64_t flatsize, newflatsize, newpkgsize; lic_t licenselogic; bool locked; int cout = 0; /* Number of characters output */ int info_num; /* Number of different data items to print */ pkg_config_bool(PKG_CONFIG_MULTIREPOS, &multirepos_enabled); pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version, PKG_PREFIX, &prefix, PKG_ORIGIN, &origin, PKG_REPONAME, &reponame, PKG_REPOURL, &repourl, PKG_MAINTAINER, &maintainer, PKG_WWW, &www, PKG_COMMENT, &comment, PKG_DESC, &desc, PKG_FLATSIZE, &flatsize, PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &newpkgsize, PKG_LICENSE_LOGIC, &licenselogic, PKG_MESSAGE, &message, PKG_ARCH, &arch, PKG_REPOPATH, &repopath, PKG_LOCKED, &locked); if (!multirepos_enabled) pkg_config_string(PKG_CONFIG_REPO, &repourl); if (options & INFO_RAW) { /* Not for remote packages */ if (pkg_type(pkg) != PKG_REMOTE) { pkg_emit_manifest(pkg, &m); printf("%s\n", m); free(m); } return; } /* Show locking status when requested to display it and the package is locally installed */ if (pkg_type(pkg) == PKG_INSTALLED && (options & INFO_LOCKED) != 0) show_locks = true; if (!quiet) { /* Print a tag-line identifying the package -- either NAMEVER, ORIGIN or NAME (in that order of preference). This may be the only output from this function */ if (options & INFO_TAG_NAMEVER) cout = printf("%s-%s", name, version); else if (options & INFO_TAG_ORIGIN) cout = printf("%s", origin); else if (options & INFO_TAG_NAME) cout = printf("%s", name); } /* Don't display a tab if quiet, retains compatibility. */ tab = quiet ? "" : "\t"; /* If we printed a tag, and there are no other items to print, then just return now. If there's only one single-line item to print, show it at column 32 on the same line. If there's one multi-line item to print, start a new line. If there is more than one item to print per pkg, use 'key : value' style to show on a new line. */ info_num = 0; for (opt = 0x1U; opt <= INFO_LASTFIELD; opt <<= 1) if ((opt & options) != 0) info_num++; if (info_num == 0 && cout > 0) { printf("\n"); return; } if (info_num == 1) { /* Only one item to print */ print_tag = false; if (!quiet) { if (options & INFO_MULTILINE) printf(":\n"); else { if (cout < 31) cout = 31 - cout; else cout = 1; printf("%*s", cout, " "); } } } else { /* Several items to print */ print_tag = true; if (!quiet) printf("\n"); } for (opt = 0x1; opt <= INFO_LASTFIELD; opt <<= 1) { if ((opt & options) == 0) continue; switch (opt) { case INFO_NAME: if (print_tag) printf("%-15s: ", "Name"); printf("%s\n", name); break; case INFO_VERSION: if (print_tag) printf("%-15s: ", "Version"); printf("%s\n", version); break; case INFO_ORIGIN: if (print_tag) printf("%-15s: ", "Origin"); printf("%s\n", origin); break; case INFO_PREFIX: if (print_tag) printf("%-15s: ", "Prefix"); printf("%s\n", prefix); break; case INFO_REPOSITORY: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Repository"); printf("%s [%s]\n", reponame, repourl); } else if (!print_tag) printf("\n"); break; case INFO_CATEGORIES: if (pkg_list_count(pkg, PKG_CATEGORIES) > 0) { if (print_tag) printf("%-15s: ", "Categories"); if (pkg_categories(pkg, &cat) == EPKG_OK) printf("%s", pkg_category_name(cat)); while (pkg_categories(pkg, &cat) == EPKG_OK) printf(" %s", pkg_category_name(cat)); printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_LICENSES: if (pkg_list_count(pkg, PKG_LICENSES) > 0) { if (print_tag) printf("%-15s: ", "Licenses"); if (pkg_licenses(pkg, &lic) == EPKG_OK) printf("%s", pkg_license_name(lic)); while (pkg_licenses(pkg, &lic) == EPKG_OK) { if (licenselogic != 1) printf(" %c", licenselogic); printf(" %s", pkg_license_name(lic)); } printf("\n"); } else if (!print_tag) printf("\n"); break; case INFO_MAINTAINER: if (print_tag) printf("%-15s: ", "Maintainer"); printf("%s\n", maintainer); break; case INFO_WWW: if (print_tag) printf("%-15s: ", "WWW"); printf("%s\n", www); break; case INFO_COMMENT: if (print_tag) printf("%-15s: ", "Comment"); printf("%s\n", comment); break; case INFO_OPTIONS: if (pkg_list_count(pkg, PKG_OPTIONS) > 0) { if (print_tag) printf("%-15s:\n", "Options"); while (pkg_options(pkg, &option) == EPKG_OK) printf("%s%-15s: %s\n", tab, pkg_option_opt(option), pkg_option_value(option)); } break; case INFO_SHLIBS_REQUIRED: if (pkg_list_count(pkg, PKG_SHLIBS_REQUIRED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs required"); while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_SHLIBS_PROVIDED: if (pkg_list_count(pkg, PKG_SHLIBS_PROVIDED) > 0) { if (print_tag) printf("%-15s:\n", "Shared Libs provided"); while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) printf("%s%s\n", tab, pkg_shlib_name(shlib)); } break; case INFO_FLATSIZE: if (pkg_type(pkg) == PKG_INSTALLED || pkg_type(pkg) == PKG_FILE) humanize_number(size, sizeof(size), flatsize,"B", HN_AUTOSCALE, 0); else humanize_number(size, sizeof(size), newflatsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Flat size"); printf("%s\n", size); break; case INFO_PKGSIZE: /* Remote pkgs only */ if (pkg_type(pkg) == PKG_REMOTE) { humanize_number(size, sizeof(size), newpkgsize,"B", HN_AUTOSCALE, 0); if (print_tag) printf("%-15s: ", "Pkg size"); printf("%s\n", size); } else if (!print_tag) printf("\n"); break; case INFO_DESCR: if (print_tag) printf("%-15s:\n", "Description"); printf("%s\n", desc); break; case INFO_MESSAGE: if (message) { if (print_tag) printf("%-15s:\n", "Message"); printf("%s\n", message); } break; case INFO_DEPS: if (pkg_list_count(pkg, PKG_DEPS) > 0) { if (print_tag) printf("%-15s:\n", "Depends on"); while (pkg_deps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_RDEPS: if (pkg_list_count(pkg, PKG_RDEPS) > 0) { if (print_tag) printf("%-15s:\n", "Required by"); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { printf("%s%s-%s", tab, pkg_dep_name(dep), pkg_dep_version(dep)); if (show_locks && pkg_dep_is_locked(dep)) printf(" (*)"); printf("\n"); } } break; case INFO_FILES: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_FILES) > 0) { if (print_tag) printf("%-15s:\n", "Files"); while (pkg_files(pkg, &file) == EPKG_OK) printf("%s%s\n", tab, pkg_file_path(file)); } break; case INFO_DIRS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_DIRS) > 0) { if (print_tag) printf("%-15s:\n", "Directories"); while (pkg_dirs(pkg, &dir) == EPKG_OK) printf("%s%s\n", tab, pkg_dir_path(dir)); } break; case INFO_USERS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_USERS) > 0) { if (print_tag) printf("%-15s: ", "Users"); if (pkg_users(pkg, &user) == EPKG_OK) printf("%s", pkg_user_name(user)); while (pkg_users(pkg, &user) == EPKG_OK) printf(" %s", pkg_user_name(user)); printf("\n"); } break; case INFO_GROUPS: /* Installed pkgs only */ if (pkg_type(pkg) != PKG_REMOTE && pkg_list_count(pkg, PKG_GROUPS) > 0) { if (print_tag) printf("%-15s: ", "Groups"); if (pkg_groups(pkg, &group) == EPKG_OK) printf("%s", pkg_group_name(group)); while (pkg_groups(pkg, &group) == EPKG_OK) printf(" %s", pkg_group_name(group)); printf("\n"); } break; case INFO_ARCH: if (print_tag) printf("%-15s: ", "Architecture"); printf("%s\n", arch); break; case INFO_REPOURL: if (pkg_type(pkg) == PKG_REMOTE && repourl != NULL && repourl[0] != '\0') { if (print_tag) printf("%-15s: ", "Pkg URL"); if (repourl[strlen(repourl) -1] == '/') printf("%s%s\n", repourl, repopath); else printf("%s/%s\n", repourl, repopath); } else if (!print_tag) printf("\n"); break; case INFO_LOCKED: if (print_tag) printf("%-15s: ", "Locked"); printf("%s\n", locked ? "yes" : "no"); break; } } }
int pkg_delete(struct pkg *pkg, struct pkgdb *db, unsigned flags) { struct pkg_dep *rdep = NULL; int ret; bool handle_rc = false; const char *origin; assert(pkg != NULL); assert(db != NULL); /* * Do not trust the existing entries as it may have changed if we * delete packages in batch. */ pkg_list_free(pkg, PKG_RDEPS); /* * Ensure that we have all the informations we need */ if ((ret = pkgdb_load_rdeps(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_files(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_dirs(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_scripts(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_mtree(db, pkg)) != EPKG_OK) return (ret); if ((ret = pkgdb_load_annotations(db, pkg)) != EPKG_OK) return (ret); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_begin(pkg); /* If the package is locked */ if (pkg_is_locked(pkg)) { pkg_emit_locked(pkg); return (EPKG_LOCKED); } /* If there are dependencies */ if ((flags & (PKG_DELETE_UPGRADE|PKG_DELETE_CONFLICT)) == 0) { if (pkg_rdeps(pkg, &rdep) == EPKG_OK) { pkg_emit_required(pkg, flags & PKG_DELETE_FORCE); if ((flags & PKG_DELETE_FORCE) == 0) return (EPKG_REQUIRED); } } /* * stop the different related services if the users do want that * and that the service is running */ handle_rc = pkg_object_bool(pkg_config_get("HANDLE_RC_SCRIPTS")); if (handle_rc) pkg_start_stop_rc_scripts(pkg, PKG_RC_STOP); if ((flags & PKG_DELETE_NOSCRIPT) == 0) { if (flags & PKG_DELETE_UPGRADE) { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE); if (ret != EPKG_OK) return (ret); } else { ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_DEINSTALL); if (ret != EPKG_OK) return (ret); } } if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE ? 1 : 0)) != EPKG_OK) return (ret); if ((flags & (PKG_DELETE_NOSCRIPT | PKG_DELETE_UPGRADE)) == 0) { ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL); if (ret != EPKG_OK) return (ret); } ret = pkg_delete_dirs(db, pkg, flags & PKG_DELETE_FORCE); if (ret != EPKG_OK) return (ret); if ((flags & PKG_DELETE_UPGRADE) == 0) pkg_emit_deinstall_finished(pkg); pkg_get(pkg, PKG_ORIGIN, &origin); return (pkgdb_unregister_pkg(db, origin)); }
int event_callback(void *data, struct pkg_event *ev) { struct pkg *pkg = NULL; struct pkg_dep *dep = NULL; const char *message; int *debug = data; (void)debug; switch(ev->type) { case PKG_EVENT_ERRNO: warn("%s(%s)", ev->e_errno.func, ev->e_errno.arg); break; case PKG_EVENT_ERROR: warnx("%s", ev->e_pkg_error.msg); break; case PKG_EVENT_FETCHING: if (fetched == 0) { strlcpy(url, ev->e_fetching.url, sizeof(url)); start_progress_meter(url, ev->e_fetching.total, &fetched); } fetched = ev->e_fetching.done; if (ev->e_fetching.done == ev->e_fetching.total) { stop_progress_meter(); fetched = 0; } break; case PKG_EVENT_INSTALL_BEGIN: printf("Installing %s-%s...", pkg_get(ev->e_install_begin.pkg, PKG_NAME), pkg_get(ev->e_install_begin.pkg, PKG_VERSION)); fflush(stdout); break; case PKG_EVENT_INSTALL_FINISHED: printf(" done\n"); message = pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE); if (message != NULL && message[0] != '\0') printf("%s\n", message); break; case PKG_EVENT_DEINSTALL_BEGIN: printf("Deinstalling %s-%s...", pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME), pkg_get(ev->e_deinstall_begin.pkg, PKG_VERSION)); fflush(stdout); break; case PKG_EVENT_DEINSTALL_FINISHED: printf(" done\n"); break; case PKG_EVENT_UPGRADE_BEGIN: printf("Upgrading %s from %s to %s...", pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME), pkg_get(ev->e_upgrade_finished.pkg, PKG_VERSION), pkg_get(ev->e_upgrade_finished.pkg, PKG_NEWVERSION)); fflush(stdout); break; case PKG_EVENT_UPGRADE_FINISHED: printf("done\n"); break; case PKG_EVENT_REQUIRED: pkg = ev->e_required.pkg; fprintf(stderr, "%s-%s is required by:", pkg_get(pkg, PKG_NAME), pkg_get(pkg, PKG_VERSION)); while (pkg_rdeps(pkg, &dep) == EPKG_OK) { fprintf(stderr, " %s-%s", pkg_dep_name(dep), pkg_dep_version(dep)); } if (ev->e_required.force == 1) fprintf(stderr, ", deleting anyway\n"); else fprintf(stderr, "\n"); break; case PKG_EVENT_ALREADY_INSTALLED: printf("%s-%s already installed\n", pkg_get(ev->e_already_installed.pkg, PKG_NAME), pkg_get(ev->e_already_installed.pkg, PKG_VERSION)); break; default: break; } return 0; }
void print_query(struct pkg *pkg, char *qstr, char multiline) { struct sbuf *output = sbuf_new_auto(); struct pkg_dep *dep = NULL; struct pkg_option *option = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct pkg_user *user = NULL; struct pkg_group *group = NULL; struct pkg_shlib *shlib = NULL; const pkg_object *o, *list; pkg_iter it; switch (multiline) { case 'd': while (pkg_deps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'r': while (pkg_rdeps(pkg, &dep) == EPKG_OK) { format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); } break; case 'C': it = NULL; pkg_get(pkg, PKG_CATEGORIES, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; case 'O': while (pkg_options(pkg, &option) == EPKG_OK) { format_str(pkg, output, qstr, option); printf("%s\n", sbuf_data(output)); } break; case 'F': while (pkg_files(pkg, &file) == EPKG_OK) { format_str(pkg, output, qstr, file); printf("%s\n", sbuf_data(output)); } break; case 'D': while (pkg_dirs(pkg, &dir) == EPKG_OK) { format_str(pkg, output, qstr, dir); printf("%s\n", sbuf_data(output)); } break; case 'L': it = NULL; pkg_get(pkg, PKG_LICENSES, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; case 'U': while (pkg_users(pkg, &user) == EPKG_OK) { format_str(pkg, output, qstr, user); printf("%s\n", sbuf_data(output)); } break; case 'G': while (pkg_groups(pkg, &group) == EPKG_OK) { format_str(pkg, output, qstr, group); printf("%s\n", sbuf_data(output)); } break; case 'B': while (pkg_shlibs_required(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'b': while (pkg_shlibs_provided(pkg, &shlib) == EPKG_OK) { format_str(pkg, output, qstr, shlib); printf("%s\n", sbuf_data(output)); } break; case 'A': it = NULL; pkg_get(pkg, PKG_ANNOTATIONS, &list); while ((o = pkg_object_iterate(list, &it))) { format_str(pkg, output, qstr, o); printf("%s\n", sbuf_data(output)); } break; default: format_str(pkg, output, qstr, dep); printf("%s\n", sbuf_data(output)); break; } sbuf_delete(output); }