2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* query.c
|
2007-06-02 12:34:01 -04:00
|
|
|
*
|
2013-01-01 23:19:59 -05:00
|
|
|
* Copyright (c) 2006-2013 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-06-02 12:34:01 -04:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2011-09-07 21:41:09 -04:00
|
|
|
#include <stdint.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
2011-09-01 19:01:33 -04:00
|
|
|
#include <unistd.h>
|
2007-03-20 23:08:19 -04:00
|
|
|
#include <errno.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-19 04:28:44 -05:00
|
|
|
#include <alpm_list.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2007-04-25 02:21:12 -04:00
|
|
|
#include "pacman.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "package.h"
|
2012-05-03 22:07:50 -04:00
|
|
|
#include "check.h"
|
2005-10-28 08:20:40 -04:00
|
|
|
#include "conf.h"
|
2005-12-13 21:23:14 -05:00
|
|
|
#include "util.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2012-05-19 09:36:30 -04:00
|
|
|
#define LOCAL_PREFIX "local/"
|
|
|
|
|
2010-03-06 22:02:37 -05:00
|
|
|
/* check if filename exists in PATH */
|
|
|
|
static int search_path(char **filename, struct stat *bufptr)
|
|
|
|
{
|
|
|
|
char *envpath, *envpathsplit, *path, *fullname;
|
|
|
|
size_t flen;
|
|
|
|
|
2011-04-20 20:45:16 -04:00
|
|
|
if((envpath = getenv("PATH")) == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
2011-04-20 20:45:16 -04:00
|
|
|
if((envpath = envpathsplit = strdup(envpath)) == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
flen = strlen(*filename);
|
|
|
|
|
2011-04-20 20:45:16 -04:00
|
|
|
while((path = strsep(&envpathsplit, ":")) != NULL) {
|
2010-03-06 22:02:37 -05:00
|
|
|
size_t plen = strlen(path);
|
|
|
|
|
|
|
|
/* strip the trailing slash if one exists */
|
|
|
|
while(path[plen - 1] == '/') {
|
2012-07-26 01:04:20 -04:00
|
|
|
path[--plen] = '\0';
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fullname = malloc(plen + flen + 2);
|
2011-05-19 17:59:53 -04:00
|
|
|
if(!fullname) {
|
|
|
|
free(envpath);
|
2011-06-13 18:43:09 -04:00
|
|
|
return -1;
|
2011-05-19 17:59:53 -04:00
|
|
|
}
|
2010-03-06 22:02:37 -05:00
|
|
|
sprintf(fullname, "%s/%s", path, *filename);
|
|
|
|
|
|
|
|
if(lstat(fullname, bufptr) == 0) {
|
|
|
|
free(*filename);
|
|
|
|
*filename = fullname;
|
|
|
|
free(envpath);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
|
|
|
free(fullname);
|
|
|
|
}
|
|
|
|
free(envpath);
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static void print_query_fileowner(const char *filename, alpm_pkg_t *info)
|
2011-04-02 15:03:03 -04:00
|
|
|
{
|
2011-04-20 20:45:16 -04:00
|
|
|
if(!config->quiet) {
|
2011-04-02 15:03:03 -04:00
|
|
|
printf(_("%s is owned by %s %s\n"), filename,
|
|
|
|
alpm_pkg_get_name(info), alpm_pkg_get_version(info));
|
|
|
|
} else {
|
|
|
|
printf("%s\n", alpm_pkg_get_name(info));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
/** Resolve the canonicalized absolute path of a symlink.
|
|
|
|
* @param path path to resolve
|
|
|
|
* @param resolved_path destination for the resolved path, will be malloc'd if
|
|
|
|
* NULL
|
|
|
|
* @return the resolved path
|
|
|
|
*/
|
|
|
|
static char *lrealpath(const char *path, char *resolved_path)
|
|
|
|
{
|
|
|
|
const char *bname = mbasename(path);
|
|
|
|
char *rpath = NULL, *dname = NULL;
|
|
|
|
int success = 0;
|
|
|
|
|
|
|
|
if(strcmp(path, ".") == 0 || strcmp(path, "..") == 0) {
|
|
|
|
/* the entire path needs to be resolved */
|
|
|
|
return realpath(path, resolved_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(dname = mdirname(path))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if(!(rpath = realpath(dname, NULL))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if(!resolved_path) {
|
|
|
|
if(!(resolved_path = malloc(strlen(rpath) + strlen(bname) + 2))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(resolved_path, rpath);
|
|
|
|
if(resolved_path[strlen(resolved_path) - 1] != '/') {
|
|
|
|
strcat(resolved_path, "/");
|
|
|
|
}
|
|
|
|
strcat(resolved_path, bname);
|
|
|
|
success = 1;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(dname);
|
|
|
|
free(rpath);
|
|
|
|
|
|
|
|
return (success ? resolved_path : NULL);
|
|
|
|
}
|
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
static int query_fileowner(alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-06-02 12:34:01 -04:00
|
|
|
int ret = 0;
|
2011-01-22 15:29:02 -05:00
|
|
|
char path[PATH_MAX];
|
2011-07-05 15:16:17 -04:00
|
|
|
size_t rootlen;
|
2007-06-02 12:34:01 -04:00
|
|
|
alpm_list_t *t;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db_local;
|
2012-09-08 17:14:19 -04:00
|
|
|
alpm_list_t *packages;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-12 23:55:14 -04:00
|
|
|
/* This code is here for safety only */
|
2007-06-02 12:34:01 -04:00
|
|
|
if(targets == NULL) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("no file was specified for --owns\n"));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-01-22 15:29:02 -05:00
|
|
|
/* 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. */
|
2012-07-26 01:01:50 -04:00
|
|
|
|
|
|
|
/* resolve root now so any symlinks in it will only have to be resolved once */
|
|
|
|
if(!realpath(alpm_option_get_root(config->handle), path)) {
|
|
|
|
pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
|
|
|
|
path, strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure there's enough room to append the package file to path */
|
|
|
|
rootlen = strlen(path);
|
|
|
|
if(rootlen + 2 > PATH_MAX) {
|
|
|
|
pm_printf(ALPM_LOG_ERROR, _("path too long: %s%s\n"), path, "");
|
2011-07-05 15:16:17 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2012-07-26 01:01:50 -04:00
|
|
|
|
|
|
|
/* append trailing '/' removed by realpath */
|
2012-08-28 21:59:25 -04:00
|
|
|
if(path[rootlen - 1] != '/') {
|
|
|
|
path[rootlen++] = '/';
|
|
|
|
path[rootlen] = '\0';
|
|
|
|
}
|
2011-01-22 15:29:02 -05:00
|
|
|
|
2012-02-02 00:45:52 -05:00
|
|
|
db_local = alpm_get_localdb(config->handle);
|
2012-09-08 17:14:19 -04:00
|
|
|
packages = alpm_db_get_pkgcache(db_local);
|
2011-01-28 18:41:15 -05:00
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
for(t = targets; t; t = alpm_list_next(t)) {
|
2013-04-13 17:31:08 -04:00
|
|
|
char *filename = NULL;
|
|
|
|
char rpath[PATH_MAX], *rel_path;
|
2011-01-22 15:29:02 -05:00
|
|
|
struct stat buf;
|
|
|
|
alpm_list_t *i;
|
2013-04-13 17:31:08 -04:00
|
|
|
size_t len, is_dir;
|
2012-09-18 22:34:07 -04:00
|
|
|
unsigned int found = 0;
|
2011-01-22 15:29:02 -05:00
|
|
|
|
2012-08-11 17:35:13 -04:00
|
|
|
if((filename = strdup(t->data)) == NULL) {
|
|
|
|
goto targcleanup;
|
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2012-07-26 01:04:20 -04:00
|
|
|
/* trailing '/' causes lstat to dereference directory symlinks */
|
|
|
|
len = strlen(filename) - 1;
|
|
|
|
while(len > 0 && filename[len] == '/') {
|
|
|
|
filename[len--] = '\0';
|
|
|
|
}
|
|
|
|
|
2009-07-25 14:00:06 -04:00
|
|
|
if(lstat(filename, &buf) == -1) {
|
2010-03-06 22:02:37 -05:00
|
|
|
/* if it is not a path but a program name, then check in PATH */
|
|
|
|
if(strchr(filename, '/') == NULL) {
|
|
|
|
if(search_path(&filename, &buf) == -1) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s\n"),
|
2010-03-06 22:02:37 -05:00
|
|
|
filename, strerror(errno));
|
2012-08-11 17:35:13 -04:00
|
|
|
goto targcleanup;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
|
|
|
} else {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("failed to read file '%s': %s\n"),
|
2010-03-06 22:02:37 -05:00
|
|
|
filename, strerror(errno));
|
2012-08-11 17:35:13 -04:00
|
|
|
goto targcleanup;
|
2010-03-06 22:02:37 -05:00
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2007-03-20 23:08:19 -04:00
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
if(!lrealpath(filename, rpath)) {
|
2012-08-11 17:35:12 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
|
|
|
|
filename, strerror(errno));
|
|
|
|
goto targcleanup;
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2008-05-04 20:15:49 -04:00
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
if(strncmp(rpath, path, rootlen) != 0) {
|
|
|
|
/* file is outside root, we know nothing can own it */
|
|
|
|
pm_printf(ALPM_LOG_ERROR, _("No package owns %s\n"), filename);
|
|
|
|
goto targcleanup;
|
|
|
|
}
|
2012-09-08 17:14:19 -04:00
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
rel_path = rpath + rootlen;
|
2012-09-08 17:14:19 -04:00
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
if((is_dir = S_ISDIR(buf.st_mode))) {
|
|
|
|
size_t rlen = strlen(rpath);
|
|
|
|
if(rlen + 2 >= PATH_MAX) {
|
|
|
|
pm_printf(ALPM_LOG_ERROR, _("path too long: %s/\n"), rpath);
|
|
|
|
}
|
|
|
|
strcat(rpath + rlen, "/");
|
|
|
|
}
|
2007-03-22 03:32:54 -04:00
|
|
|
|
2013-04-13 17:31:08 -04:00
|
|
|
for(i = packages; i && (!found || is_dir); i = alpm_list_next(i)) {
|
|
|
|
if(alpm_filelist_contains(alpm_pkg_get_files(i->data), rel_path)) {
|
|
|
|
print_query_fileowner(rpath, i->data);
|
|
|
|
found = 1;
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
if(!found) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("No package owns %s\n"), filename);
|
2012-08-11 17:35:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
targcleanup:
|
|
|
|
if(!found) {
|
2007-06-02 12:34:01 -04:00
|
|
|
ret++;
|
|
|
|
}
|
2010-03-06 22:02:37 -05:00
|
|
|
free(filename);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-03-22 03:32:54 -04:00
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
/* search the local database for a matching package */
|
|
|
|
static int query_search(alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_db_t *db_local = alpm_get_localdb(config->handle);
|
2013-02-28 13:56:28 -05:00
|
|
|
return dump_pkg_search(db_local, targets, 0);
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2007-05-14 01:21:42 -04:00
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
static int query_group(alpm_list_t *targets)
|
|
|
|
{
|
|
|
|
alpm_list_t *i, *j;
|
2011-10-06 01:55:47 -04:00
|
|
|
const char *grpname = NULL;
|
2007-06-02 12:34:01 -04:00
|
|
|
int ret = 0;
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_db_t *db_local = alpm_get_localdb(config->handle);
|
2011-01-28 18:41:15 -05:00
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
if(targets == NULL) {
|
2011-06-29 01:46:49 -04:00
|
|
|
for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
alpm_group_t *grp = j->data;
|
2011-06-16 12:55:26 -04:00
|
|
|
const alpm_list_t *p;
|
2007-06-02 12:34:01 -04:00
|
|
|
|
2011-06-16 12:55:26 -04:00
|
|
|
for(p = grp->packages; p; p = alpm_list_next(p)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
alpm_pkg_t *pkg = p->data;
|
2011-06-16 12:55:26 -04:00
|
|
|
printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
2011-06-28 00:37:16 -04:00
|
|
|
alpm_group_t *grp;
|
2011-10-06 01:55:47 -04:00
|
|
|
grpname = i->data;
|
2012-02-02 00:45:52 -05:00
|
|
|
grp = alpm_db_get_group(db_local, grpname);
|
2007-06-02 12:34:01 -04:00
|
|
|
if(grp) {
|
2011-06-16 12:55:26 -04:00
|
|
|
const alpm_list_t *p;
|
|
|
|
for(p = grp->packages; p; p = alpm_list_next(p)) {
|
2008-07-16 08:42:25 -04:00
|
|
|
if(!config->quiet) {
|
|
|
|
printf("%s %s\n", grpname,
|
2011-10-06 01:55:47 -04:00
|
|
|
alpm_pkg_get_name(p->data));
|
2008-07-16 08:42:25 -04:00
|
|
|
} else {
|
2011-10-06 01:55:47 -04:00
|
|
|
printf("%s\n", alpm_pkg_get_name(p->data));
|
2008-07-16 08:42:25 -04:00
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2007-01-24 03:51:50 -05:00
|
|
|
} else {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("group '%s' was not found\n"), grpname);
|
2007-06-02 12:34:01 -04:00
|
|
|
ret++;
|
2007-01-24 03:51:50 -05:00
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2007-01-24 03:51:50 -05:00
|
|
|
|
2012-12-13 10:06:41 -05:00
|
|
|
static unsigned short pkg_get_locality(alpm_pkg_t *pkg)
|
2007-06-12 23:55:14 -04:00
|
|
|
{
|
2007-07-14 14:45:30 -04:00
|
|
|
const char *pkgname = alpm_pkg_get_name(pkg);
|
|
|
|
alpm_list_t *j;
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_list_t *sync_dbs = alpm_get_syncdbs(config->handle);
|
2007-07-14 14:45:30 -04:00
|
|
|
|
|
|
|
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
2012-12-01 00:40:46 -05:00
|
|
|
if(alpm_db_get_pkg(j->data, pkgname)) {
|
2012-12-13 10:06:41 -05:00
|
|
|
return PKG_LOCALITY_LOCAL;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
|
|
|
}
|
2012-12-13 10:06:41 -05:00
|
|
|
return PKG_LOCALITY_FOREIGN;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2007-06-12 23:55:14 -04:00
|
|
|
|
2013-06-17 04:46:38 -04:00
|
|
|
static int is_unrequired(alpm_pkg_t *pkg, unsigned short level)
|
2007-07-14 14:45:30 -04:00
|
|
|
{
|
2007-11-12 20:40:08 -05:00
|
|
|
alpm_list_t *requiredby = alpm_pkg_compute_requiredby(pkg);
|
|
|
|
if(requiredby == NULL) {
|
2013-06-17 04:46:38 -04:00
|
|
|
if(level == 1) {
|
|
|
|
requiredby = alpm_pkg_compute_optionalfor(pkg);
|
|
|
|
}
|
|
|
|
if(requiredby == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
2007-05-31 15:48:16 -04:00
|
|
|
}
|
2007-11-12 20:40:08 -05:00
|
|
|
FREELIST(requiredby);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
2007-05-31 15:48:16 -04:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static int filter(alpm_pkg_t *pkg)
|
2007-06-12 23:55:14 -04:00
|
|
|
{
|
2007-07-14 18:44:06 -04:00
|
|
|
/* check if this package was explicitly installed */
|
|
|
|
if(config->op_q_explicit &&
|
2011-07-01 12:01:38 -04:00
|
|
|
alpm_pkg_get_reason(pkg) != ALPM_PKG_REASON_EXPLICIT) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-07-14 18:44:06 -04:00
|
|
|
}
|
|
|
|
/* check if this package was installed as a dependency */
|
|
|
|
if(config->op_q_deps &&
|
2011-07-01 12:01:38 -04:00
|
|
|
alpm_pkg_get_reason(pkg) != ALPM_PKG_REASON_DEPEND) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-07-14 18:44:06 -04:00
|
|
|
}
|
2012-12-13 10:06:41 -05:00
|
|
|
/* check if this pkg is or isn't in a sync DB */
|
|
|
|
if(config->op_q_locality && config->op_q_locality & pkg_get_locality(pkg)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2008-01-10 09:59:43 -05:00
|
|
|
/* check if this pkg is unrequired */
|
2013-06-17 04:46:38 -04:00
|
|
|
if(config->op_q_unrequired && !is_unrequired(pkg, config->op_q_unrequired)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2008-10-23 20:05:12 -04:00
|
|
|
/* check if this pkg is outdated */
|
2011-06-07 14:15:43 -04:00
|
|
|
if(config->op_q_upgrade && (alpm_sync_newversion(pkg,
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_get_syncdbs(config->handle)) == NULL)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2008-10-23 20:05:12 -04:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2007-01-19 04:28:44 -05:00
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static int display(alpm_pkg_t *pkg)
|
2009-03-30 12:48:15 -04:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2007-07-14 14:45:30 -04:00
|
|
|
if(config->op_q_info) {
|
2007-11-11 16:02:33 -05:00
|
|
|
if(config->op_q_isfile) {
|
2011-08-29 00:41:17 -04:00
|
|
|
dump_pkg_full(pkg, 0);
|
2007-11-11 16:02:33 -05:00
|
|
|
} else {
|
2011-08-29 00:41:17 -04:00
|
|
|
dump_pkg_full(pkg, config->op_q_info > 1);
|
2007-11-11 16:02:33 -05:00
|
|
|
}
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
|
|
|
if(config->op_q_list) {
|
2009-05-10 16:41:29 -04:00
|
|
|
dump_pkg_files(pkg, config->quiet);
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
|
|
|
if(config->op_q_changelog) {
|
2007-12-09 00:42:04 -05:00
|
|
|
dump_pkg_changelog(pkg);
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2009-03-30 12:48:15 -04:00
|
|
|
if(config->op_q_check) {
|
2012-05-03 23:56:55 -04:00
|
|
|
if(config->op_q_check == 1) {
|
|
|
|
ret = check_pkg_fast(pkg);
|
|
|
|
} else {
|
|
|
|
ret = check_pkg_full(pkg);
|
|
|
|
}
|
2009-03-30 12:48:15 -04:00
|
|
|
}
|
|
|
|
if(!config->op_q_info && !config->op_q_list
|
|
|
|
&& !config->op_q_changelog && !config->op_q_check) {
|
2011-04-20 20:45:16 -04:00
|
|
|
if(!config->quiet) {
|
2013-03-01 15:48:17 -05:00
|
|
|
const colstr_t *colstr = &config->colstr;
|
|
|
|
printf("%s%s %s%s%s\n", colstr->title, alpm_pkg_get_name(pkg),
|
|
|
|
colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor);
|
2007-11-07 02:05:33 -05:00
|
|
|
} else {
|
|
|
|
printf("%s\n", alpm_pkg_get_name(pkg));
|
|
|
|
}
|
2005-12-13 21:23:14 -05:00
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int pacman_query(alpm_list_t *targets)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2009-08-18 10:56:19 -04:00
|
|
|
int match = 0;
|
2007-06-12 23:55:14 -04:00
|
|
|
alpm_list_t *i;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = NULL;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db_local;
|
2005-12-13 21:23:14 -05:00
|
|
|
|
2007-06-12 23:55:14 -04:00
|
|
|
/* First: operations that do not require targets */
|
|
|
|
|
|
|
|
/* search for a package */
|
|
|
|
if(config->op_q_search) {
|
|
|
|
ret = query_search(targets);
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
|
|
|
|
2007-06-02 12:34:01 -04:00
|
|
|
/* looking for groups */
|
|
|
|
if(config->group) {
|
|
|
|
ret = query_group(targets);
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2012-12-13 10:06:41 -05:00
|
|
|
if(config->op_q_locality || config->op_q_upgrade) {
|
2011-06-08 00:08:06 -04:00
|
|
|
if(check_syncdbs(1, 1)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
2007-06-02 12:34:01 -04:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2012-02-02 00:45:52 -05:00
|
|
|
db_local = alpm_get_localdb(config->handle);
|
2011-01-28 18:41:15 -05:00
|
|
|
|
2007-06-12 23:55:14 -04:00
|
|
|
/* operations on all packages in the local DB
|
2009-03-30 12:48:15 -04:00
|
|
|
* valid: no-op (plain -Q), list, info, check
|
2007-06-12 23:55:14 -04:00
|
|
|
* invalid: isfile, owns */
|
2007-07-14 14:45:30 -04:00
|
|
|
if(targets == NULL) {
|
|
|
|
if(config->op_q_isfile || config->op_q_owns) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2007-07-14 14:45:30 -04:00
|
|
|
}
|
|
|
|
|
2011-02-25 09:22:09 -05:00
|
|
|
for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
pkg = i->data;
|
2007-07-14 14:45:30 -04:00
|
|
|
if(filter(pkg)) {
|
2009-03-30 12:48:15 -04:00
|
|
|
int value = display(pkg);
|
|
|
|
if(value != 0) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
2009-08-18 10:56:19 -04:00
|
|
|
match = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2009-08-18 10:56:19 -04:00
|
|
|
if(!match) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-06-12 23:55:14 -04:00
|
|
|
/* Second: operations that require target(s) */
|
|
|
|
|
|
|
|
/* determine the owner of a file */
|
|
|
|
if(config->op_q_owns) {
|
|
|
|
ret = query_fileowner(targets);
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* operations on named packages in the local DB
|
2009-03-30 12:48:15 -04:00
|
|
|
* valid: no-op (plain -Q), list, info, check */
|
2007-06-12 23:55:14 -04:00
|
|
|
for(i = targets; i; i = alpm_list_next(i)) {
|
2011-10-06 01:55:47 -04:00
|
|
|
const char *strname = i->data;
|
2007-07-14 14:45:30 -04:00
|
|
|
|
2012-05-19 09:36:30 -04:00
|
|
|
/* strip leading part of "local/pkgname" */
|
|
|
|
if(strncmp(strname, LOCAL_PREFIX, strlen(LOCAL_PREFIX)) == 0) {
|
|
|
|
strname += strlen(LOCAL_PREFIX);
|
|
|
|
}
|
|
|
|
|
2007-07-14 14:45:30 -04:00
|
|
|
if(config->op_q_isfile) {
|
2011-06-27 17:29:49 -04:00
|
|
|
alpm_pkg_load(config->handle, strname, 1, 0, &pkg);
|
2007-07-14 14:45:30 -04:00
|
|
|
} else {
|
|
|
|
pkg = alpm_db_get_pkg(db_local, strname);
|
|
|
|
}
|
|
|
|
|
2007-06-12 23:55:14 -04:00
|
|
|
if(pkg == NULL) {
|
2011-08-25 19:29:00 -04:00
|
|
|
switch(alpm_errno(config->handle)) {
|
|
|
|
case ALPM_ERR_PKG_NOT_FOUND:
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR,
|
2011-08-25 19:29:00 -04:00
|
|
|
_("package '%s' was not found\n"), strname);
|
2011-09-01 19:01:33 -04:00
|
|
|
if(!config->op_q_isfile && access(strname, R_OK) == 0) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_WARNING,
|
2011-09-05 13:16:07 -04:00
|
|
|
_("'%s' is a file, you might want to use %s.\n"),
|
2011-09-01 19:01:33 -04:00
|
|
|
strname, "-p/--file");
|
|
|
|
}
|
2011-08-25 19:29:00 -04:00
|
|
|
break;
|
|
|
|
default:
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR,
|
2011-08-25 19:29:00 -04:00
|
|
|
_("could not load package '%s': %s\n"), strname,
|
|
|
|
alpm_strerror(alpm_errno(config->handle)));
|
|
|
|
break;
|
|
|
|
}
|
2009-03-30 12:48:15 -04:00
|
|
|
ret = 1;
|
2007-06-12 23:55:14 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-07-14 14:45:30 -04:00
|
|
|
if(filter(pkg)) {
|
2009-03-30 12:48:15 -04:00
|
|
|
int value = display(pkg);
|
|
|
|
if(value != 0) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
2009-08-18 10:56:19 -04:00
|
|
|
match = 1;
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
2007-11-25 15:12:00 -05:00
|
|
|
|
|
|
|
if(config->op_q_isfile) {
|
|
|
|
alpm_pkg_free(pkg);
|
|
|
|
pkg = NULL;
|
|
|
|
}
|
2007-06-12 23:55:14 -04:00
|
|
|
}
|
|
|
|
|
2009-08-18 10:56:19 -04:00
|
|
|
if(!match) {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|