Exemple #1
0
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;
}
Exemple #2
0
/* Dumps info from dbs and returns.
 */
int pacman_db_dump(enum pkgfrom_t from, enum dumplvl_t lvl)
{
	int cnt = 0;
	alpm_list_t *i, *j, *dbs, *syncdbs;
	const char *repo;

	pmdb_t *localdb, *db;
	pmpkg_t *pkg;
	pmdepend_t *dep;

	switch (lvl) {
	case DUMP_Q:
	case DUMP_Q_SEARCH:
	case DUMP_Q_INFO:
		localdb = alpm_option_get_localdb();
		syncdbs = alpm_option_get_syncdbs();
		break;
	case DUMP_S_SEARCH:
	case DUMP_S_INFO:
		dbs = alpm_option_get_syncdbs();
		break;
	}

	if (lvl == DUMP_S_SEARCH || lvl == DUMP_S_INFO) {
		goto dump_sync;
	}

	/* -Qi */
	if (lvl == DUMP_Q_INFO) {
		for (i = alpm_db_get_pkgcache(localdb); i; i = i->next) {
			pacman_pkgdump(i->data, PKG_FROM_LOCAL);
		}
	} else {
		/* plain -Q and -Qs */
		for (j = alpm_db_get_pkgcache(localdb); j; j = j->next) {
			pkg = j->data;
			print_pkg_pretty(syncdbs, pkg, lvl);
		}
	}

	goto done;

dump_sync:
	/* -S */
	for (i = dbs; i; i = i->next) {
		db = i->data;

		for (j = alpm_db_get_pkgcache(db); j; j = j->next) {
			if (cnt++) {
				printf("\n");
			}

			pkg = j->data;
			if (lvl == DUMP_S_INFO) {
				pacman_pkgdump(pkg, from);
			} else {
				/* -Ss */
				print_pkg_pretty(dbs, pkg, lvl);
			}
		}
	}

done:
	if (lvl != DUMP_Q && lvl != DUMP_Q_SEARCH) {
		printf("\n");
	}
	return 0;
}