diff options
Diffstat (limited to 'src/pacman/query.c')
-rw-r--r-- | src/pacman/query.c | 124 |
1 files changed, 56 insertions, 68 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c index 6c63774f..62472cb7 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> @@ -41,17 +40,17 @@ static char *resolve_path(const char *file) { char *str = NULL; - str = calloc(PATH_MAX + 1, sizeof(char)); + str = calloc(PATH_MAX, 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); @@ -80,7 +79,7 @@ static int search_path(char **filename, struct stat *bufptr) fullname = malloc(plen + flen + 2); if(!fullname) { free(envpath); - return(-1); + return -1; } sprintf(fullname, "%s/%s", path, *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,18 +118,18 @@ 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 * once, then we can just overwrite whatever file was there on the previous * iteration. */ - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); strncpy(path, root, PATH_MAX - 1); append = path + strlen(path); max_length = PATH_MAX - (append - path) - 1; - db_local = alpm_option_get_localdb(); + db_local = alpm_option_get_localdb(config->handle); for(t = targets; t; t = alpm_list_next(t)) { char *filename, *dname, *rpath; @@ -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); @@ -241,7 +240,7 @@ static int query_search(alpm_list_t *targets) { alpm_list_t *i, *searchlist; int freelist; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); /* if we have a targets list, search for packages matching it */ if(targets) { @@ -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) @@ -308,19 +299,16 @@ static int query_group(alpm_list_t *targets) alpm_list_t *i, *j; char *grpname = NULL; int ret = 0; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); if(targets == NULL) { for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) { pmgrp_t *grp = alpm_list_getdata(j); - const alpm_list_t *p, *packages; - const char *grpname; + const alpm_list_t *p; - grpname = alpm_grp_get_name(grp); - packages = alpm_grp_get_pkgs(grp); - - for(p = packages; p; p = alpm_list_next(p)) { - printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p))); + for(p = grp->packages; p; p = alpm_list_next(p)) { + pmpkg_t *pkg = alpm_list_getdata(p); + printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg)); } } } else { @@ -329,8 +317,8 @@ static int query_group(alpm_list_t *targets) grpname = alpm_list_getdata(i); grp = alpm_db_readgrp(db_local, grpname); if(grp) { - const alpm_list_t *p, *packages = alpm_grp_get_pkgs(grp); - for(p = packages; p; p = alpm_list_next(p)) { + const alpm_list_t *p; + for(p = grp->packages; p; p = alpm_list_next(p)) { if(!config->quiet) { printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p))); @@ -351,7 +339,7 @@ static int is_foreign(pmpkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); alpm_list_t *j; - alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); int match = 0; for(j = sync_dbs; j; j = alpm_list_next(j)) { @@ -363,19 +351,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 +371,27 @@ 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); + if(config->op_q_upgrade && (alpm_sync_newversion(pkg, + alpm_option_get_syncdbs(config->handle)) == NULL)) { + return 0; } - return(1); + return 1; } /* Loop through the packages. For each package, @@ -415,12 +404,12 @@ static int check(pmpkg_t *pkg) size_t rootlen; char f[PATH_MAX]; - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); rootlen = strlen(root); 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 +443,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 +452,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 +468,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,25 +490,25 @@ 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) { /* ensure we have at least one valid sync db set up */ - alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); - if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) { + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); + if(sync_dbs == NULL) { pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n")); - return(1); + return 1; } } - db_local = alpm_option_get_localdb(); + db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check @@ -528,7 +516,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 +532,7 @@ int pacman_query(alpm_list_t *targets) if(!match) { ret = 1; } - return(ret); + return ret; } /* Second: operations that require target(s) */ @@ -552,7 +540,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 +549,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(config->handle, strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } @@ -590,7 +578,7 @@ int pacman_query(alpm_list_t *targets) ret = 1; } - return(ret); + return ret; } /* vim: set ts=2 sw=2 noet: */ |