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.c73
1 files changed, 50 insertions, 23 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 7f064f23..734875be 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -1,7 +1,7 @@
/*
* query.c
*
- * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -37,13 +37,11 @@
#include "conf.h"
#include "util.h"
-extern pmdb_t *db_local;
-
-static char *resolve_path(const char* file)
+static char *resolve_path(const char *file)
{
char *str = NULL;
- str = calloc(PATH_MAX+1, sizeof(char));
+ str = calloc(PATH_MAX + 1, sizeof(char));
if(!str) {
return(NULL);
}
@@ -97,8 +95,12 @@ static int search_path(char **filename, struct stat *bufptr)
static int query_fileowner(alpm_list_t *targets)
{
int ret = 0;
- char *filename;
+ char path[PATH_MAX];
+ const char *root;
+ char *append;
+ size_t max_length;
alpm_list_t *t;
+ pmdb_t *db_local;
/* This code is here for safety only */
if(targets == NULL) {
@@ -106,13 +108,24 @@ static int query_fileowner(alpm_list_t *targets)
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();
+ strncpy(path, root, PATH_MAX - 1);
+ append = path + strlen(path);
+ max_length = PATH_MAX - (append - path) - 1;
+
+ db_local = alpm_option_get_localdb();
+
for(t = targets; t; t = alpm_list_next(t)) {
+ char *filename, *dname, *rpath;
+ const char *bname;
+ struct stat buf;
+ alpm_list_t *i;
int found = 0;
+
filename = strdup(alpm_list_getdata(t));
- char *bname, *dname, *rpath;
- const char *root;
- struct stat buf;
- alpm_list_t *i, *j;
if(lstat(filename, &buf) == -1) {
/* if it is not a path but a program name, then check in PATH */
@@ -144,32 +157,38 @@ static int query_fileowner(alpm_list_t *targets)
bname = mbasename(filename);
dname = mdirname(filename);
rpath = resolve_path(dname);
- free(dname);
- if(!rpath) {
+ /* this odd conditional is to ensure files in '/' can be checked */
+ if(!rpath && strcmp(dname, "") != 0) {
pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
filename, strerror(errno));
free(filename);
+ free(dname);
free(rpath);
ret++;
continue;
}
+ free(dname);
- root = alpm_option_get_root();
-
- for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) {
+ for(i = alpm_db_get_pkgcache_list(db_local); i && !found; i = alpm_list_next(i)) {
+ alpm_list_t *j;
pmpkg_t *info = alpm_list_getdata(i);
for(j = alpm_pkg_get_files(info); j && !found; j = alpm_list_next(j)) {
- char path[PATH_MAX], *ppath, *pdname;
- snprintf(path, PATH_MAX, "%s%s",
- root, (const char *)alpm_list_getdata(j));
+ char *ppath, *pdname;
+ const char *pkgfile = alpm_list_getdata(j);
/* avoid the costly resolve_path usage if the basenames don't match */
- if(strcmp(mbasename(path), bname) != 0) {
+ if(strcmp(mbasename(pkgfile), bname) != 0) {
continue;
}
+ if(strlen(pkgfile) > max_length) {
+ pm_fprintf(stderr, PM_LOG_ERROR, _("Path too long: %s%s\n"), root, pkgfile);
+ }
+ /* concatenate our file and the root path */
+ strcpy(append, pkgfile);
+
pdname = mdirname(path);
ppath = resolve_path(pdname);
free(pdname);
@@ -202,13 +221,14 @@ static int query_search(alpm_list_t *targets)
{
alpm_list_t *i, *searchlist;
int freelist;
+ pmdb_t *db_local = alpm_option_get_localdb();
/* if we have a targets list, search for packages matching it */
if(targets) {
searchlist = alpm_db_search(db_local, targets);
freelist = 1;
} else {
- searchlist = alpm_db_get_pkgcache(db_local);
+ searchlist = alpm_db_get_pkgcache_list(db_local);
freelist = 0;
}
if(searchlist == NULL) {
@@ -268,6 +288,8 @@ 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();
+
if(targets == NULL) {
for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
@@ -406,8 +428,10 @@ static int check(pmpkg_t *pkg)
}
if(!config->quiet) {
- printf(_("%s: %d total files, %d missing file(s)\n"),
- pkgname, allfiles, errors);
+ printf(_n("%s: %d total file, ", "%s: %d total files, ",
+ (unsigned long)allfiles), pkgname, allfiles);
+ printf(_n("%d missing file\n", "%d missing files\n",
+ (unsigned long)errors), errors);
}
return(errors != 0 ? 1 : 0);
@@ -451,6 +475,7 @@ int pacman_query(alpm_list_t *targets)
int match = 0;
alpm_list_t *i;
pmpkg_t *pkg = NULL;
+ pmdb_t *db_local;
/* First: operations that do not require targets */
@@ -475,6 +500,8 @@ int pacman_query(alpm_list_t *targets)
}
}
+ db_local = alpm_option_get_localdb();
+
/* operations on all packages in the local DB
* valid: no-op (plain -Q), list, info, check
* invalid: isfile, owns */
@@ -484,7 +511,7 @@ int pacman_query(alpm_list_t *targets)
return(1);
}
- for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
+ for(i = alpm_db_get_pkgcache_list(db_local); i; i = alpm_list_next(i)) {
pkg = alpm_list_getdata(i);
if(filter(pkg)) {
int value = display(pkg);