Skip to content
Browse files

Updated to use libalpm 7

Signed-off-by: Pang Yan Han <pangyanhan@gmail.com>
  • Loading branch information...
1 parent bf66292 commit 2c2c8ac7b3e075e55ba46f5b2a262068f1049466 @yanhan committed Jan 24, 2012
Showing with 102 additions and 63 deletions.
  1. +4 −11 conf.c
  2. +2 −0 conf.h
  3. +17 −3 environment.c
  4. +2 −0 environment.h
  5. +4 −0 error.c
  6. +7 −6 hashdb.c
  7. +1 −1 hashdb.h
  8. +15 −15 package.c
  9. +2 −2 package.h
  10. +2 −5 powaur.c
  11. +2 −0 powaur.h
  12. +35 −10 query.c
  13. +8 −8 sync.c
  14. +1 −2 util.c
View
15 conf.c
@@ -15,11 +15,12 @@
struct config_t *config_init(void)
{
struct config_t *conf;
+ enum _alpm_errno_t err;
+
conf = xcalloc(1, sizeof(struct config_t));
conf->op = PW_OP_MAIN;
conf->loglvl = PW_LOG_NORM | PW_LOG_INFO | PW_LOG_WARNING | PW_LOG_ERROR;
conf->color = 1;
-
return conf;
}
@@ -341,20 +342,12 @@ int parse_pmconfig(void)
goto cleanup;
} else {
/* Must be a repository
- * We just add the repository for now
+ * Add repository name to pacman_syncdbs list
*/
in_options = 0;
pw_printf(PW_LOG_DEBUG, "%sParsing Repo [%s]\n", TAB, line);
-
- if (!alpm_db_register_sync(line)) {
- pw_printf(PW_LOG_ERROR, "%sFailed to register %s db\n",
- TAB, line);
- goto cleanup;
- }
-
- pw_printf(PW_LOG_DEBUG, "%sRegistering sync database '%s'\n",
- TAB, line);
+ pacman_syncdbs = alpm_list_add(pacman_syncdbs, xstrdup(line));
}
} else if (in_options) {
View
2 conf.h
@@ -2,6 +2,7 @@
#define POWAUR_CONF_H
#include <stdio.h>
+#include <alpm.h>
#include "powaur.h"
@@ -12,6 +13,7 @@ struct config_t {
char *target_dir;
unsigned short maxthreads;
unsigned short color;
+ alpm_handle_t *handle;
unsigned help : 1;
unsigned version : 1;
View
20 environment.c
@@ -5,6 +5,7 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <alpm.h>
#include <alpm_list.h>
#include "conf.h"
@@ -25,6 +26,7 @@ struct colorstrs color;
char *pacman_rootdir;
char *pacman_dbpath;
alpm_list_t *pacman_cachedirs;
+alpm_list_t *pacman_syncdbs;
int setup_config(void)
{
@@ -117,6 +119,8 @@ static void colors_cleanup(void)
*/
static int setup_pacman_environment(int reload)
{
+ enum _alpm_errno_t err;
+ alpm_list_t *i;
if (reload) {
pw_printf(PW_LOG_DEBUG, "Reloading pacman configuration\n");
pacman_cachedirs = NULL;
@@ -141,9 +145,18 @@ static int setup_pacman_environment(int reload)
xstrdup(PACMAN_DEF_CACHEDIR));
}
- alpm_option_set_root(pacman_rootdir);
- alpm_option_set_dbpath(pacman_dbpath);
- alpm_option_set_cachedirs(pacman_cachedirs);
+ alpm_option_set_cachedirs(config->handle, pacman_cachedirs);
+ config->handle = alpm_initialize(pacman_rootdir, pacman_dbpath, &err);
+ if (!config->handle) {
+ return error(PW_ERR_INIT_ALPM_HANDLE);
+ }
+ /* Register sync dbs */
+ for (i = pacman_syncdbs; i; i = i->next) {
+ if (!alpm_db_register_sync(config->handle, (const char *) i->data,
+ ALPM_SIG_USE_DEFAULT)) {
+ return error(PW_ERR_INIT_ALPM_REGISTER_SYNC);
+ }
+ }
return 0;
}
@@ -260,4 +273,5 @@ void cleanup_environment(void)
/* No need to free pacman_cachedirs */
free(pacman_rootdir);
free(pacman_dbpath);
+ FREELIST(pacman_syncdbs);
}
View
2 environment.h
@@ -1,6 +1,7 @@
#ifndef POWAUR_ENV_H
#define POWAUR_ENV_H
+#include <alpm.h>
#include <alpm_list.h>
#include "conf.h"
@@ -124,6 +125,7 @@ extern int powaur_maxthreads;
extern char *pacman_rootdir;
extern char *pacman_dbpath;
extern alpm_list_t *pacman_cachedirs;
+extern alpm_list_t *pacman_syncdbs;
int setup_environment(void);
void colors_setup(void);
View
4 error.c
@@ -58,6 +58,10 @@ const char *pw_strerror(enum _pw_errno_t err)
switch (err) {
case PW_ERR_INIT_CONFIG:
return "config initialization failed";
+ case PW_ERR_INIT_ALPM_HANDLE:
+ return "Failed to initialize alpm handle";
+ case PW_ERR_INIT_ALPM_REGISTER_SYNC:
+ return "Failed to register alpm database";
case PW_ERR_INIT_ENV:
return "Setup environment failed";
case PW_ERR_INIT_HANDLE:
View
13 hashdb.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <alpm.h>
+#include "environment.h"
#include "hashdb.h"
#include "hash.h"
#include "memlist.h"
@@ -61,7 +62,7 @@ void hashdb_free(struct pw_hashdb *hashdb)
}
/* hashes packages and their provides
- * @param dbcache list of pmpkg_t * to be hashed
+ * @param dbcache list of alpm_pkg_t * to be hashed
* @param htable hash table hashing struct pkgpair
* @param provides hashbst used to hash provides
* @param hashdb hash database
@@ -70,7 +71,7 @@ static void hash_packages(alpm_list_t *dbcache, struct hash_table *htable,
struct hashbst *provides, struct pw_hashdb *hashdb)
{
alpm_list_t *i, *k;
- pmpkg_t *pkg;
+ alpm_pkg_t *pkg;
struct pkgpair pkgpair;
void *memlist_ptr;
@@ -104,8 +105,8 @@ static void hash_packages(alpm_list_t *dbcache, struct hash_table *htable,
struct pw_hashdb *build_hashdb(void)
{
alpm_list_t *i, *k, *syncdbs, *dbcache;
- pmdb_t *db;
- pmpkg_t *pkg;
+ alpm_db_t *db;
+ alpm_pkg_t *pkg;
char buf[1024];
const char *pkgname;
@@ -115,7 +116,7 @@ struct pw_hashdb *build_hashdb(void)
struct pw_hashdb *hashdb = hashdb_new();
- db = alpm_option_get_localdb();
+ db = alpm_option_get_localdb(config->handle);
if (!db) {
error(PW_ERR_LOCALDB_NULL);
goto error_cleanup;
@@ -129,7 +130,7 @@ struct pw_hashdb *build_hashdb(void)
hash_packages(dbcache, hashdb->local, hashdb->local_provides, hashdb);
- syncdbs = alpm_option_get_syncdbs();
+ syncdbs = alpm_option_get_syncdbs(config->handle);
for (i = syncdbs; i; i = i->next) {
db = i->data;
hash_packages(alpm_db_get_pkgcache(db), hashdb->sync, hashdb->sync_provides,
View
2 hashdb.h
@@ -45,7 +45,7 @@ struct pw_hashdb *hashdb_new(void);
void hashdb_free(struct pw_hashdb *hashdb);
struct pw_hashdb *build_hashdb(void);
-/* Used for hashing, pkg can be pmpkg_t or aurpkg_t */
+/* Used for hashing, pkg can be alpm_pkg_t or aurpkg_t */
struct pkgpair {
const char *pkgname;
void *pkg;
View
30 package.c
@@ -248,7 +248,7 @@ alpm_list_t *resolve_dependencies(struct pw_hashdb *hashdb, alpm_list_t *package
alpm_list_t *i, *k, *m, *q;
alpm_list_t *deps, *newdeps;
- pmpkg_t *pkg;
+ alpm_pkg_t *pkg;
struct pkgpair pkgpair;
struct pkgpair *pkgpair_ptr;
char pkgbuild[PATH_MAX];
@@ -347,7 +347,7 @@ const char *which_db(alpm_list_t *sdbs, const char *pkgname, alpm_list_t **grp)
{
const char *repo = NULL;
alpm_list_t *i, *k;
- pmpkg_t *spkg;
+ alpm_pkg_t *spkg;
for (i = sdbs; i && !repo; i = i->next) {
for (k = alpm_db_get_pkgcache(i->data); k; k = k->next) {
@@ -371,7 +371,7 @@ const char *which_db(alpm_list_t *sdbs, const char *pkgname, alpm_list_t **grp)
}
/* For plain -Q, -Qs, -Ss */
-void print_pkg_pretty(alpm_list_t *sdbs, pmpkg_t *pkg, enum dumplvl_t lvl)
+void print_pkg_pretty(alpm_list_t *sdbs, alpm_pkg_t *pkg, enum dumplvl_t lvl)
{
alpm_list_t *grp = NULL;
const char *repo;
@@ -399,20 +399,20 @@ int pacman_db_dump(enum pkgfrom_t from, enum dumplvl_t lvl)
alpm_list_t *i, *j, *dbs, *syncdbs;
const char *repo;
- pmdb_t *localdb, *db;
- pmpkg_t *pkg;
- pmdepend_t *dep;
+ alpm_db_t *localdb, *db;
+ alpm_pkg_t *pkg;
+ alpm_depend_t *dep;
switch (lvl) {
case DUMP_Q:
case DUMP_Q_SEARCH:
case DUMP_Q_INFO:
- localdb = alpm_option_get_localdb();
- syncdbs = alpm_option_get_syncdbs();
+ localdb = alpm_option_get_localdb(config->handle);
+ syncdbs = alpm_option_get_syncdbs(config->handle);
break;
case DUMP_S_SEARCH:
case DUMP_S_INFO:
- dbs = alpm_option_get_syncdbs();
+ dbs = alpm_option_get_syncdbs(config->handle);
break;
}
@@ -488,14 +488,14 @@ static void humanize_size(off_t sz, const char *prefix)
units[ptr]);
}
-void pacman_pkgdump(pmpkg_t *pkg, enum pkgfrom_t from)
+void pacman_pkgdump(alpm_pkg_t *pkg, enum pkgfrom_t from)
{
static const char *datefmt = "%a %d %b %Y %I:%M:%S %p %Z";
alpm_list_t *i, *results = NULL;
- pmdb_t *db;
- pmdepend_t *dep;
- pmpkgreason_t reason;
+ alpm_db_t *db;
+ alpm_depend_t *dep;
+ alpm_pkgreason_t reason;
int has_script;
time_t inst_time;
@@ -576,10 +576,10 @@ void pacman_pkgdump(pmpkg_t *pkg, enum pkgfrom_t from)
printf("%s%s%s ", color.bold, REASON, color.nocolor);
switch (reason) {
- case PM_PKG_REASON_EXPLICIT:
+ case ALPM_PKG_REASON_EXPLICIT:
printf("Explicitly installed");
break;
- case PM_PKG_REASON_DEPEND:
+ case ALPM_PKG_REASON_DEPEND:
printf("Installed as a dependency for another package");
break;
default:
View
4 package.h
@@ -50,12 +50,12 @@ alpm_list_t *resolve_dependencies(struct pw_hashdb *hashdb, alpm_list_t *package
const char *which_db(alpm_list_t *sdbs, const char *pkgname, alpm_list_t **grp);
/* Prints pretty pkg, for plain -Q, -Qs, -Ss */
-void print_pkg_pretty(alpm_list_t *sdbs, pmpkg_t *pkg, enum dumplvl_t lvl);
+void print_pkg_pretty(alpm_list_t *sdbs, alpm_pkg_t *pkg, enum dumplvl_t lvl);
/* Dumps entire pacman database, for -Q, -Qi, -Qs, -Si, -Ss w/o targets */
int pacman_db_dump(enum pkgfrom_t from, enum dumplvl_t lvl);
/* Dumps a pacman package, for -Qi and -Si */
-void pacman_pkgdump(pmpkg_t *pkg, enum pkgfrom_t from);
+void pacman_pkgdump(alpm_pkg_t *pkg, enum pkgfrom_t from);
#endif
View
7 powaur.c
@@ -27,7 +27,7 @@ static int powaur_cleanup(int ret)
curl_cleanup();
_pwhandle_free(pwhandle);
cleanup_environment();
- alpm_release();
+ alpm_release(config->handle);
exit(ret);
}
@@ -36,10 +36,7 @@ static int powaur_init(void)
{
struct stat st;
int ret = 0;
-
- if (alpm_initialize() == -1) {
- return -1;
- }
+ enum _alpm_errno_t err;
if (setup_environment()) {
return error(PW_ERR_INIT_ENV);
View
2 powaur.h
@@ -47,6 +47,8 @@ enum _pw_errno_t {
/* Initialization errors */
PW_ERR_INIT_CONFIG,
+ PW_ERR_INIT_ALPM_HANDLE,
+ PW_ERR_INIT_ALPM_REGISTER_SYNC,
PW_ERR_INIT_ENV,
PW_ERR_INIT_HANDLE,
PW_ERR_INIT_DIR,
View
45 query.c
@@ -1,3 +1,4 @@
+#include <string.h>
#include <alpm.h>
#include "conf.h"
@@ -10,12 +11,32 @@
#include "query.h"
#include "util.h"
+/* Removes version information from a package string like "glibc>=2.12" */
+static void chompversion(char *str)
+{
+ char *p;
+ p = strchr(str, '>');
+ if (p) {
+ *p = 0;
+ return;
+ }
+ p = strchr(str, '<');
+ if (p) {
+ *p = 0;
+ return;
+ }
+ p = strchr(str, '=');
+ if (p) {
+ *p = 0;
+ }
+}
+
/* -Qi */
-static int query_info(pmdb_t *localdb, alpm_list_t *targets)
+static int query_info(alpm_db_t *localdb, alpm_list_t *targets)
{
int ret, hits, found, pkgcount;
alpm_list_t *i, *k, *dbcache;
- pmpkg_t *pkg;
+ alpm_pkg_t *pkg;
ret = pkgcount = hits = found = 0;
dbcache = alpm_db_get_pkgcache(localdb);
@@ -49,16 +70,16 @@ static int query_info(pmdb_t *localdb, alpm_list_t *targets)
}
/* -Qs, only 1 target for now */
-static int query_search(pmdb_t *localdb, const char *pkgname)
+static int query_search(alpm_db_t *localdb, const char *pkgname)
{
int ret, found;
const char *repo;
alpm_list_t *i, *k, *dbcache, *groups;
alpm_list_t *syncdbs;
- pmpkg_t *pkg;
+ alpm_pkg_t *pkg;
dbcache = alpm_db_get_pkgcache(localdb);
- syncdbs = alpm_option_get_syncdbs();
+ syncdbs = alpm_option_get_syncdbs(config->handle);
for (k = dbcache; k; k = k->next) {
pkg = k->data;
@@ -80,14 +101,14 @@ static int query_search(pmdb_t *localdb, const char *pkgname)
int powaur_query(alpm_list_t *targets)
{
- pmdb_t *localdb = alpm_option_get_localdb();
+ alpm_db_t *localdb = alpm_option_get_localdb(config->handle);
if (!localdb) {
return error(PW_ERR_INIT_LOCALDB);
}
alpm_list_t *dblist = NULL;
alpm_list_t *i, *j, *dbcache;
- pmpkg_t *pkg, *spkg;
+ alpm_pkg_t *pkg, *spkg;
int ret = 0, found;
/* -i and -s conflicting options */
@@ -127,7 +148,7 @@ int powaur_query(alpm_list_t *targets)
ret = query_search(localdb, targets->data);
} else {
/* Plain -Q */
- alpm_list_t *sdbs = alpm_option_get_syncdbs();
+ alpm_list_t *sdbs = alpm_option_get_syncdbs(config->handle);
dbcache = alpm_db_get_pkgcache(localdb);
for (i = targets; i; i = i->next) {
@@ -290,6 +311,7 @@ static int crawl_resolve(CURL *curl, struct pw_hashdb *hashdb, struct pkgpair *c
const char *cache_result;
const char *depname, *final_pkgname;
char cwd[PATH_MAX];
+ char buf[PATH_MAX];
/* Normalize package before doing anything else */
final_pkgname = normalize_package(curl, hashdb, curpkg->pkgname, resolve_lvl);
@@ -328,8 +350,11 @@ static int crawl_resolve(CURL *curl, struct pw_hashdb *hashdb, struct pkgpair *c
depmod_list = alpm_pkg_get_depends(pkgpair->pkg);
for (i = depmod_list; i; i = i->next) {
- depname = normalize_package(curl, hashdb, alpm_dep_get_name(i->data),
- resolve_lvl);
+ char *s = alpm_dep_compute_string(i->data);
+ strncpy(buf, s, sizeof(buf));
+ free(s);
+ chompversion(buf);
+ depname = normalize_package(curl, hashdb, buf, resolve_lvl);
/* Possibility of normalize_package fail due to AUR download failing */
if (!depname) {
alpm_list_free(deps);
View
16 sync.c
@@ -180,8 +180,8 @@ static int install_single_package(char *pkgname)
static int sync_search(CURL *curl, alpm_list_t *targets)
{
alpm_list_t *i, *j, *search_results;
- pmdb_t *db;
- pmpkg_t *spkg;
+ alpm_db_t *db;
+ alpm_pkg_t *spkg;
struct aurpkg_t *pkg;
size_t listsz;
@@ -216,11 +216,11 @@ static int sync_search(CURL *curl, alpm_list_t *targets)
}
/* -Si, search inside sync dbs */
-static pmpkg_t *search_syncdbs(alpm_list_t *dbs, const char *pkgname)
+static alpm_pkg_t *search_syncdbs(alpm_list_t *dbs, const char *pkgname)
{
alpm_list_t *i, *j;
- pmdb_t *sdb;
- pmpkg_t *spkg;
+ alpm_db_t *sdb;
+ alpm_pkg_t *spkg;
for (i = dbs; i; i = i->next) {
sdb = i->data;
@@ -242,8 +242,8 @@ static int sync_info(CURL *curl, alpm_list_t *targets)
int found, ret, pkgcount;
alpm_list_t *i, *j, *results;
alpm_list_t *free_list = NULL;
- alpm_list_t *syncdbs = alpm_option_get_syncdbs();
- pmpkg_t *spkg;
+ alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle);
+ alpm_pkg_t *spkg;
char cwd[PATH_MAX];
char filename[PATH_MAX];
@@ -742,7 +742,7 @@ static int sync_targets(CURL *curl, alpm_list_t *targets)
struct pkgpair pkgpair;
struct pkgpair *pkgpair_ptr;
struct aurpkg_t *aurpkg;
- pmpkg_t *lpkg;
+ alpm_pkg_t *lpkg;
alpm_list_t *i;
alpm_list_t *reinstall, *new_packages, *upgrade, *downgrade, *not_aur;
alpm_list_t *aurpkg_list, *final_targets;
View
3 util.c
@@ -172,8 +172,7 @@ int extract_file(const char *filename)
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
- ret = archive_read_open_filename(archive, filename,
- ARCHIVE_DEFAULT_BYTES_PER_BLOCK);
+ ret = archive_read_open_filename(archive, filename, 16384);
if (ret != ARCHIVE_OK) {
return error(PW_ERR_ARCHIVE_OPEN);

0 comments on commit 2c2c8ac

Please sign in to comment.
Something went wrong with that request. Please try again.