From b6f3fe6957d0206485eac98fb2120578b75d0058 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 31 May 2007 15:48:16 -0400 Subject: Implement a -Qt operation in frontend to test the database After adding a alpm_db_check() operation in the back end, we can call it in the front end and present a user-friendly interface to it. Inspired-by: VMiklos Signed-off-by: Dan McGee --- doc/pacman.8 | 4 ++++ src/pacman/conf.h | 1 + src/pacman/pacman.c | 7 ++++++- src/pacman/query.c | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/doc/pacman.8 b/doc/pacman.8 index 79097783..4825f4a7 100644 --- a/doc/pacman.8 +++ b/doc/pacman.8 @@ -157,6 +157,10 @@ useful in combination with \fB--info\fP and \fB--list\fP. This will search each locally-installed package for names or descriptions that matche \fIregexp\fP. .TP +.B \-t, --test +Test the consistancy of the local pacman database, and alert you of any +problems found while searching. Returns 0 on success, >0 otherwise. +.TP .B \-u, --upgrades Lists all packages that are out of date on the local system. This option works best if the sync database is refreshed using \fB-Sy\fP. diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 74d83e69..252bb95a 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -45,6 +45,7 @@ typedef struct __config_t { unsigned short op_q_owns; unsigned short op_q_search; unsigned short op_q_changelog; + unsigned short op_q_test; unsigned short op_q_upgrade; unsigned short op_s_clean; unsigned short op_s_dependsonly; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index bfbfb1b9..2f0ed790 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -121,6 +121,7 @@ static void usage(int op, char *myname) printf(_(" -o, --owns query the package that owns \n")); printf(_(" -p, --file query a package file instead of the database\n")); printf(_(" -s, --search search locally-installed packages for matching strings\n")); + printf(_(" -t, --test check the consistency of the local database\n")); printf(_(" -u, --upgrades list all packages that can be upgraded\n")); } else if(op == PM_OP_SYNC) { printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg); @@ -278,6 +279,7 @@ static int parseargs(int argc, char *argv[]) {"root", required_argument, 0, 'r'}, {"recursive", no_argument, 0, 's'}, {"search", no_argument, 0, 's'}, + {"test", no_argument, 0, 't'}, {"upgrades", no_argument, 0, 'u'}, {"sysupgrade", no_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, @@ -296,7 +298,7 @@ static int parseargs(int argc, char *argv[]) }; struct stat st; - while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepiuwygz", opts, &option_index))) { + while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { if(opt < 0) { break; } @@ -402,6 +404,9 @@ static int parseargs(int argc, char *argv[]) config->op_q_search = 1; config->flags |= PM_TRANS_FLAG_RECURSE; break; + case 't': + config->op_q_test = 1; + break; case 'u': config->op_s_upgrade = 1; config->op_q_upgrade = 1; diff --git a/src/pacman/query.c b/src/pacman/query.c index 3863572f..6ca45d91 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -257,6 +257,26 @@ int pacman_query(alpm_list_t *targets) return(ret); } + if(config->op_q_test) { + alpm_list_t *testlist; + printf(_("Checking database for consistency...")); + testlist = alpm_db_test(db_local); + if(testlist == NULL) { + printf(_("check complete.\n")); + return(0); + } else { + /* on failure, increment the ret val by 1 for each failure */ + ret = 0; + printf(_("check failed!\n")); + fflush(stdout); + for(i = testlist; i; i = alpm_list_next(i)) { + fprintf(stderr, "%s\n", (char*)alpm_list_getdata(i)); + ret++; + } + return(ret); + } + } + if(config->op_q_foreign) { sync_dbs = alpm_option_get_syncdbs(); -- cgit v1.2.3-24-g4f1b