From 15689bddbfc37ada11c2d4d5d77997dabf303960 Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Wed, 14 Dec 2005 02:23:14 +0000 Subject: added Frugalware patch: -Q --foreign to display packages not found in sync repos --- doc/pacman.8.in | 4 ++++ src/pacman/conf.h | 1 + src/pacman/pacman.c | 5 ++++- src/pacman/query.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/doc/pacman.8.in b/doc/pacman.8.in index a3c93f65..f2b1437e 100644 --- a/doc/pacman.8.in +++ b/doc/pacman.8.in @@ -105,6 +105,10 @@ dependencies, conflicts, etc. List all files in the specified repositories. Multiple repositories can be specified on the command line. .TP +.B "\-m, \-\-foreign" +List all packages that were not found in the sync database(s). Typically these +are packages that were downloading manually and installed with --add. +.TP .B "\-p, \-\-print-uris" Print out URIs for each specified package and its dependencies. These can be piped to a file and downloaded at a later time, using a program diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 678c0062..4b2d3a84 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -38,6 +38,7 @@ typedef struct __config_t { unsigned short op_q_isfile; unsigned short op_q_info; unsigned short op_q_list; + unsigned short op_q_foreign; unsigned short op_q_orphans; unsigned short op_q_owns; unsigned short op_q_search; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 698cbfe2..cdc6816c 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -383,6 +383,7 @@ int parseargs(int argc, char *argv[]) {"dbonly", no_argument, 0, 'k'}, {"list", no_argument, 0, 'l'}, {"nosave", no_argument, 0, 'n'}, + {"foreign", no_argument, 0, 'm'}, {"owns", no_argument, 0, 'o'}, {"file", no_argument, 0, 'p'}, {"print-uris", no_argument, 0, 'p'}, @@ -401,7 +402,7 @@ int parseargs(int argc, char *argv[]) }; char root[PATH_MAX]; - while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfnoldepiuwyg", opts, &option_index))) { + while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) { if(opt < 0) { break; } @@ -443,6 +444,7 @@ int parseargs(int argc, char *argv[]) case 'i': config->op_q_info++; config->op_s_info++; break; case 'k': config->flags |= PM_TRANS_FLAG_DBONLY; break; case 'l': config->op_q_list = 1; break; + case 'm': config->op_q_foreign = 1; break; case 'n': config->flags |= PM_TRANS_FLAG_NOSAVE; break; case 'o': config->op_q_owns = 1; break; case 'p': config->op_q_isfile = 1; config->op_s_printuris = 1; break; @@ -536,6 +538,7 @@ void usage(int op, char *myname) printf(" -g, --groups view all members of a package group\n"); printf(" -i, --info view package information\n"); printf(" -l, --list list the contents of the queried package\n"); + printf(" -m, --foreign list all packages that were not found in the sync repos\n"); printf(" -o, --owns query the package that owns \n"); printf(" -p, --file pacman will query the package file [package] instead of\n"); printf(" looking in the database\n"); diff --git a/src/pacman/query.c b/src/pacman/query.c index f2b74c83..0462f5aa 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -33,9 +33,12 @@ #include "query.h" #include "log.h" #include "conf.h" +#include "sync.h" +#include "util.h" extern config_t *config; extern PM_DB *db_local; +extern list_t *pmc_syncs; static int query_fileowner(PM_DB *db, char *filename) { @@ -90,6 +93,8 @@ int pacman_query(list_t *targets) { PM_PKG *info = NULL; list_t *targ; + list_t *i; + PM_LIST *j; char *package = NULL; int done = 0; @@ -100,6 +105,23 @@ int pacman_query(list_t *targets) return(0); } + if(config->op_q_foreign) { + if(pmc_syncs == NULL || !list_count(pmc_syncs)) { + ERR(NL, "no usable package repositories configured.\n"); + return(1); + } + + /* open the database(s) */ + for(i = pmc_syncs; i; i = i->next) { + sync_t *sync = i->data; + sync->db = alpm_db_register(sync->treename); + if(sync->db == NULL) { + ERR(NL, "%s\n", alpm_strerror(pm_errno)); + return(1); + } + } + } + for(targ = targets; !done; targ = (targ ? targ->next : NULL)) { if(targets == NULL) { done = 1; @@ -182,13 +204,36 @@ int pacman_query(list_t *targets) pkgname = alpm_pkg_getinfo(tmpp, PM_PKG_NAME); pkgver = alpm_pkg_getinfo(tmpp, PM_PKG_VERSION); - if(config->op_q_list || config->op_q_orphans) { + if(config->op_q_list || config->op_q_orphans || config->op_q_foreign) { info = alpm_db_readpkg(db_local, pkgname); if(info == NULL) { /* something weird happened */ ERR(NL, "package \"%s\" not found\n", pkgname); return(1); } + if(config->op_q_foreign) { + int match = 0; + for(i = pmc_syncs; i; i = i->next) { + sync_t *sync = (sync_t *)i->data; + for(j = alpm_db_getpkgcache(sync->db); j; j = alpm_list_next(j)) { + PM_PKG *pkg = alpm_list_getdata(j); + char *haystack; + char *needle; + haystack = strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME)); + strtoupper(haystack); + needle = strdup(alpm_pkg_getinfo(info, PM_PKG_NAME)); + strtoupper(needle); + if(strstr(haystack, needle)) { + match = 1; + } + FREE(haystack); + FREE(needle); + } + } + if(match==0) { + MSG(NL, "%s %s\n", pkgname, pkgver); + } + } if(config->op_q_list) { dump_pkg_files(info); } -- cgit v1.2.3-24-g4f1b