summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-05-31 15:48:16 -0400
committerDan McGee <dan@archlinux.org>2007-06-09 12:58:12 -0400
commitb6f3fe6957d0206485eac98fb2120578b75d0058 (patch)
tree394e45bb19e23284e23103fbab85aa3035d54b27
parentdfc85cb5f516ffbcff557522e9703c5c7d88b047 (diff)
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 <vmiklos@frugalware.org> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--doc/pacman.84
-rw-r--r--src/pacman/conf.h1
-rw-r--r--src/pacman/pacman.c7
-rw-r--r--src/pacman/query.c20
4 files changed, 31 insertions, 1 deletions
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 <file> query the package that owns <file>\n"));
printf(_(" -p, --file <package> query a package file instead of the database\n"));
printf(_(" -s, --search <regex> 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();