summaryrefslogtreecommitdiffstats
path: root/src/util/testdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/testdb.c')
-rw-r--r--src/util/testdb.c67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 0436a23f..af5007e2 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -31,9 +31,11 @@
#define BASENAME "testdb"
+pmhandle_t *handle = NULL;
+
static void cleanup(int signum) {
- if(alpm_release() == -1) {
- fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
+ if(handle && alpm_release(handle) == -1) {
+ fprintf(stderr, "error releasing alpm\n");
}
exit(signum);
@@ -59,14 +61,14 @@ static int check_localdb_files(void)
int ret = 0;
DIR *dir;
- dbpath = alpm_option_get_dbpath();
+ dbpath = alpm_option_get_dbpath(handle);
snprintf(path, sizeof(path), "%slocal", dbpath);
if(!(dir = opendir(path))) {
fprintf(stderr, "error : %s : %s\n", path, strerror(errno));
- return(1);
+ return 1;
}
- while ((ent = readdir(dir)) != NULL) {
+ while((ent = readdir(dir)) != NULL) {
if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0
|| ent->d_name[0] == '.') {
continue;
@@ -85,10 +87,10 @@ static int check_localdb_files(void)
}
if(closedir(dir)) {
fprintf(stderr, "error closing dbpath : %s\n", strerror(errno));
- return(1);
+ return 1;
}
- return(ret);
+ return ret;
}
static int checkdeps(alpm_list_t *pkglist)
@@ -96,18 +98,17 @@ static int checkdeps(alpm_list_t *pkglist)
alpm_list_t *data, *i;
int ret = 0;
/* check dependencies */
- data = alpm_checkdeps(pkglist, 0, NULL, pkglist);
+ data = alpm_checkdeps(handle, pkglist, NULL, pkglist, 0);
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
- pmdepend_t *dep = alpm_miss_get_dep(miss);
- char *depstring = alpm_dep_compute_string(dep);
- printf("missing dependency for %s : %s\n", alpm_miss_get_target(miss),
+ char *depstring = alpm_dep_compute_string(miss->depend);
+ printf("missing dependency for %s : %s\n", miss->target,
depstring);
free(depstring);
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int checkconflicts(alpm_list_t *pkglist)
@@ -115,15 +116,15 @@ static int checkconflicts(alpm_list_t *pkglist)
alpm_list_t *data, *i;
int ret = 0;
/* check conflicts */
- data = alpm_checkconflicts(pkglist);
+ data = alpm_checkconflicts(handle, pkglist);
for(i = data; i; i = i->next) {
pmconflict_t *conflict = alpm_list_getdata(i);
- printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict),
- alpm_conflict_get_package2(conflict));
+ printf("%s conflicts with %s\n",
+ conflict->package1, conflict->package2);
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int check_localdb(void) {
@@ -133,19 +134,14 @@ static int check_localdb(void) {
ret = check_localdb_files();
if(ret) {
- return(ret);
+ return ret;
}
- db = alpm_option_get_localdb();
- if(db == NULL) {
- fprintf(stderr, "error: could not register 'local' database (%s)\n",
- alpm_strerrorlast());
- cleanup(EXIT_FAILURE);
- }
+ db = alpm_option_get_localdb(handle);
pkglist = alpm_db_get_pkgcache(db);
ret += checkdeps(pkglist);
ret += checkconflicts(pkglist);
- return(ret);
+ return ret;
}
static int check_syncdbs(alpm_list_t *dbnames) {
@@ -155,10 +151,10 @@ static int check_syncdbs(alpm_list_t *dbnames) {
for(i = dbnames; i; i = alpm_list_next(i)) {
char *dbname = alpm_list_getdata(i);
- db = alpm_db_register_sync(dbname);
+ db = alpm_db_register_sync(handle, dbname, PM_PGP_VERIFY_OPTIONAL);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database (%s)\n",
- alpm_strerrorlast());
+ alpm_strerror(alpm_errno(handle)));
ret = 1;
goto cleanup;
}
@@ -169,7 +165,7 @@ static int check_syncdbs(alpm_list_t *dbnames) {
cleanup:
alpm_list_free(syncpkglist);
- return(ret);
+ return ret;
}
static void usage(void) {
@@ -184,7 +180,8 @@ static void usage(void) {
int main(int argc, char *argv[])
{
int ret = 0;
- char *dbpath = DBPATH;
+ enum _pmerrno_t err;
+ const char *dbpath = DBPATH;
int a = 1;
alpm_list_t *dbnames = NULL;
@@ -204,18 +201,14 @@ int main(int argc, char *argv[])
a++;
}
- if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
+ handle = alpm_initialize(ROOTDIR, dbpath, &err);
+ if(!handle) {
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
+ return EXIT_FAILURE;
}
/* let us get log messages from libalpm */
- alpm_option_set_logcb(output_cb);
-
- if(alpm_option_set_dbpath(dbpath) != 0) {
- fprintf(stderr, "cannot set dbpath: %s\n", alpm_strerrorlast());
- return(EXIT_FAILURE);
- }
+ alpm_option_set_logcb(handle, output_cb);
if(!dbnames) {
ret = check_localdb();