/* TODO this is one of the worst ever functions written. void *data ? wtf */ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2, void *data3, int *response) { switch(event) { case PM_TRANS_CONV_INSTALL_IGNOREPKG: if(!config->op_s_downloadonly) { *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); } else { *response = 1; } break; case PM_TRANS_CONV_REPLACE_PKG: *response = yesno(_(":: Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); break; case PM_TRANS_CONV_CONFLICT_PKG: /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { *response = noyes(_(":: %s and %s are in conflict. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); } else { *response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"), (char *)data1, (char *)data2, (char *)data3, (char *)data2); } break; case PM_TRANS_CONV_REMOVE_PKGS: { alpm_list_t *unresolved = (alpm_list_t *) data1; alpm_list_t *namelist = NULL, *i; size_t count = 0; for (i = unresolved; i; i = i->next) { namelist = alpm_list_add(namelist, (char *)alpm_pkg_get_name(i->data)); count++; } printf(_n( ":: The following package cannot be upgraded due to unresolvable dependencies:\n", ":: The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); list_display(" ", namelist); printf("\n"); *response = noyes(_n( "Do you want to skip the above package for this upgrade?", "Do you want to skip the above packages for this upgrade?", count)); alpm_list_free(namelist); } break; case PM_TRANS_CONV_SELECT_PROVIDER: { alpm_list_t *providers = (alpm_list_t *)data1; int count = alpm_list_count(providers); char *depstring = alpm_dep_compute_string((pmdepend_t *)data2); printf(_(":: There are %d providers available for %s:\n"), count, depstring); free(depstring); select_display(providers); *response = select_question(count); } break; case PM_TRANS_CONV_LOCAL_NEWER: if(!config->op_s_downloadonly) { *response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); } else { *response = 1; } break; case PM_TRANS_CONV_CORRUPTED_PKG: *response = yesno(_(":: File %s is corrupted. Do you want to delete it?"), (char *)data1); break; } if(config->noask) { if(config->ask & event) { /* inverse the default answer */ *response = !*response; } } }
/* callback to handle questions from libalpm transactions (yes/no) */ void cb_question(alpm_question_t *question) { if(config->print) { if(question->type == ALPM_QUESTION_INSTALL_IGNOREPKG) { question->any.answer = 1; } else { question->any.answer = 0; } return; } switch(question->type) { case ALPM_QUESTION_INSTALL_IGNOREPKG: { alpm_question_install_ignorepkg_t *q = &question->install_ignorepkg; if(!config->op_s_downloadonly) { q->install = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(q->pkg)); } else { q->install = 1; } } break; case ALPM_QUESTION_REPLACE_PKG: { alpm_question_replace_t *q = &question->replace; q->replace = yesno(_("Replace %s with %s/%s?"), alpm_pkg_get_name(q->oldpkg), alpm_db_get_name(q->newdb), alpm_pkg_get_name(q->newpkg)); } break; case ALPM_QUESTION_CONFLICT_PKG: { alpm_question_conflict_t *q = &question->conflict; /* print conflict only if it contains new information */ if(strcmp(q->conflict->package1, q->conflict->reason->name) == 0 || strcmp(q->conflict->package2, q->conflict->reason->name) == 0) { q->remove = noyes(_("%s and %s are in conflict. Remove %s?"), q->conflict->package1, q->conflict->package2, q->conflict->package2); } else { q->remove = noyes(_("%s and %s are in conflict (%s). Remove %s?"), q->conflict->package1, q->conflict->package2, q->conflict->reason->name, q->conflict->package2); } } break; case ALPM_QUESTION_REMOVE_PKGS: { alpm_question_remove_pkgs_t *q = &question->remove_pkgs; alpm_list_t *namelist = NULL, *i; size_t count = 0; for(i = q->packages; i; i = i->next) { namelist = alpm_list_add(namelist, (char *)alpm_pkg_get_name(i->data)); count++; } colon_printf(_n( "The following package cannot be upgraded due to unresolvable dependencies:\n", "The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); list_display(" ", namelist, getcols()); printf("\n"); q->skip = noyes(_n( "Do you want to skip the above package for this upgrade?", "Do you want to skip the above packages for this upgrade?", count)); alpm_list_free(namelist); } break; case ALPM_QUESTION_SELECT_PROVIDER: { alpm_question_select_provider_t *q = &question->select_provider; size_t count = alpm_list_count(q->providers); char *depstring = alpm_dep_compute_string(q->depend); colon_printf(_n("There is %zd provider available for %s\n", "There are %zd providers available for %s:\n", count), count, depstring); free(depstring); select_display(q->providers); q->use_index = select_question(count); } break; case ALPM_QUESTION_CORRUPTED_PKG: { alpm_question_corrupted_t *q = &question->corrupted; q->remove = yesno(_("File %s is corrupted (%s).\n" "Do you want to delete it?"), q->filepath, alpm_strerror(q->reason)); } break; case ALPM_QUESTION_IMPORT_KEY: { alpm_question_import_key_t *q = &question->import_key; char created[12]; time_t time = (time_t)q->key->created; strftime(created, 12, "%Y-%m-%d", localtime(&time)); if(q->key->revoked) { q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created); } else { q->import = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"), q->key->length, q->key->pubkey_algo, q->key->fingerprint, q->key->uid, created); } } break; } if(config->noask) { if(config->ask & question->type) { /* inverse the default answer */ question->any.answer = !question->any.answer; } } }
/* TODO this is one of the worst ever functions written. void *data ? wtf */ void cb_question(alpm_question_t event, void *data1, void *data2, void *data3, int *response) { if(config->print) { if(event == ALPM_QUESTION_INSTALL_IGNOREPKG) { *response = 1; } else { *response = 0; } return; } switch(event) { case ALPM_QUESTION_INSTALL_IGNOREPKG: if(!config->op_s_downloadonly) { *response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"), alpm_pkg_get_name(data1)); } else { *response = 1; } break; case ALPM_QUESTION_REPLACE_PKG: *response = yesno(_("Replace %s with %s/%s?"), alpm_pkg_get_name(data1), (char *)data3, alpm_pkg_get_name(data2)); break; case ALPM_QUESTION_CONFLICT_PKG: /* data parameters: target package, local package, conflict (strings) */ /* print conflict only if it contains new information */ if(strcmp(data1, data3) == 0 || strcmp(data2, data3) == 0) { *response = noyes(_("%s and %s are in conflict. Remove %s?"), (char *)data1, (char *)data2, (char *)data2); } else { *response = noyes(_("%s and %s are in conflict (%s). Remove %s?"), (char *)data1, (char *)data2, (char *)data3, (char *)data2); } break; case ALPM_QUESTION_REMOVE_PKGS: { alpm_list_t *unresolved = data1; alpm_list_t *namelist = NULL, *i; size_t count = 0; for(i = unresolved; i; i = i->next) { namelist = alpm_list_add(namelist, (char *)alpm_pkg_get_name(i->data)); count++; } colon_printf(_n( "The following package cannot be upgraded due to unresolvable dependencies:\n", "The following packages cannot be upgraded due to unresolvable dependencies:\n", count)); list_display(" ", namelist, getcols(fileno(stdout))); printf("\n"); *response = noyes(_n( "Do you want to skip the above package for this upgrade?", "Do you want to skip the above packages for this upgrade?", count)); alpm_list_free(namelist); } break; case ALPM_QUESTION_SELECT_PROVIDER: { alpm_list_t *providers = data1; size_t count = alpm_list_count(providers); char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2); colon_printf(_("There are %zd providers available for %s:\n"), count, depstring); free(depstring); select_display(providers); *response = select_question(count); } break; case ALPM_QUESTION_CORRUPTED_PKG: *response = yesno(_("File %s is corrupted (%s).\n" "Do you want to delete it?"), (char *)data1, alpm_strerror(*(alpm_errno_t *)data2)); break; case ALPM_QUESTION_IMPORT_KEY: { alpm_pgpkey_t *key = data1; char created[12]; time_t time = (time_t)key->created; strftime(created, 12, "%Y-%m-%d", localtime(&time)); if(key->revoked) { *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s (revoked)?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created); } else { *response = yesno(_("Import PGP key %d%c/%s, \"%s\", created: %s?"), key->length, key->pubkey_algo, key->fingerprint, key->uid, created); } } break; } if(config->noask) { if(config->ask & event) { /* inverse the default answer */ *response = !*response; } } }