summaryrefslogtreecommitdiffstats
path: root/src/pacman/query.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/query.c')
-rw-r--r--src/pacman/query.c84
1 files changed, 37 insertions, 47 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 6c63774f..d1105b4a 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -26,7 +26,6 @@
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
-#include <unistd.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -43,15 +42,15 @@ static char *resolve_path(const char *file)
str = calloc(PATH_MAX + 1, sizeof(char));
if(!str) {
- return(NULL);
+ return NULL;
}
if(!realpath(file, str)) {
free(str);
- return(NULL);
+ return NULL;
}
- return(str);
+ return str;
}
/* check if filename exists in PATH */
@@ -61,10 +60,10 @@ static int search_path(char **filename, struct stat *bufptr)
size_t flen;
if((envpath = getenv("PATH")) == NULL) {
- return(-1);
+ return -1;
}
if((envpath = envpathsplit = strdup(envpath)) == NULL) {
- return(-1);
+ return -1;
}
flen = strlen(*filename);
@@ -88,12 +87,12 @@ static int search_path(char **filename, struct stat *bufptr)
free(*filename);
*filename = fullname;
free(envpath);
- return(0);
+ return 0;
}
free(fullname);
}
free(envpath);
- return(-1);
+ return -1;
}
static void print_query_fileowner(const char *filename, pmpkg_t *info)
@@ -119,7 +118,7 @@ static int query_fileowner(alpm_list_t *targets)
/* This code is here for safety only */
if(targets == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n"));
- return(1);
+ return 1;
}
/* Set up our root path buffer. We only need to copy the location of root in
@@ -171,7 +170,7 @@ static int query_fileowner(alpm_list_t *targets)
bname = mbasename(filename);
dname = mdirname(filename);
/* for files in '/', there is no directory name to match */
- if (strcmp(dname, "") == 0) {
+ if(strcmp(dname, "") == 0) {
rpath = NULL;
} else {
rpath = resolve_path(dname);
@@ -252,29 +251,21 @@ static int query_search(alpm_list_t *targets)
freelist = 0;
}
if(searchlist == NULL) {
- return(1);
+ return 1;
}
for(i = searchlist; i; i = alpm_list_next(i)) {
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(i);
- if (!config->quiet) {
+ if(!config->quiet) {
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
printf("%s", alpm_pkg_get_name(pkg));
}
- /* print the package size with the output if ShowSize option set */
- if(!config->quiet && config->showsize) {
- /* Convert byte size to MB */
- double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0);
- printf(" [%.2f MB]", mbsize);
- }
-
-
- if (!config->quiet) {
+ if(!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_list_t *k;
printf(" (");
@@ -300,7 +291,7 @@ static int query_search(alpm_list_t *targets)
if(freelist) {
alpm_list_free(searchlist);
}
- return(0);
+ return 0;
}
static int query_group(alpm_list_t *targets)
@@ -363,19 +354,19 @@ static int is_foreign(pmpkg_t *pkg)
}
}
if(match == 0) {
- return(1);
+ return 1;
}
- return(0);
+ return 0;
}
static int is_unrequired(pmpkg_t *pkg)
{
alpm_list_t *requiredby = alpm_pkg_compute_requiredby(pkg);
if(requiredby == NULL) {
- return(1);
+ return 1;
}
FREELIST(requiredby);
- return(0);
+ return 0;
}
static int filter(pmpkg_t *pkg)
@@ -383,26 +374,26 @@ static int filter(pmpkg_t *pkg)
/* check if this package was explicitly installed */
if(config->op_q_explicit &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_EXPLICIT) {
- return(0);
+ return 0;
}
/* check if this package was installed as a dependency */
if(config->op_q_deps &&
alpm_pkg_get_reason(pkg) != PM_PKG_REASON_DEPEND) {
- return(0);
+ return 0;
}
/* check if this pkg isn't in a sync DB */
if(config->op_q_foreign && !is_foreign(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is unrequired */
if(config->op_q_unrequired && !is_unrequired(pkg)) {
- return(0);
+ return 0;
}
/* check if this pkg is outdated */
if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
- return(0);
+ return 0;
}
- return(1);
+ return 1;
}
/* Loop through the packages. For each package,
@@ -420,7 +411,7 @@ static int check(pmpkg_t *pkg)
if(rootlen + 1 > PATH_MAX) {
/* we are in trouble here */
pm_fprintf(stderr, PM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
- return(1);
+ return 1;
}
strcpy(f, root);
@@ -454,7 +445,7 @@ static int check(pmpkg_t *pkg)
(unsigned long)errors), errors);
}
- return(errors != 0 ? 1 : 0);
+ return (errors != 0 ? 1 : 0);
}
static int display(pmpkg_t *pkg)
@@ -463,10 +454,9 @@ static int display(pmpkg_t *pkg)
if(config->op_q_info) {
if(config->op_q_isfile) {
- /* omit info that isn't applicable for a file package */
- dump_pkg_full(pkg, 0);
+ dump_pkg_full(pkg, PKG_FROM_FILE, 0);
} else {
- dump_pkg_full(pkg, config->op_q_info);
+ dump_pkg_full(pkg, PKG_FROM_LOCALDB, config->op_q_info > 1);
}
}
if(config->op_q_list) {
@@ -480,13 +470,13 @@ static int display(pmpkg_t *pkg)
}
if(!config->op_q_info && !config->op_q_list
&& !config->op_q_changelog && !config->op_q_check) {
- if (!config->quiet) {
+ if(!config->quiet) {
printf("%s %s\n", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
printf("%s\n", alpm_pkg_get_name(pkg));
}
}
- return(ret);
+ return ret;
}
int pacman_query(alpm_list_t *targets)
@@ -502,13 +492,13 @@ int pacman_query(alpm_list_t *targets)
/* search for a package */
if(config->op_q_search) {
ret = query_search(targets);
- return(ret);
+ return ret;
}
/* looking for groups */
if(config->group) {
ret = query_group(targets);
- return(ret);
+ return ret;
}
if(config->op_q_foreign) {
@@ -516,7 +506,7 @@ int pacman_query(alpm_list_t *targets)
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
- return(1);
+ return 1;
}
}
@@ -528,7 +518,7 @@ int pacman_query(alpm_list_t *targets)
if(targets == NULL) {
if(config->op_q_isfile || config->op_q_owns) {
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
- return(1);
+ return 1;
}
for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
@@ -544,7 +534,7 @@ int pacman_query(alpm_list_t *targets)
if(!match) {
ret = 1;
}
- return(ret);
+ return ret;
}
/* Second: operations that require target(s) */
@@ -552,7 +542,7 @@ int pacman_query(alpm_list_t *targets)
/* determine the owner of a file */
if(config->op_q_owns) {
ret = query_fileowner(targets);
- return(ret);
+ return ret;
}
/* operations on named packages in the local DB
@@ -561,7 +551,7 @@ int pacman_query(alpm_list_t *targets)
char *strname = alpm_list_getdata(i);
if(config->op_q_isfile) {
- alpm_pkg_load(strname, 1, &pkg);
+ alpm_pkg_load(strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg);
} else {
pkg = alpm_db_get_pkg(db_local, strname);
}
@@ -590,7 +580,7 @@ int pacman_query(alpm_list_t *targets)
ret = 1;
}
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */