int pacman_query(alpm_list_t *targets) { int ret = 0; int match = 0; alpm_list_t *i; alpm_pkg_t *pkg = NULL; alpm_db_t *db_local; /* First: operations that do not require targets */ /* search for a package */ if(config->op_q_search) { ret = query_search(targets); return ret; } /* looking for groups */ if(config->group) { ret = query_group(targets); return ret; } if(config->op_q_foreign || config->op_q_upgrade) { if(check_syncdbs(1, 1)) { return 1; } } db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check * invalid: isfile, owns */ if(targets == NULL) { if(config->op_q_isfile || config->op_q_owns) { pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); return 1; } for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) { pkg = alpm_list_getdata(i); if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } } if(!match) { ret = 1; } return ret; } /* Second: operations that require target(s) */ /* determine the owner of a file */ if(config->op_q_owns) { ret = query_fileowner(targets); return ret; } /* operations on named packages in the local DB * valid: no-op (plain -Q), list, info, check */ for(i = targets; i; i = alpm_list_next(i)) { char *strname = alpm_list_getdata(i); if(config->op_q_isfile) { alpm_pkg_load(config->handle, strname, 1, 0, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } if(pkg == NULL) { switch(alpm_errno(config->handle)) { case ALPM_ERR_PKG_NOT_FOUND: pm_fprintf(stderr, ALPM_LOG_ERROR, _("package '%s' was not found\n"), strname); if(!config->op_q_isfile && access(strname, R_OK) == 0) { pm_fprintf(stderr, ALPM_LOG_WARNING, _("'%s' is a file, you might want to use %s.\n"), strname, "-p/--file"); } break; default: pm_fprintf(stderr, ALPM_LOG_ERROR, _("could not load package '%s': %s\n"), strname, alpm_strerror(alpm_errno(config->handle))); break; } ret = 1; continue; } if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } if(config->op_q_isfile) { alpm_pkg_free(pkg); pkg = NULL; } } if(!match) { ret = 1; } return ret; }
int powaur_query(alpm_list_t *targets) { alpm_db_t *localdb = alpm_option_get_localdb(config->handle); if (!localdb) { return error(PW_ERR_INIT_LOCALDB); } alpm_list_t *dblist = NULL; alpm_list_t *i, *j, *dbcache; alpm_pkg_t *pkg, *spkg; int ret = 0, found; /* -i and -s conflicting options */ if (config->op_q_info && config->op_q_search) { pw_fprintf(PW_LOG_ERROR, stderr, "-i (info) and -s (search) are " "mutually exclusive.\n"); return -1; } /* No targets */ if (targets == NULL) { dblist = alpm_list_add(dblist, localdb); if (config->op_q_info) { /* -Qi, detailed info */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_INFO); } else if (config->op_q_search) { /* -Qs * repo/pkg ver (grp) * desc */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_SEARCH); } else { /* -Q * repo/pkg ver (grp) */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q); } alpm_list_free(dblist); return ret; } if (config->op_q_info) { ret = query_info(localdb, targets); } else if (config->op_q_search) { ret = query_search(localdb, targets->data); } else { /* Plain -Q */ alpm_list_t *sdbs = alpm_option_get_syncdbs(config->handle); dbcache = alpm_db_get_pkgcache(localdb); for (i = targets; i; i = i->next) { found = 0; for (j = dbcache; j; j = j->next) { pkg = j->data; if (!strcmp(i->data, alpm_pkg_get_name(pkg))) { print_pkg_pretty(sdbs, pkg, DUMP_Q); found = 1; break; } } if (!found) { printf("package \"%s\" not found\n", i->data); ret = -1; } } } return ret; }
int pacman_query(alpm_list_t *targets) { int ret = 0; int match = 0; alpm_list_t *i; alpm_pkg_t *pkg = NULL; alpm_db_t *db_local; /* First: operations that do not require targets */ /* search for a package */ if(config->op_q_search) { ret = query_search(targets); return ret; } /* looking for groups */ if(config->group) { ret = query_group(targets); return ret; } if(config->op_q_foreign || config->op_q_upgrade) { if(check_syncdbs(1, 1)) { return 1; } } db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check * invalid: isfile, owns */ if(targets == NULL) { if(config->op_q_isfile || config->op_q_owns) { pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); return 1; } for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) { pkg = alpm_list_getdata(i); if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } } if(!match) { ret = 1; } return ret; } /* Second: operations that require target(s) */ /* determine the owner of a file */ if(config->op_q_owns) { ret = query_fileowner(targets); return ret; } /* operations on named packages in the local DB * valid: no-op (plain -Q), list, info, check */ for(i = targets; i; i = alpm_list_next(i)) { char *strname = alpm_list_getdata(i); if(config->op_q_isfile) { alpm_pkg_load(config->handle, strname, 1, 0, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } if(pkg == NULL) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("package \"%s\" not found\n"), strname); ret = 1; continue; } if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } if(config->op_q_isfile) { alpm_pkg_free(pkg); pkg = NULL; } } if(!match) { ret = 1; } return ret; }