index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | src/util/cleanupdelta.c | 20 | ||||
-rw-r--r-- | src/util/pactree.c | 47 | ||||
-rw-r--r-- | src/util/testdb.c | 36 | ||||
-rw-r--r-- | src/util/testpkg.c | 20 |
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index ae36d2a2..98291706 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -29,9 +29,11 @@ #define BASENAME "cleanupdelta" +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); @@ -73,10 +75,10 @@ static void checkdbs(const char *dbpath, alpm_list_t *dbnames) { for(i = dbnames; i; i = alpm_list_next(i)) { char *dbname = alpm_list_getdata(i); snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname); - db = alpm_db_register_sync(dbname); + db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); return; } checkpkgs(alpm_db_get_pkgcache(db)); @@ -94,6 +96,7 @@ static void usage(void) { int main(int argc, char *argv[]) { const char *dbpath = DBPATH; + enum _pmerrno_t err; int a = 1; alpm_list_t *dbnames = NULL; @@ -117,15 +120,14 @@ int main(int argc, char *argv[]) usage(); } - if(alpm_initialize() == -1) { - fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); + handle = alpm_initialize(ROOTDIR, dbpath, &err); + if(!handle) { + fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err)); return 1; } /* let us get log messages from libalpm */ - alpm_option_set_logcb(output_cb); - - alpm_option_set_dbpath(dbpath); + alpm_option_set_logcb(handle, output_cb); checkdbs(dbpath,dbnames); alpm_list_free(dbnames); diff --git a/src/util/pactree.c b/src/util/pactree.c index e9a2816e..1dee61bf 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -74,6 +74,7 @@ static struct color_choices no_color = { }; /* globals */ +pmhandle_t *handle = NULL; pmdb_t *db_local; alpm_list_t *walked = NULL; alpm_list_t *provisions = NULL; @@ -87,33 +88,6 @@ int reverse = 0; int unique = 0; const char *dbpath = DBPATH; -static int alpm_local_init(void) -{ - int ret; - - ret = alpm_initialize(); - if(ret != 0) { - return ret; - } - - ret = alpm_option_set_root(ROOTDIR); - if(ret != 0) { - return ret; - } - - ret = alpm_option_set_dbpath(dbpath); - if(ret != 0) { - return ret; - } - - db_local = alpm_option_get_localdb(); - if(!db_local) { - return 1; - } - - return 0; -} - static int parse_options(int argc, char *argv[]) { int opt, option_index = 0; @@ -196,7 +170,7 @@ static void cleanup(void) { alpm_list_free(walked); alpm_list_free(provisions); - alpm_release(); + alpm_release(handle); } /* pkg provides provision */ @@ -340,22 +314,27 @@ static void walk_deps(pmpkg_t *pkg, int depth) int main(int argc, char *argv[]) { - int ret; + int ret = 0; + enum _pmerrno_t err; const char *target_name; pmpkg_t *pkg; - ret = parse_options(argc, argv); - if(ret != 0) { + if(parse_options(argc, argv) != 0) { usage(); + ret = 1; goto finish; } - ret = alpm_local_init(); - if(ret != 0) { - fprintf(stderr, "error: cannot initialize alpm: %s\n", alpm_strerrorlast()); + handle = alpm_initialize(ROOTDIR, dbpath, &err); + if(!handle) { + fprintf(stderr, "error: cannot initialize alpm: %s\n", + alpm_strerror(err)); + ret = 1; goto finish; } + db_local = alpm_option_get_localdb(handle); + /* we only care about the first non option arg for walking */ target_name = argv[optind]; diff --git a/src/util/testdb.c b/src/util/testdb.c index d8a2fb4d..0bd78202 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,7 +61,7 @@ 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)); @@ -96,7 +98,7 @@ 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); @@ -115,7 +117,7 @@ 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), @@ -136,12 +138,7 @@ static int check_localdb(void) { 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); @@ -155,10 +152,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); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); ret = 1; goto cleanup; } @@ -184,6 +181,7 @@ static void usage(void) { int main(int argc, char *argv[]) { int ret = 0; + enum _pmerrno_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()); + 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(); diff --git a/src/util/testpkg.c b/src/util/testpkg.c index ad6ec30b..c6f02e34 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -40,6 +40,8 @@ static void output_cb(pmloglevel_t level, const char *fmt, va_list args) int main(int argc, char *argv[]) { int retval = 1; /* default = false */ + pmhandle_t *handle; + enum _pmerrno_t err; pmpkg_t *pkg = NULL; if(argc != 2) { @@ -47,17 +49,19 @@ int main(int argc, char *argv[]) return 1; } - if(alpm_initialize() == -1) { - fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast()); + handle = alpm_initialize(ROOTDIR, DBPATH, &err); + if(!handle) { + fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err)); return 1; } /* let us get log messages from libalpm */ - alpm_option_set_logcb(output_cb); + alpm_option_set_logcb(handle, output_cb); - if(alpm_pkg_load(argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 + if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 || pkg == NULL) { - switch(pm_errno) { + enum _pmerrno_t err = alpm_errno(handle); + switch(err) { case PM_ERR_PKG_OPEN: printf("Cannot open the given file.\n"); break; @@ -66,7 +70,7 @@ int main(int argc, char *argv[]) printf("Package is invalid.\n"); break; default: - printf("libalpm error: %s\n", alpm_strerrorlast()); + printf("libalpm error: %s\n", alpm_strerror(err)); break; } retval = 1; @@ -76,8 +80,8 @@ int main(int argc, char *argv[]) retval = 0; } - if(alpm_release() == -1) { - fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast()); + if(alpm_release(handle) == -1) { + fprintf(stderr, "error releasing alpm\n"); } return retval; |