summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/aurblup/aurblup.c84
1 files changed, 46 insertions, 38 deletions
diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c
index 6a67d68d..32365548 100644
--- a/scripts/aurblup/aurblup.c
+++ b/scripts/aurblup/aurblup.c
@@ -11,7 +11,7 @@
#include "config.h"
-#define alpm_die(...) die(__VA_ARGS__, alpm_strerrorlast());
+#define alpm_die(...) die(__VA_ARGS__, alpm_strerror(alpm_errno(handle)));
#define mysql_die(...) die(__VA_ARGS__, mysql_error(c));
static void die(const char *, ...);
@@ -34,6 +34,8 @@ static char *mysql_db = NULL;
static MYSQL *c;
+static alpm_handle_t *handle;
+
static void
die(const char *format, ...)
{
@@ -52,12 +54,13 @@ static alpm_list_t *
pkglist_append(alpm_list_t *pkglist, const char *pkgname)
{
int len = strcspn(pkgname, "<=>");
- if (!len) len = strlen(pkgname);
+ if (!len)
+ len = strlen(pkgname);
char *s = malloc(len + 1);
strncpy(s, pkgname, len);
- s[len] = 0;
+ s[len] = '\0';
if (alpm_list_find_str(pkglist, s))
free(s);
@@ -74,7 +77,7 @@ blacklist_get_pkglist()
MYSQL_ROW row;
alpm_list_t *pkglist = NULL;
- if (mysql_query(c, "SELECT Name FROM PackageBlacklist;"))
+ if (mysql_query(c, "SELECT Name FROM PackageBlacklist"))
mysql_die("failed to read blacklist from MySQL database: %s\n");
if (!(res = mysql_store_result(c)))
@@ -96,7 +99,7 @@ blacklist_add(const char *name)
mysql_real_escape_string(c, esc, name, strlen(name));
snprintf(query, 1024, "INSERT INTO PackageBlacklist (Name) "
- "VALUES ('%s');", esc);
+ "VALUES ('%s')", esc);
free(esc);
if (mysql_query(c, query))
@@ -110,7 +113,7 @@ blacklist_remove(const char *name)
char query[1024];
mysql_real_escape_string(c, esc, name, strlen(name));
- snprintf(query, 1024, "DELETE FROM PackageBlacklist WHERE Name = '%s';", esc);
+ snprintf(query, 1024, "DELETE FROM PackageBlacklist WHERE Name = '%s'", esc);
free(esc);
if (mysql_query(c, query))
@@ -125,16 +128,16 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new)
pkgs_add = alpm_list_diff(pkgs_new, pkgs_cur, (alpm_list_fn_cmp)strcmp);
pkgs_rem = alpm_list_diff(pkgs_cur, pkgs_new, (alpm_list_fn_cmp)strcmp);
- if (mysql_query(c, "START TRANSACTION;"))
+ if (mysql_query(c, "START TRANSACTION"))
mysql_die("failed to start MySQL transaction: %s\n");
for (p = pkgs_add; p; p = alpm_list_next(p))
- blacklist_add(alpm_list_getdata(p));
+ blacklist_add(p->data);
for (p = pkgs_rem; p; p = alpm_list_next(p))
- blacklist_remove(alpm_list_getdata(p));
+ blacklist_remove(p->data);
- if (mysql_query(c, "COMMIT;"))
+ if (mysql_query(c, "COMMIT"))
mysql_die("failed to commit MySQL transaction: %s\n");
alpm_list_free(pkgs_add);
@@ -148,25 +151,29 @@ dblist_get_pkglist(alpm_list_t *dblist)
alpm_list_t *pkglist = NULL;
for (d = dblist; d; d = alpm_list_next(d)) {
- pmdb_t *db = alpm_list_getdata(d);
+ alpm_db_t *db = d->data;
- if (alpm_trans_init(0, NULL, NULL, NULL))
+ if (alpm_trans_init(handle, 0))
alpm_die("failed to initialize ALPM transaction: %s\n");
if (alpm_db_update(0, db) < 0)
alpm_die("failed to update ALPM database: %s\n");
- if (alpm_trans_release())
+ if (alpm_trans_release(handle))
alpm_die("failed to release ALPM transaction: %s\n");
for (p = alpm_db_get_pkgcache(db); p; p = alpm_list_next(p)) {
- pmpkg_t *pkg = alpm_list_getdata(p);
+ alpm_pkg_t *pkg = p->data;
pkglist = pkglist_append(pkglist, alpm_pkg_get_name(pkg));
- for (q = alpm_pkg_get_provides(pkg); q; q = alpm_list_next(q))
- pkglist = pkglist_append(pkglist, alpm_list_getdata(q));
+ for (q = alpm_pkg_get_provides(pkg); q; q = alpm_list_next(q)) {
+ alpm_depend_t *provide = q->data;
+ pkglist = pkglist_append(pkglist, provide->name);
+ }
- for (q = alpm_pkg_get_replaces(pkg); q; q = alpm_list_next(q))
- pkglist = pkglist_append(pkglist, alpm_list_getdata(q));
+ for (q = alpm_pkg_get_replaces(pkg); q; q = alpm_list_next(q)) {
+ alpm_depend_t *replace = q->data;
+ pkglist = pkglist_append(pkglist, replace->name);
+ }
}
}
@@ -181,20 +188,20 @@ dblist_create(void)
int i;
for (i = 0; i < sizeof(alpm_repos) / sizeof(char *); i++) {
- if (!alpm_db_register_sync(alpm_repos[i]))
+ if (!alpm_db_register_sync(handle, alpm_repos[i], 0))
alpm_die("failed to register sync db \"%s\": %s\n", alpm_repos[i]);
}
- if (!(dblist = alpm_option_get_syncdbs()))
+ if (!(dblist = alpm_option_get_syncdbs(handle)))
alpm_die("failed to get sync DBs: %s\n");
for (d = dblist; d; d = alpm_list_next(d)) {
- pmdb_t *db = alpm_list_getdata(d);
+ alpm_db_t *db = d->data;
char server[1024];
snprintf(server, 1024, ALPM_MIRROR, alpm_db_get_name(db));
- if (alpm_db_setserver(db, server))
+ if (alpm_db_add_server(db, server))
alpm_die("failed to set server \"%s\": %s\n", server);
}
@@ -217,10 +224,14 @@ read_config(const char *fn)
t = &mysql_host;
u = &mysql_socket;
}
- else if (strstr(line, CONFIG_KEY_USER)) t = &mysql_user;
- else if (strstr(line, CONFIG_KEY_PASSWD)) t = &mysql_passwd;
- else if (strstr(line, CONFIG_KEY_DB)) t = &mysql_db;
- else t = NULL;
+ else if (strstr(line, CONFIG_KEY_USER))
+ t = &mysql_user;
+ else if (strstr(line, CONFIG_KEY_PASSWD))
+ t = &mysql_passwd;
+ else if (strstr(line, CONFIG_KEY_DB))
+ t = &mysql_db;
+ else
+ t = NULL;
if (t) {
strtok(line, "\"");
@@ -261,6 +272,7 @@ read_config(const char *fn)
static void
init(void)
{
+ enum _alpm_errno_t alpm_err;
if (mysql_library_init(0, NULL, NULL))
mysql_die("could not initialize MySQL library: %s\n");
if (!(c = mysql_init(NULL)))
@@ -269,24 +281,20 @@ init(void)
mysql_db, 0, mysql_socket, 0))
mysql_die("failed to initiate MySQL connection to %s: %s\n", mysql_host);
- if (alpm_initialize())
- alpm_die("failed to initialize ALPM: %s\n");
- if (alpm_option_set_root("/"))
- alpm_die("failed to set ALPM root: %s\n");
- if (alpm_option_set_dbpath(ALPM_DBPATH))
- alpm_die("failed to set ALPM database path: %s\n");
+ if ((handle = alpm_initialize("/", ALPM_DBPATH, &alpm_err)) == NULL)
+ die("failed to initialize ALPM: %s\n", alpm_strerror(alpm_err));
}
static void
cleanup(void)
{
- if (mysql_host) free(mysql_host);
- if (mysql_socket) free(mysql_socket);
- if (mysql_user) free(mysql_user);
- if (mysql_passwd) free(mysql_passwd);
- if (mysql_db) free(mysql_db);
+ free(mysql_host);
+ free(mysql_socket);
+ free(mysql_user);
+ free(mysql_passwd);
+ free(mysql_db);
- alpm_release();
+ alpm_release(handle);
mysql_close(c);
mysql_library_end();
}