Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/util/testdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/testdb.c')
-rw-r--r--src/util/testdb.c82
1 files changed, 38 insertions, 44 deletions
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 0436a23f..ee169df2 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -31,20 +31,22 @@
#define BASENAME "testdb"
+alpm_handle_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);
}
-static void output_cb(pmloglevel_t level, const char *fmt, va_list args)
+static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
{
if(strlen(fmt)) {
switch(level) {
- case PM_LOG_ERROR: printf("error: "); break;
- case PM_LOG_WARNING: printf("warning: "); break;
+ case ALPM_LOG_ERROR: printf("error: "); break;
+ case ALPM_LOG_WARNING: printf("warning: "); break;
default: return;
}
vprintf(fmt, args);
@@ -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),
+ alpm_depmissing_t *miss = alpm_list_getdata(i);
+ 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,50 +116,46 @@ 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));
+ alpm_conflict_t *conflict = alpm_list_getdata(i);
+ printf("%s conflicts with %s\n",
+ conflict->package1, conflict->package2);
ret++;
}
FREELIST(data);
- return(ret);
+ return ret;
}
static int check_localdb(void) {
int ret = 0;
- pmdb_t *db = NULL;
+ alpm_db_t *db = NULL;
alpm_list_t *pkglist;
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) {
int ret = 0;
- pmdb_t *db = NULL;
+ alpm_db_t *db = NULL;
alpm_list_t *i, *pkglist, *syncpkglist = NULL;
+ const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
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, level);
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 +166,7 @@ static int check_syncdbs(alpm_list_t *dbnames) {
cleanup:
alpm_list_free(syncpkglist);
- return(ret);
+ return ret;
}
static void usage(void) {
@@ -184,7 +181,8 @@ static void usage(void) {
int main(int argc, char *argv[])
{
int ret = 0;
- char *dbpath = DBPATH;
+ enum _alpm_errno_t err;
+ const char *dbpath = DBPATH;
int a = 1;
alpm_list_t *dbnames = NULL;
@@ -204,18 +202,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();