From 6c7f5212985e6171abe943b386694c17c2240322 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Mon, 10 Oct 2005 15:05:12 +0000 Subject: improved query_fileowner() function --- src/pacman/query.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/pacman/query.c b/src/pacman/query.c index 71c02c71..d13c1af9 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -54,12 +54,12 @@ static int query_fileowner(PM_DB *db, char *filename) return(0); } if(filename == NULL || strlen(filename) == 0) { - fprintf(stderr, "error: no file was specified for --owns\n"); + ERR(NL, "no file was specified for --owns\n"); return(1); } if(stat(filename, &buf) == -1 || S_ISDIR(buf.st_mode) || realpath(filename, rpath) == NULL) { - fprintf(stderr, "error: %s is not a file.\n", filename); + ERR(NL, "%s is not a file.\n", filename); return(1); } @@ -67,23 +67,16 @@ static int query_fileowner(PM_DB *db, char *filename) for(lp = alpm_db_getpkgcache(db); lp && !gotcha; lp = alpm_list_next(lp)) { PM_PKG *info; - char *pkgname; PM_LIST *i; - pkgname = alpm_pkg_getinfo(alpm_list_getdata(lp), PM_PKG_NAME); - - info = alpm_db_readpkg(db, pkgname); - if(info == NULL) { - fprintf(stderr, "error: package %s not found\n", pkgname); - return(1); - } + info = alpm_list_getdata(lp); for(i = alpm_pkg_getinfo(info, PM_PKG_FILES); i && !gotcha; i = alpm_list_next(i)) { char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s%s", root, (char *)alpm_list_getdata(i)); if(!strcmp(path, rpath)) { - printf("%s is owned by %s %s\n", filename, pkgname, + printf("%s is owned by %s %s\n", filename, (char *)alpm_pkg_getinfo(info, PM_PKG_NAME), (char *)alpm_pkg_getinfo(info, PM_PKG_VERSION)); gotcha = 1; break; @@ -91,7 +84,7 @@ static int query_fileowner(PM_DB *db, char *filename) } } if(!gotcha) { - fprintf(stderr, "No package owns %s\n", filename); + ERR(NL, "No package owns %s\n", filename); return(1); } -- cgit v1.2.3-70-g09d2