Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/callback.c32
-rw-r--r--src/pacman/conf.c403
-rw-r--r--src/pacman/conf.h16
-rw-r--r--src/pacman/database.c4
-rw-r--r--src/pacman/deptest.c3
-rw-r--r--src/pacman/package.c5
-rw-r--r--src/pacman/pacman.c74
-rw-r--r--src/pacman/query.c27
-rw-r--r--src/pacman/remove.c33
-rw-r--r--src/pacman/sync.c78
-rw-r--r--src/pacman/upgrade.c36
-rw-r--r--src/pacman/util.c103
-rw-r--r--src/pacman/util.h2
-rw-r--r--src/util/cleanupdelta.c20
-rw-r--r--src/util/pactree.c47
-rw-r--r--src/util/testdb.c36
-rw-r--r--src/util/testpkg.c20
17 files changed, 520 insertions, 419 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index d3dc7440..4ac3b56b 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -176,7 +176,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
}
break;
case PM_TRANS_EVT_ADD_DONE:
- alpm_logaction("installed %s (%s)\n",
+ alpm_logaction(config->handle, "installed %s (%s)\n",
alpm_pkg_get_name(data1),
alpm_pkg_get_version(data1));
display_optdepends(data1);
@@ -187,7 +187,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
}
break;
case PM_TRANS_EVT_REMOVE_DONE:
- alpm_logaction("removed %s (%s)\n",
+ alpm_logaction(config->handle, "removed %s (%s)\n",
alpm_pkg_get_name(data1),
alpm_pkg_get_version(data1));
break;
@@ -197,7 +197,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2)
}
break;
case PM_TRANS_EVT_UPGRADE_DONE:
- alpm_logaction("upgraded %s (%s -> %s)\n",
+ alpm_logaction(config->handle, "upgraded %s (%s -> %s)\n",
(char *)alpm_pkg_get_name(data1),
(char *)alpm_pkg_get_version(data2),
(char *)alpm_pkg_get_version(data1));
@@ -256,8 +256,12 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
{
switch(event) {
case PM_TRANS_CONV_INSTALL_IGNOREPKG:
- *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
- alpm_pkg_get_name(data1));
+ if(!config->op_s_downloadonly) {
+ *response = yesno(_(":: %s is in IgnorePkg/IgnoreGroup. Install anyway?"),
+ alpm_pkg_get_name(data1));
+ } else {
+ *response = 1;
+ }
break;
case PM_TRANS_CONV_REPLACE_PKG:
*response = yesno(_(":: Replace %s with %s/%s?"),
@@ -351,7 +355,9 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
int len, wclen, wcwid, padwid;
wchar_t *wcstr;
- if(config->noprogressbar) {
+ const int cols = getcols(0);
+
+ if(config->noprogressbar || cols == 0) {
return;
}
@@ -397,7 +403,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
return;
}
- infolen = getcols() * 6 / 10;
+ infolen = cols * 6 / 10;
if(infolen < 50) {
infolen = 50;
}
@@ -454,7 +460,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
free(wcstr);
/* call refactored fill progress function */
- fill_progress(percent, percent, getcols() - infolen);
+ fill_progress(percent, percent, cols - infolen);
if(percent == 100) {
alpm_list_t *i = NULL;
@@ -498,7 +504,9 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
const char *rate_label, *xfered_label;
int file_percent = 0, total_percent = 0;
- if(config->noprogressbar || file_total == -1) {
+ const int cols = getcols(0);
+
+ if(config->noprogressbar || cols == 0 || file_total == -1) {
if(file_xfered == 0) {
printf(_("downloading %s...\n"), filename);
fflush(stdout);
@@ -506,7 +514,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
return;
}
- infolen = getcols() * 6 / 10;
+ infolen = cols * 6 / 10;
if(infolen < 50) {
infolen = 50;
}
@@ -639,9 +647,9 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
free(wcfname);
if(totaldownload) {
- fill_progress(file_percent, total_percent, getcols() - infolen);
+ fill_progress(file_percent, total_percent, cols - infolen);
} else {
- fill_progress(file_percent, file_percent, getcols() - infolen);
+ fill_progress(file_percent, file_percent, cols - infolen);
}
return;
}
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 370ec510..a5bc1485 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -34,6 +34,7 @@
#include "conf.h"
#include "util.h"
#include "pacman.h"
+#include "callback.h"
/* global config variable */
config_t *config = NULL;
@@ -50,8 +51,8 @@ config_t *config_new(void)
/* defaults which may get overridden later */
newconfig->op = PM_OP_MAIN;
newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
- /* CONFFILE is defined at compile-time */
newconfig->configfile = strdup(CONFFILE);
+ newconfig->sigverify = PM_PGP_VERIFY_UNKNOWN;
return newconfig;
}
@@ -64,12 +65,19 @@ int config_free(config_t *oldconfig)
FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->syncfirst);
+ FREELIST(oldconfig->ignorepkg);
+ FREELIST(oldconfig->ignoregrp);
+ FREELIST(oldconfig->noupgrade);
+ FREELIST(oldconfig->noextract);
free(oldconfig->configfile);
free(oldconfig->rootdir);
free(oldconfig->dbpath);
free(oldconfig->logfile);
+ free(oldconfig->gpgdir);
+ FREELIST(oldconfig->cachedirs);
free(oldconfig->xfercommand);
free(oldconfig->print_format);
+ free(oldconfig->arch);
free(oldconfig);
oldconfig = NULL;
@@ -206,12 +214,12 @@ int config_set_arch(const char *arch)
if(strcmp(arch, "auto") == 0) {
struct utsname un;
uname(&un);
- pm_printf(PM_LOG_DEBUG, "config: Architecture: %s\n", un.machine);
- return alpm_option_set_arch(un.machine);
+ config->arch = strdup(un.machine);
} else {
- pm_printf(PM_LOG_DEBUG, "config: Architecture: %s\n", arch);
- return alpm_option_set_arch(arch);
+ config->arch = strdup(arch);
}
+ pm_printf(PM_LOG_DEBUG, "config: arch: %s\n", config->arch);
+ return 0;
}
static pgp_verify_t option_verifysig(const char *value)
@@ -230,27 +238,19 @@ static pgp_verify_t option_verifysig(const char *value)
return level;
}
-/* helper for being used with setrepeatingoption */
-static int option_add_holdpkg(const char *name) {
- config->holdpkg = alpm_list_add(config->holdpkg, strdup(name));
- return 0;
-}
-
-/* helper for being used with setrepeatingoption */
-static int option_add_syncfirst(const char *name) {
- config->syncfirst = alpm_list_add(config->syncfirst, strdup(name));
- return 0;
-}
-
-/* helper for being used with setrepeatingoption */
-static int option_add_cleanmethod(const char *value) {
- if(strcmp(value, "KeepInstalled") == 0) {
- config->cleanmethod |= PM_CLEAN_KEEPINST;
- } else if(strcmp(value, "KeepCurrent") == 0) {
- config->cleanmethod |= PM_CLEAN_KEEPCUR;
- } else {
- pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
- value);
+static int process_cleanmethods(alpm_list_t *values) {
+ alpm_list_t *i;
+ for(i = values; i; i = alpm_list_next(i)) {
+ const char *value = i->data;
+ if(strcmp(value, "KeepInstalled") == 0) {
+ config->cleanmethod |= PM_CLEAN_KEEPINST;
+ } else if(strcmp(value, "KeepCurrent") == 0) {
+ config->cleanmethod |= PM_CLEAN_KEEPCUR;
+ } else {
+ pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"),
+ value);
+ return 1;
+ }
}
return 0;
}
@@ -260,21 +260,21 @@ static int option_add_cleanmethod(const char *value) {
* the exact same thing and duplicated code.
* @param ptr a pointer to the start of the multiple options
* @param option the string (friendly) name of the option, used for messages
- * @param optionfunc a function pointer to an alpm_option_add_* function
+ * @param list the list to add the option to
*/
static void setrepeatingoption(char *ptr, const char *option,
- int (*optionfunc)(const char *))
+ alpm_list_t **list)
{
char *q;
while((q = strchr(ptr, ' '))) {
*q = '\0';
- (*optionfunc)(ptr);
+ *list = alpm_list_add(*list, strdup(ptr));
pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, ptr);
ptr = q;
ptr++;
}
- (*optionfunc)(ptr);
+ *list = alpm_list_add(*list, strdup(ptr));
pm_printf(PM_LOG_DEBUG, "config: %s: %s\n", option, ptr);
}
@@ -284,7 +284,7 @@ static int _parse_options(const char *key, char *value,
if(value == NULL) {
/* options without settings */
if(strcmp(key, "UseSyslog") == 0) {
- alpm_option_set_usesyslog(1);
+ config->usesyslog = 1;
pm_printf(PM_LOG_DEBUG, "config: usesyslog\n");
} else if(strcmp(key, "ILoveCandy") == 0) {
config->chomp = 1;
@@ -293,13 +293,13 @@ static int _parse_options(const char *key, char *value,
config->verbosepkglists = 1;
pm_printf(PM_LOG_DEBUG, "config: verbosepkglists\n");
} else if(strcmp(key, "UseDelta") == 0) {
- alpm_option_set_usedelta(1);
+ config->usedelta = 1;
pm_printf(PM_LOG_DEBUG, "config: usedelta\n");
} else if(strcmp(key, "TotalDownload") == 0) {
config->totaldownload = 1;
pm_printf(PM_LOG_DEBUG, "config: totaldownload\n");
} else if(strcmp(key, "CheckSpace") == 0) {
- alpm_option_set_checkspace(1);
+ config->checkspace = 1;
} else {
pm_printf(PM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
@@ -308,19 +308,21 @@ static int _parse_options(const char *key, char *value,
} else {
/* options with settings */
if(strcmp(key, "NoUpgrade") == 0) {
- setrepeatingoption(value, "NoUpgrade", alpm_option_add_noupgrade);
+ setrepeatingoption(value, "NoUpgrade", &(config->noupgrade));
} else if(strcmp(key, "NoExtract") == 0) {
- setrepeatingoption(value, "NoExtract", alpm_option_add_noextract);
+ setrepeatingoption(value, "NoExtract", &(config->noextract));
} else if(strcmp(key, "IgnorePkg") == 0) {
- setrepeatingoption(value, "IgnorePkg", alpm_option_add_ignorepkg);
+ setrepeatingoption(value, "IgnorePkg", &(config->ignorepkg));
} else if(strcmp(key, "IgnoreGroup") == 0) {
- setrepeatingoption(value, "IgnoreGroup", alpm_option_add_ignoregrp);
+ setrepeatingoption(value, "IgnoreGroup", &(config->ignoregrp));
} else if(strcmp(key, "HoldPkg") == 0) {
- setrepeatingoption(value, "HoldPkg", option_add_holdpkg);
+ setrepeatingoption(value, "HoldPkg", &(config->holdpkg));
} else if(strcmp(key, "SyncFirst") == 0) {
- setrepeatingoption(value, "SyncFirst", option_add_syncfirst);
+ setrepeatingoption(value, "SyncFirst", &(config->syncfirst));
+ } else if(strcmp(key, "CacheDir") == 0) {
+ setrepeatingoption(value, "CacheDir", &(config->cachedirs));
} else if(strcmp(key, "Architecture") == 0) {
- if(!alpm_option_get_arch()) {
+ if(!config->arch) {
config_set_arch(value);
}
} else if(strcmp(key, "DBPath") == 0) {
@@ -329,13 +331,6 @@ static int _parse_options(const char *key, char *value,
config->dbpath = strdup(value);
pm_printf(PM_LOG_DEBUG, "config: dbpath: %s\n", value);
}
- } else if(strcmp(key, "CacheDir") == 0) {
- if(alpm_option_add_cachedir(value) != 0) {
- pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
- value, alpm_strerrorlast());
- return 1;
- }
- pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", value);
} else if(strcmp(key, "RootDir") == 0) {
/* don't overwrite a path specified on the command line */
if(!config->rootdir) {
@@ -354,14 +349,19 @@ static int _parse_options(const char *key, char *value,
}
} else if(strcmp(key, "XferCommand") == 0) {
config->xfercommand = strdup(value);
- alpm_option_set_fetchcb(download_with_xfercommand);
pm_printf(PM_LOG_DEBUG, "config: xfercommand: %s\n", value);
} else if(strcmp(key, "CleanMethod") == 0) {
- setrepeatingoption(value, "CleanMethod", option_add_cleanmethod);
+ alpm_list_t *methods = NULL;
+ setrepeatingoption(value, "CleanMethod", &methods);
+ if(process_cleanmethods(methods)) {
+ FREELIST(methods);
+ return 1;
+ }
+ FREELIST(methods);
} else if(strcmp(key, "VerifySig") == 0) {
pgp_verify_t level = option_verifysig(value);
if(level != PM_PGP_VERIFY_UNKNOWN) {
- alpm_option_set_default_sigverify(level);
+ config->sigverify = level;
} else {
pm_printf(PM_LOG_ERROR,
_("config file %s, line %d: directive '%s' has invalid value '%s'\n"),
@@ -384,7 +384,7 @@ static int _add_mirror(pmdb_t *db, char *value)
/* let's attempt a replacement for the current repo */
char *temp = strreplace(value, "$repo", dbname);
/* let's attempt a replacement for the arch */
- const char *arch = alpm_option_get_arch();
+ const char *arch = config->arch;
char *server;
if(arch) {
server = strreplace(temp, "$arch", arch);
@@ -402,7 +402,7 @@ static int _add_mirror(pmdb_t *db, char *value)
if(alpm_db_add_server(db, server) != 0) {
/* pm_errno is set by alpm_db_setserver */
pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"),
- dbname, server, alpm_strerrorlast());
+ dbname, server, alpm_strerror(alpm_errno(config->handle)));
free(server);
return 1;
}
@@ -411,145 +411,248 @@ static int _add_mirror(pmdb_t *db, char *value)
return 0;
}
-/** Sets all libalpm required paths in one go. Called after the command line
+/** Sets up libalpm global stuff in one go. Called after the command line
* and inital config file parsing. Once this is complete, we can see if any
* paths were defined. If a rootdir was defined and nothing else, we want all
* of our paths to live under the rootdir that was specified. Safe to call
* multiple times (will only do anything the first time).
*/
-static int setlibpaths(void)
+static int setup_libalpm(void)
{
int ret = 0;
+ enum _pmerrno_t err;
+ pmhandle_t *handle;
+
+ pm_printf(PM_LOG_DEBUG, "setup_libalpm called\n");
- pm_printf(PM_LOG_DEBUG, "setlibpaths() called\n");
/* Configure root path first. If it is set and dbpath/logfile were not
* set, then set those as well to reside under the root. */
if(config->rootdir) {
char path[PATH_MAX];
- ret = alpm_option_set_root(config->rootdir);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting rootdir '%s' (%s)\n"),
- config->rootdir, alpm_strerrorlast());
- return ret;
- }
if(!config->dbpath) {
- /* omit leading slash from our static DBPATH, root handles it */
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), DBPATH + 1);
+ snprintf(path, PATH_MAX, "%s/%s", config->rootdir, DBPATH + 1);
config->dbpath = strdup(path);
}
if(!config->logfile) {
- /* omit leading slash from our static LOGFILE path, root handles it */
- snprintf(path, PATH_MAX, "%s%s", alpm_option_get_root(), LOGFILE + 1);
+ snprintf(path, PATH_MAX, "%s/%s", config->rootdir, LOGFILE + 1);
config->logfile = strdup(path);
}
- }
- /* Set other paths if they were configured. Note that unless rootdir
- * was left undefined, these two paths (dbpath and logfile) will have
- * been set locally above, so the if cases below will now trigger. */
- if(config->dbpath) {
- ret = alpm_option_set_dbpath(config->dbpath);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting dbpath '%s' (%s)\n"),
- config->dbpath, alpm_strerrorlast());
- return ret;
+ } else {
+ config->rootdir = strdup(ROOTDIR);
+ if(!config->dbpath) {
+ config->dbpath = strdup(DBPATH);
}
}
- if(config->logfile) {
- ret = alpm_option_set_logfile(config->logfile);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
- config->logfile, alpm_strerrorlast());
- return ret;
- }
+
+ /* initialize library */
+ handle = alpm_initialize(config->rootdir, config->dbpath, &err);
+ if(!handle) {
+ pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"),
+ alpm_strerror(err));
+ return -1;
+ }
+ config->handle = handle;
+
+ alpm_option_set_logcb(handle, cb_log);
+ alpm_option_set_dlcb(handle, cb_dl_progress);
+
+ config->logfile = config->logfile ? config->logfile : strdup(LOGFILE);
+ ret = alpm_option_set_logfile(handle, config->logfile);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"),
+ config->logfile, alpm_strerror(alpm_errno(config->handle)));
+ return ret;
}
/* Set GnuPG's home directory. This is not relative to rootdir, even if
* rootdir is defined. Reasoning: gpgdir contains configuration data. */
- if(config->gpgdir) {
- ret = alpm_option_set_signaturedir(config->gpgdir);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"),
- config->gpgdir, alpm_strerrorlast());
- return ret;
- }
+ config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR);
+ ret = alpm_option_set_signaturedir(handle, config->gpgdir);
+ if(ret != 0) {
+ pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"),
+ config->gpgdir, alpm_strerror(alpm_errno(config->handle)));
+ return ret;
}
/* add a default cachedir if one wasn't specified */
- if(alpm_option_get_cachedirs() == NULL) {
- alpm_option_add_cachedir(CACHEDIR);
+ if(config->cachedirs == NULL) {
+ alpm_option_add_cachedir(handle, CACHEDIR);
+ } else {
+ alpm_option_set_cachedirs(handle, config->cachedirs);
+ }
+
+ if(config->sigverify != PM_PGP_VERIFY_UNKNOWN) {
+ alpm_option_set_default_sigverify(handle, config->sigverify);
+ }
+
+ if(config->xfercommand) {
+ alpm_option_set_fetchcb(handle, download_with_xfercommand);
}
+
+ if(config->totaldownload) {
+ alpm_option_set_totaldlcb(handle, cb_dl_total);
+ }
+
+ alpm_option_set_arch(handle, config->arch);
+ alpm_option_set_checkspace(handle, config->checkspace);
+ alpm_option_set_usesyslog(handle, config->usesyslog);
+ alpm_option_set_usedelta(handle, config->usedelta);
+ alpm_option_set_default_sigverify(handle, config->sigverify);
+
+ alpm_option_set_ignorepkgs(handle, config->ignorepkg);
+ alpm_option_set_ignoregrps(handle, config->ignoregrp);
+ alpm_option_set_noupgrades(handle, config->noupgrade);
+ alpm_option_set_noextracts(handle, config->noextract);
+
return 0;
}
+/**
+ * Allows parsing in advance of an entire config section before we start
+ * calling library methods.
+ */
+struct section_t {
+ /* useful for all sections */
+ char *name;
+ int is_options;
+ /* db section option gathering */
+ pgp_verify_t sigverify;
+ alpm_list_t *servers;
+};
+
+/**
+ * Wrap up a section once we have reached the end of it. This should be called
+ * when a subsequent section is encountered, or when we have reached the end of
+ * the root config file. Once called, all existing saved config pieces on the
+ * section struct are freed.
+ * @param section the current parsed and saved section data
+ * @param parse_options whether we are parsing options or repo data
+ * @return 0 on success, 1 on failure
+ */
+static int finish_section(struct section_t *section, int parse_options)
+{
+ int ret = 0;
+ alpm_list_t *i;
+ pmdb_t *db;
-/* The real parseconfig. Called with a null section argument by the publicly
- * visible parseconfig so we can recall from within ourself on an include */
-static int _parseconfig(const char *file, int parse_options,
- char **section, pmdb_t *db)
+ pm_printf(PM_LOG_DEBUG, "config: finish section '%s'\n", section->name);
+
+ /* parsing options (or nothing)- nothing to do except free the pieces */
+ if(!section->name || parse_options || section->is_options) {
+ goto cleanup;
+ }
+
+ /* if we are not looking at options sections only, register a db */
+ db = alpm_db_register_sync(config->handle, section->name);
+ if(db == NULL) {
+ pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
+ section->name, alpm_strerror(alpm_errno(config->handle)));
+ ret = 1;
+ goto cleanup;
+ }
+
+ if(section->sigverify) {
+ if(alpm_db_set_pgp_verify(db, section->sigverify)) {
+ pm_printf(PM_LOG_ERROR,
+ _("could not set verify option for database '%s' (%s)\n"),
+ section->name, alpm_strerror(alpm_errno(config->handle)));
+ ret = 1;
+ goto cleanup;
+ }
+ }
+
+ for(i = section->servers; i; i = alpm_list_next(i)) {
+ char *value = alpm_list_getdata(i);
+ if(_add_mirror(db, value) != 0) {
+ pm_printf(PM_LOG_ERROR,
+ _("could not add mirror '%s' to database '%s' (%s)\n"),
+ value, section->name, alpm_strerror(alpm_errno(config->handle)));
+ ret = 1;
+ goto cleanup;
+ }
+ free(value);
+ }
+
+cleanup:
+ alpm_list_free(section->servers);
+ section->servers = NULL;
+ section->sigverify = 0;
+ free(section->name);
+ section->name = NULL;
+ return ret;
+}
+
+/** The "real" parseconfig. Each "Include" directive will recall this method so
+ * recursion and stack depth are limited to 10 levels. The publicly visible
+ * parseconfig calls this with a NULL section argument so we can recall from
+ * within ourself on an include.
+ * @param file path to the config file
+ * @param section the current active section
+ * @param parse_options whether to parse and call methods for the options
+ * section; if 0, parse and call methods for the repos sections
+ * @param depth the current recursion depth
+ * @return 0 on success, 1 on failure
+ */
+static int _parseconfig(const char *file, struct section_t *section,
+ int parse_options, int depth)
{
FILE *fp = NULL;
- char line[PATH_MAX+1];
+ char line[PATH_MAX];
int linenum = 0;
- char *ptr;
int ret = 0;
+ const int max_depth = 10;
+
+ if(depth >= max_depth) {
+ pm_printf(PM_LOG_ERROR,
+ _("config parsing exceeded max recursion depth of %d.\n"), max_depth);
+ ret = 1;
+ goto cleanup;
+ }
pm_printf(PM_LOG_DEBUG, "config: attempting to read file %s\n", file);
fp = fopen(file, "r");
if(fp == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s could not be read.\n"), file);
- return 1;
+ ret = 1;
+ goto cleanup;
}
while(fgets(line, PATH_MAX, fp)) {
- char *key, *value;
+ char *key, *value, *ptr;
+ size_t line_len;
linenum++;
strtrim(line);
+ line_len = strlen(line);
/* ignore whole line and end of line comments */
- if(strlen(line) == 0 || line[0] == '#') {
+ if(line_len == 0 || line[0] == '#') {
continue;
}
if((ptr = strchr(line, '#'))) {
*ptr = '\0';
}
- /* sanity check */
- if(parse_options && db) {
- pm_printf(PM_LOG_ERROR, _("config file %s, line %d: parsing options but have a database.\n"),
- file, linenum);
- ret = 1;
- goto cleanup;
- }
-
- if(line[0] == '[' && line[strlen(line)-1] == ']') {
+ if(line[0] == '[' && line[line_len - 1] == ']') {
char *name;
- /* new config section, skip the '[' */
- ptr = line;
- ptr++;
- name = strdup(ptr);
- name[strlen(name)-1] = '\0';
- if(!strlen(name)) {
+ /* only possibility here is a line == '[]' */
+ if(line_len <= 2) {
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: bad section name.\n"),
file, linenum);
ret = 1;
goto cleanup;
}
- pm_printf(PM_LOG_DEBUG, "config: new section '%s'\n", name);
- /* if we are not looking at the options section, register a db */
- if(!parse_options && strcmp(name, "options") != 0) {
- db = alpm_db_register_sync(name);
- if(db == NULL) {
- pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
- name, alpm_strerrorlast());
- ret = 1;
- goto cleanup;
- }
- }
- if(*section) {
- free(*section);
+ /* new config section, skip the '[' */
+ name = strdup(line + 1);
+ name[line_len - 2] = '\0';
+ /* we're at a new section; perform any post-actions for the prior */
+ if(finish_section(section, parse_options)) {
+ ret = 1;
+ goto cleanup;
}
- *section = name;
+ pm_printf(PM_LOG_DEBUG, "config: new section '%s'\n", name);
+ section->name = name;
+ section->is_options = (strcmp(name, "options") == 0);
continue;
}
@@ -568,7 +671,7 @@ static int _parseconfig(const char *file, int parse_options,
goto cleanup;
}
/* For each directive, compare to the camelcase string. */
- if(*section == NULL) {
+ if(section->name == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: All directives must belong to a section.\n"),
file, linenum);
ret = 1;
@@ -608,19 +711,19 @@ static int _parseconfig(const char *file, int parse_options,
for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
pm_printf(PM_LOG_DEBUG, "config file %s, line %d: including %s\n",
file, linenum, globbuf.gl_pathv[gindex]);
- _parseconfig(globbuf.gl_pathv[gindex], parse_options, section, db);
+ _parseconfig(globbuf.gl_pathv[gindex], section, parse_options, depth + 1);
}
break;
}
globfree(&globbuf);
continue;
}
- if(parse_options && strcmp(*section, "options") == 0) {
+ if(parse_options && section->is_options) {
/* we are either in options ... */
if((ret = _parse_options(key, value, file, linenum)) != 0) {
goto cleanup;
}
- } else if (!parse_options && strcmp(*section, "options") != 0) {
+ } else if (!parse_options && !section->is_options) {
/* ... or in a repo section */
if(strcmp(key, "Server") == 0) {
if(value == NULL) {
@@ -629,19 +732,11 @@ static int _parseconfig(const char *file, int parse_options,
ret = 1;
goto cleanup;
}
- if(_add_mirror(db, value) != 0) {
- ret = 1;
- goto cleanup;
- }
+ section->servers = alpm_list_add(section->servers, strdup(value));
} else if(strcmp(key, "VerifySig") == 0) {
pgp_verify_t level = option_verifysig(value);
if(level != PM_PGP_VERIFY_UNKNOWN) {
- ret = alpm_db_set_pgp_verify(db, level);
- if(ret != 0) {
- pm_printf(PM_LOG_ERROR, _("could not add set verify option for database '%s': %s (%s)\n"),
- alpm_db_get_name(db), value, alpm_strerrorlast());
- goto cleanup;
- }
+ section->sigverify = level;
} else {
pm_printf(PM_LOG_ERROR,
_("config file %s, line %d: directive '%s' has invalid value '%s'\n"),
@@ -652,11 +747,15 @@ static int _parseconfig(const char *file, int parse_options,
} else {
pm_printf(PM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
- file, linenum, key, *section);
+ file, linenum, key, section->name);
}
}
}
+ if(depth == 0) {
+ ret = finish_section(section, parse_options);
+ }
+
cleanup:
fclose(fp);
pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file);
@@ -664,33 +763,29 @@ cleanup:
}
/** Parse a configuration file.
- * @param file path to the config file.
+ * @param file path to the config file
* @return 0 on success, non-zero on error
*/
int parseconfig(const char *file)
{
int ret;
- char *section = NULL;
+ struct section_t section;
+ memset(&section, 0, sizeof(struct section_t));
/* the config parse is a two-pass affair. We first parse the entire thing for
* the [options] section so we can get all default and path options set.
* Next, we go back and parse everything but [options]. */
/* call the real parseconfig function with a null section & db argument */
pm_printf(PM_LOG_DEBUG, "parseconfig: options pass\n");
- if((ret = _parseconfig(file, 1, &section, NULL))) {
- free(section);
+ if((ret = _parseconfig(file, &section, 1, 0))) {
return ret;
}
- free(section);
- /* call setlibpaths here to ensure we have called it at least once */
- if((ret = setlibpaths())) {
+ if((ret = setup_libalpm())) {
return ret;
}
/* second pass, repo section parsing */
- section = NULL;
pm_printf(PM_LOG_DEBUG, "parseconfig: repo pass\n");
- return _parseconfig(file, 0, &section, NULL);
- free(section);
+ return _parseconfig(file, &section, 0, 0);
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 76c76cf5..4c44bfdd 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -32,6 +32,10 @@ typedef struct __config_t {
unsigned short noprogressbar;
unsigned short logmask;
unsigned short print;
+ unsigned short checkspace;
+ unsigned short usesyslog;
+ unsigned short usedelta;
+ char *arch;
char *print_format;
/* unfortunately, we have to keep track of paths both here and in the library
* because they can come from both the command line or config file, and we
@@ -41,7 +45,7 @@ typedef struct __config_t {
char *dbpath;
char *logfile;
char *gpgdir;
- /* TODO how to handle cachedirs? */
+ alpm_list_t *cachedirs;
unsigned short op_q_isfile;
unsigned short op_q_info;
@@ -64,9 +68,10 @@ typedef struct __config_t {
unsigned short op_s_upgrade;
unsigned short group;
- pmtransflag_t flags;
unsigned short noask;
unsigned int ask;
+ pmtransflag_t flags;
+ pgp_verify_t sigverify;
/* conf file options */
/* I Love Candy! */
@@ -80,7 +85,14 @@ typedef struct __config_t {
unsigned short cleanmethod;
alpm_list_t *holdpkg;
alpm_list_t *syncfirst;
+ alpm_list_t *ignorepkg;
+ alpm_list_t *ignoregrp;
+ alpm_list_t *noupgrade;
+ alpm_list_t *noextract;
char *xfercommand;
+
+ /* our connection to libalpm */
+ pmhandle_t *handle;
} config_t;
/* Operations */
diff --git a/src/pacman/database.c b/src/pacman/database.c
index 123f72d2..292fa54a 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -63,12 +63,12 @@ int pacman_database(alpm_list_t *targets)
return 1;
}
- db_local = alpm_option_get_localdb();
+ db_local = alpm_option_get_localdb(config->handle);
for(i = targets; i; i = alpm_list_next(i)) {
char *pkgname = i->data;
if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) {
pm_printf(PM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
- pkgname, alpm_strerrorlast());
+ pkgname, alpm_strerror(alpm_errno(config->handle)));
retval = 1;
} else {
if(reason == PM_PKG_REASON_DEPEND) {
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 19e4da4a..99abd72d 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -27,12 +27,13 @@
/* pacman */
#include "pacman.h"
+#include "conf.h"
int pacman_deptest(alpm_list_t *targets)
{
alpm_list_t *i;
alpm_list_t *deps = NULL;
- pmdb_t *localdb = alpm_option_get_localdb();
+ pmdb_t *localdb = alpm_option_get_localdb(config->handle);
for(i = targets; i; i = alpm_list_next(i)) {
char *target = alpm_list_getdata(i);
diff --git a/src/pacman/package.c b/src/pacman/package.c
index e256dda5..9cdb4877 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -33,6 +33,7 @@
/* pacman */
#include "package.h"
#include "util.h"
+#include "conf.h"
#define CLBUF_SIZE 4096
@@ -194,7 +195,7 @@ static const char *get_backup_file_status(const char *root,
void dump_pkg_backups(pmpkg_t *pkg)
{
alpm_list_t *i;
- const char *root = alpm_option_get_root();
+ const char *root = alpm_option_get_root(config->handle);
printf(_("Backup Files:\n"));
if(alpm_pkg_get_backup(pkg)) {
/* package has backup files, so print them */
@@ -227,7 +228,7 @@ void dump_pkg_files(pmpkg_t *pkg, int quiet)
pkgname = alpm_pkg_get_name(pkg);
pkgfiles = alpm_pkg_get_files(pkg);
- root = alpm_option_get_root();
+ root = alpm_option_get_root(config->handle);
for(i = pkgfiles; i; i = alpm_list_next(i)) {
filestr = alpm_list_getdata(i);
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 1a6e3eb4..afc79f6f 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -50,7 +50,6 @@
/* pacman */
#include "pacman.h"
#include "util.h"
-#include "callback.h"
#include "conf.h"
/* list of targets specified on command line */
@@ -264,8 +263,8 @@ static void setuseragent(void)
*/
static void cleanup(int ret) {
/* free alpm library resources */
- if(alpm_release() == -1) {
- pm_printf(PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
+ if(config->handle && alpm_release(config->handle) == -1) {
+ pm_printf(PM_LOG_ERROR, "error releasing alpm library\n");
}
/* free memory */
@@ -308,12 +307,12 @@ static void handler(int signum)
} else if(signum == SIGINT) {
const char *msg = "\nInterrupt signal received\n";
xwrite(err, msg, strlen(msg));
- if(alpm_trans_interrupt() == 0) {
+ if(alpm_trans_interrupt(config->handle) == 0) {
/* a transaction is being interrupted, don't exit pacman yet. */
return;
}
/* no commiting transaction, we can release it now and then exit pacman */
- alpm_trans_release();
+ alpm_trans_release(config->handle);
/* output a newline to be sure we clear any line we may be on */
xwrite(out, "\n", 1);
}
@@ -322,18 +321,16 @@ static void handler(int signum)
#define check_optarg() if(!optarg) { return 1; }
-typedef int (*fn_add) (const char *s);
-
-static int parsearg_util_addlist(fn_add fn)
+static int parsearg_util_addlist(alpm_list_t **list)
{
- alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */
+ alpm_list_t *split, *item;
check_optarg();
- list = strsplit(optarg, ',');
- for(item = list; item; item = alpm_list_next(item)) {
- fn((char *)alpm_list_getdata(item));
+ split = strsplit(optarg, ',');
+ for(item = split; item; item = alpm_list_next(item)) {
+ *list = alpm_list_add(*list, item->data);
}
- FREELIST(list);
+ alpm_list_free(split);
return 0;
}
@@ -385,7 +382,7 @@ static int parsearg_global(int opt)
switch(opt) {
case OP_ARCH:
check_optarg();
- config_set_arch(optarg);
+ config_set_arch(strdup(optarg));
break;
case OP_ASK:
check_optarg();
@@ -394,11 +391,7 @@ static int parsearg_global(int opt)
break;
case OP_CACHEDIR:
check_optarg();
- if(alpm_option_add_cachedir(optarg) != 0) {
- pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
- optarg, alpm_strerrorlast());
- return 1;
- }
+ config->cachedirs = alpm_list_add(config->cachedirs, strdup(optarg));
break;
case OP_CONFIG:
check_optarg();
@@ -535,10 +528,10 @@ static int parsearg_upgrade(int opt)
case OP_ASDEPS: config->flags |= PM_TRANS_FLAG_ALLDEPS; break;
case OP_ASEXPLICIT: config->flags |= PM_TRANS_FLAG_ALLEXPLICIT; break;
case OP_IGNORE:
- parsearg_util_addlist(alpm_option_add_ignorepkg);
+ parsearg_util_addlist(&(config->ignorepkg));
break;
case OP_IGNOREGROUP:
- parsearg_util_addlist(alpm_option_add_ignoregrp);
+ parsearg_util_addlist(&(config->ignoregrp));
break;
default: return 1;
}
@@ -732,8 +725,9 @@ static void cl_to_log(int argc, char* argv[])
size += strlen(argv[i]) + 1;
}
char *cl_text = malloc(size);
- if(!cl_text)
+ if(!cl_text) {
return;
+ }
char *p = cl_text;
for(i = 0; i<argc-1; i++) {
strcpy(p, argv[i]);
@@ -741,7 +735,7 @@ static void cl_to_log(int argc, char* argv[])
*p++ = ' ';
}
strcpy(p, argv[i]);
- alpm_logaction("Running '%s'\n", cl_text);
+ alpm_logaction(config->handle, "Running '%s'\n", cl_text);
free(cl_text);
}
@@ -799,22 +793,6 @@ int main(int argc, char *argv[])
config->noprogressbar = 1;
}
- /* initialize library */
- if(alpm_initialize() == -1) {
- pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"),
- alpm_strerrorlast());
- cleanup(EXIT_FAILURE);
- }
-
- /* Setup logging as soon as possible, to print out maximum debugging info */
- alpm_option_set_logcb(cb_log);
- alpm_option_set_dlcb(cb_dl_progress);
- /* define paths to reasonable defaults */
- alpm_option_set_root(ROOTDIR);
- alpm_option_set_dbpath(DBPATH);
- alpm_option_set_signaturedir(GPGDIR);
- alpm_option_set_logfile(LOGFILE);
-
/* Priority of options:
* 1. command line
* 2. config file
@@ -873,18 +851,13 @@ int main(int argc, char *argv[])
cleanup(ret);
}
- /* set TotalDownload callback if option enabled */
- if(config->totaldownload) {
- alpm_option_set_totaldlcb(cb_dl_total);
- }
-
/* noask is meant to be non-interactive */
if(config->noask) {
config->noconfirm = 1;
}
/* set up the print operations */
- if(config->print) {
+ if(config->print && !config->op_s_clean) {
config->noconfirm = 1;
config->flags |= PM_TRANS_FLAG_NOCONFLICTS;
config->flags |= PM_TRANS_FLAG_NOLOCK;
@@ -902,16 +875,17 @@ int main(int argc, char *argv[])
if(config->verbose > 0) {
alpm_list_t *i;
- printf("Root : %s\n", alpm_option_get_root());
+ printf("Root : %s\n", alpm_option_get_root(config->handle));
printf("Conf File : %s\n", config->configfile);
- printf("DB Path : %s\n", alpm_option_get_dbpath());
+ printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle));
printf("Cache Dirs: ");
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) {
printf("%s ", (char *)alpm_list_getdata(i));
}
printf("\n");
- printf("Lock File : %s\n", alpm_option_get_lockfile());
- printf("Log File : %s\n", alpm_option_get_logfile());
+ printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle));
+ printf("Log File : %s\n", alpm_option_get_logfile(config->handle));
+ printf("GPG Dir : %s\n", alpm_option_get_signaturedir(config->handle));
list_display("Targets :", pm_targets);
}
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 5ca52c38..06fd704a 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -40,7 +40,7 @@ static char *resolve_path(const char *file)
{
char *str = NULL;
- str = calloc(PATH_MAX + 1, sizeof(char));
+ str = calloc(PATH_MAX, sizeof(char));
if(!str) {
return NULL;
}
@@ -77,6 +77,10 @@ static int search_path(char **filename, struct stat *bufptr)
}
fullname = malloc(plen + flen + 2);
+ if(!fullname) {
+ free(envpath);
+ return -1;
+ }
sprintf(fullname, "%s/%s", path, *filename);
if(lstat(fullname, bufptr) == 0) {
@@ -120,12 +124,12 @@ static int query_fileowner(alpm_list_t *targets)
/* Set up our root path buffer. We only need to copy the location of root in
* once, then we can just overwrite whatever file was there on the previous
* iteration. */
- root = alpm_option_get_root();
+ root = alpm_option_get_root(config->handle);
strncpy(path, root, PATH_MAX - 1);
append = path + strlen(path);
max_length = PATH_MAX - (append - path) - 1;
- db_local = alpm_option_get_localdb();
+ db_local = alpm_option_get_localdb(config->handle);
for(t = targets; t; t = alpm_list_next(t)) {
char *filename, *dname, *rpath;
@@ -236,7 +240,7 @@ static int query_search(alpm_list_t *targets)
{
alpm_list_t *i, *searchlist;
int freelist;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
/* if we have a targets list, search for packages matching it */
if(targets) {
@@ -295,7 +299,7 @@ static int query_group(alpm_list_t *targets)
alpm_list_t *i, *j;
char *grpname = NULL;
int ret = 0;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
if(targets == NULL) {
for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) {
@@ -338,7 +342,7 @@ static int is_foreign(pmpkg_t *pkg)
{
const char *pkgname = alpm_pkg_get_name(pkg);
alpm_list_t *j;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle);
int match = 0;
for(j = sync_dbs; j; j = alpm_list_next(j)) {
@@ -386,7 +390,8 @@ static int filter(pmpkg_t *pkg)
return 0;
}
/* check if this pkg is outdated */
- if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
+ if(config->op_q_upgrade && (alpm_sync_newversion(pkg,
+ alpm_option_get_syncdbs(config->handle)) == NULL)) {
return 0;
}
return 1;
@@ -402,7 +407,7 @@ static int check(pmpkg_t *pkg)
size_t rootlen;
char f[PATH_MAX];
- root = alpm_option_get_root();
+ root = alpm_option_get_root(config->handle);
rootlen = strlen(root);
if(rootlen + 1 > PATH_MAX) {
/* we are in trouble here */
@@ -499,14 +504,14 @@ int pacman_query(alpm_list_t *targets)
if(config->op_q_foreign) {
/* ensure we have at least one valid sync db set up */
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle);
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
return 1;
}
}
- db_local = alpm_option_get_localdb();
+ db_local = alpm_option_get_localdb(config->handle);
/* operations on all packages in the local DB
* valid: no-op (plain -Q), list, info, check
@@ -547,7 +552,7 @@ int pacman_query(alpm_list_t *targets)
char *strname = alpm_list_getdata(i);
if(config->op_q_isfile) {
- alpm_pkg_load(strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg);
+ alpm_pkg_load(config->handle, strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg);
} else {
pkg = alpm_db_get_pkg(db_local, strname);
}
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 58e6edd5..a4e18941 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -31,15 +31,16 @@
#include "util.h"
#include "conf.h"
-static int remove_target(char *target)
+static int remove_target(const char *target)
{
pmpkg_t *info;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
alpm_list_t *p;
if((info = alpm_db_get_pkg(db_local, target)) != NULL) {
- if(alpm_remove_pkg(info) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
+ if(alpm_remove_pkg(config->handle, info) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target,
+ alpm_strerror(alpm_errno(config->handle)));
return -1;
}
return 0;
@@ -53,8 +54,9 @@ static int remove_target(char *target)
}
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
pmpkg_t *pkg = alpm_list_getdata(p);
- if(alpm_remove_pkg(pkg) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast());
+ if(alpm_remove_pkg(config->handle, pkg) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target,
+ alpm_strerror(alpm_errno(config->handle)));
return -1;
}
}
@@ -99,10 +101,11 @@ int pacman_remove(alpm_list_t *targets)
}
/* Step 2: prepare the transaction based on its type, targets and flags */
- if(alpm_trans_prepare(&data) == -1) {
+ if(alpm_trans_prepare(config->handle, &data) == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
+ alpm_strerror(err));
+ switch(err) {
case PM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
char *pkg = alpm_list_getdata(i);
@@ -118,18 +121,18 @@ int pacman_remove(alpm_list_t *targets)
depstring);
free(depstring);
}
- FREELIST(data);
break;
default:
break;
}
+ FREELIST(data);
retval = 1;
goto cleanup;
}
/* Search for holdpkg in target list */
int holdpkg = 0;
- for(i = alpm_trans_get_remove(); i; i = alpm_list_next(i)) {
+ for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
@@ -143,7 +146,7 @@ int pacman_remove(alpm_list_t *targets)
}
/* Step 3: actually perform the removal */
- alpm_list_t *pkglist = alpm_trans_get_remove();
+ alpm_list_t *pkglist = alpm_trans_get_remove(config->handle);
if(pkglist == NULL) {
printf(_(" there is nothing to do\n"));
goto cleanup; /* we are done */
@@ -162,12 +165,14 @@ int pacman_remove(alpm_list_t *targets)
goto cleanup;
}
- if(alpm_trans_commit(NULL) == -1) {
+ if(alpm_trans_commit(config->handle, &data) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
- alpm_strerrorlast());
+ alpm_strerror(alpm_errno(config->handle)));
retval = 1;
}
+ FREELIST(data);
+
/* Step 4: release transaction resources */
cleanup:
if(trans_release() == -1) {
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 884504f3..37b9d6e3 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -51,7 +51,7 @@ static int sync_cleandb(const char *dbpath, int keep_used)
return 1;
}
- syncdbs = alpm_option_get_syncdbs();
+ syncdbs = alpm_option_get_syncdbs(config->handle);
rewinddir(dir);
/* step through the directory one file at a time */
@@ -125,7 +125,7 @@ static int sync_cleandb_all(void)
char newdbpath[PATH_MAX];
int ret = 0;
- dbpath = alpm_option_get_dbpath();
+ dbpath = alpm_option_get_dbpath(config->handle);
printf(_("Database directory: %s\n"), dbpath);
if(!yesno(_("Do you want to remove unused repositories?"))) {
return 0;
@@ -145,11 +145,12 @@ static int sync_cleandb_all(void)
static int sync_cleancache(int level)
{
alpm_list_t *i;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
- pmdb_t *db_local = alpm_option_get_localdb();
+ alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle);
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_list_t *cachedirs = alpm_option_get_cachedirs(config->handle);
int ret = 0;
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = cachedirs; i; i = alpm_list_next(i)) {
printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
}
@@ -177,7 +178,7 @@ static int sync_cleancache(int level)
printf(_("removing all files from cache...\n"));
}
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = cachedirs; i; i = alpm_list_next(i)) {
const char *cachedir = alpm_list_getdata(i);
DIR *dir = opendir(cachedir);
struct dirent *ent;
@@ -219,7 +220,7 @@ static int sync_cleancache(int level)
/* attempt to load the package, prompt removal on failures as we may have
* files here that aren't valid packages. we also don't need a full
* load of the package, just the metadata. */
- if(alpm_pkg_load(path, 0, PM_PGP_VERIFY_NEVER, &localpkg) != 0
+ if(alpm_pkg_load(config->handle, path, 0, PM_PGP_VERIFY_NEVER, &localpkg) != 0
|| localpkg == NULL) {
if(yesno(_("File %s does not seem to be a valid package, remove it?"),
path)) {
@@ -292,7 +293,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to update %s (%s)\n"),
- alpm_db_get_name(db), alpm_strerrorlast());
+ alpm_db_get_name(db), alpm_strerror(alpm_errno(config->handle)));
} else if(ret == 1) {
printf(_(" %s is up to date\n"), alpm_db_get_name(db));
success++;
@@ -335,7 +336,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *i, *j, *ret;
int freelist;
int found = 0;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);
@@ -532,7 +533,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
{
alpm_list_t *i, *j, *ls = NULL;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
@@ -587,7 +588,8 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
static alpm_list_t *syncfirst(void) {
alpm_list_t *i, *res = NULL;
- pmdb_t *db_local = alpm_option_get_localdb();
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
+ alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle);
for(i = config->syncfirst; i; i = alpm_list_next(i)) {
char *pkgname = alpm_list_getdata(i);
@@ -596,7 +598,7 @@ static alpm_list_t *syncfirst(void) {
continue;
}
- if(alpm_sync_newversion(pkg, alpm_option_get_syncdbs())) {
+ if(alpm_sync_newversion(pkg, syncdbs)) {
res = alpm_list_add(res, strdup(pkgname));
}
}
@@ -607,7 +609,7 @@ static alpm_list_t *syncfirst(void) {
static pmdb_t *get_db(const char *dbname)
{
alpm_list_t *i;
- for(i = alpm_option_get_syncdbs(); i; i = i->next) {
+ for(i = alpm_option_get_syncdbs(config->handle); i; i = i->next) {
pmdb_t *db = i->data;
if(strcmp(alpm_db_get_name(db), dbname) == 0) {
return db;
@@ -618,17 +620,18 @@ static pmdb_t *get_db(const char *dbname)
static int process_pkg(pmpkg_t *pkg)
{
- int ret = alpm_add_pkg(pkg);
+ int ret = alpm_add_pkg(config->handle, pkg);
if(ret == -1) {
- if(pm_errno == PM_ERR_TRANS_DUP_TARGET
- || pm_errno == PM_ERR_PKG_IGNORED) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
+ if(err == PM_ERR_TRANS_DUP_TARGET
+ || err == PM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg));
return 0;
} else {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg),
- alpm_strerrorlast());
+ alpm_strerror(err));
return 1;
}
}
@@ -683,12 +686,13 @@ cleanup:
static int process_targname(alpm_list_t *dblist, char *targname)
{
- pmpkg_t *pkg = alpm_find_dbs_satisfier(dblist, targname);
+ pmpkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname);
- /* #FS23342 - skip ignored packages when user says no */
- if(pm_errno == PM_ERR_PKG_IGNORED) {
+ /* #FS#23342 - skip ignored packages when user says no */
+ if(alpm_errno(config->handle) == PM_ERR_PKG_IGNORED) {
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname);
- pm_errno = 0;
+ /* TODO how to do this, we shouldn't be fucking with it from the frontend */
+ /* pm_errno = 0; */
return 0;
}
@@ -726,7 +730,7 @@ static int process_target(char *target)
alpm_list_free(dblist);
} else {
targname = targstring;
- dblist = alpm_option_get_syncdbs();
+ dblist = alpm_option_get_syncdbs(config->handle);
ret = process_targname(dblist, targname);
}
cleanup:
@@ -757,19 +761,20 @@ static int sync_trans(alpm_list_t *targets)
if(config->op_s_upgrade) {
printf(_(":: Starting full system upgrade...\n"));
- alpm_logaction("starting full system upgrade\n");
- if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
+ alpm_logaction(config->handle, "starting full system upgrade\n");
+ if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle)));
retval = 1;
goto cleanup;
}
}
/* Step 2: "compute" the transaction based on targets and flags */
- if(alpm_trans_prepare(&data) == -1) {
+ if(alpm_trans_prepare(config->handle, &data) == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
+ alpm_strerror(err));
+ switch(err) {
alpm_list_t *i;
case PM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
@@ -808,7 +813,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- packages = alpm_trans_get_add();
+ packages = alpm_trans_get_add(config->handle);
if(packages == NULL) {
/* nothing to do: just exit without complaining */
printf(_(" there is nothing to do\n"));
@@ -821,8 +826,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- display_targets(alpm_trans_get_remove(), 0);
- display_targets(alpm_trans_get_add(), 1);
+ display_targets(alpm_trans_get_remove(config->handle), 0);
+ display_targets(alpm_trans_get_add(config->handle), 1);
printf("\n");
int confirm;
@@ -835,10 +840,11 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- if(alpm_trans_commit(&data) == -1) {
+ if(alpm_trans_commit(config->handle, &data) == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
+ alpm_strerror(err));
+ switch(err) {
alpm_list_t *i;
case PM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
@@ -910,7 +916,7 @@ int pacman_sync(alpm_list_t *targets)
}
/* ensure we have at least one valid sync db set up */
- sync_dbs = alpm_option_get_syncdbs();
+ sync_dbs = alpm_option_get_syncdbs(config->handle);
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
return 1;
@@ -919,7 +925,7 @@ int pacman_sync(alpm_list_t *targets)
if(config->op_s_sync) {
/* grab a fresh package list */
printf(_(":: Synchronizing package databases...\n"));
- alpm_logaction("synchronizing package lists\n");
+ alpm_logaction(config->handle, "synchronizing package lists\n");
if(!sync_synctree(config->op_s_sync, sync_dbs)) {
return 1;
}
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 0ffc94c4..c0466456 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -42,7 +42,7 @@
int pacman_upgrade(alpm_list_t *targets)
{
alpm_list_t *i, *data = NULL;
- pgp_verify_t check_sig = alpm_option_get_default_sigverify();
+ pgp_verify_t check_sig = alpm_option_get_default_sigverify(config->handle);
int retval = 0;
if(targets == NULL) {
@@ -54,10 +54,10 @@ int pacman_upgrade(alpm_list_t *targets)
*/
for(i = targets; i; i = alpm_list_next(i)) {
if(strstr(i->data, "://")) {
- char *str = alpm_fetch_pkgurl(i->data);
+ char *str = alpm_fetch_pkgurl(config->handle, i->data);
if(str == NULL) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- (char *)i->data, alpm_strerrorlast());
+ (char *)i->data, alpm_strerror(alpm_errno(config->handle)));
return 1;
} else {
free(i->data);
@@ -76,15 +76,15 @@ int pacman_upgrade(alpm_list_t *targets)
char *targ = alpm_list_getdata(i);
pmpkg_t *pkg;
- if(alpm_pkg_load(targ, 1, check_sig, &pkg) != 0) {
+ if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 0) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- targ, alpm_strerrorlast());
+ targ, alpm_strerror(alpm_errno(config->handle)));
trans_release();
return 1;
}
- if(alpm_add_pkg(pkg) == -1) {
+ if(alpm_add_pkg(config->handle, pkg) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- targ, alpm_strerrorlast());
+ targ, alpm_strerror(alpm_errno(config->handle)));
alpm_pkg_free(pkg);
trans_release();
return 1;
@@ -93,10 +93,11 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 2: "compute" the transaction based on targets and flags */
/* TODO: No, compute nothing. This is stupid. */
- if(alpm_trans_prepare(&data) == -1) {
+ if(alpm_trans_prepare(config->handle, &data) == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
+ alpm_strerror(err));
+ switch(err) {
case PM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
char *pkg = alpm_list_getdata(i);
@@ -140,22 +141,22 @@ int pacman_upgrade(alpm_list_t *targets)
}
/* Step 3: perform the installation */
+ alpm_list_t *packages = alpm_trans_get_add(config->handle);
if(config->print) {
- print_packages(alpm_trans_get_add());
+ print_packages(packages);
trans_release();
return 0;
}
/* print targets and ask user confirmation */
- alpm_list_t *packages = alpm_trans_get_add();
if(packages == NULL) { /* we are done */
printf(_(" there is nothing to do\n"));
trans_release();
return retval;
}
- display_targets(alpm_trans_get_remove(), 0);
- display_targets(alpm_trans_get_add(), 1);
+ display_targets(alpm_trans_get_remove(config->handle), 0);
+ display_targets(alpm_trans_get_add(config->handle), 1);
printf("\n");
int confirm = yesno(_("Proceed with installation?"));
if(!confirm) {
@@ -163,10 +164,11 @@ int pacman_upgrade(alpm_list_t *targets)
return retval;
}
- if(alpm_trans_commit(&data) == -1) {
+ if(alpm_trans_commit(config->handle, &data) == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
- alpm_strerrorlast());
- switch(pm_errno) {
+ alpm_strerror(err));
+ switch(err) {
alpm_list_t *i;
case PM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 8631075f..27b18601 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -53,20 +53,22 @@ int trans_init(pmtransflag_t flags)
{
int ret;
if(config->print) {
- ret = alpm_trans_init(flags, NULL, NULL, NULL);
+ ret = alpm_trans_init(config->handle, flags, NULL, NULL, NULL);
} else {
- ret = alpm_trans_init(flags, cb_trans_evt, cb_trans_conv,
+ ret = alpm_trans_init(config->handle, flags, cb_trans_evt, cb_trans_conv,
cb_trans_progress);
}
if(ret == -1) {
+ enum _pmerrno_t err = alpm_errno(config->handle);
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to init transaction (%s)\n"),
- alpm_strerrorlast());
- if(pm_errno == PM_ERR_HANDLE_LOCK) {
+ alpm_strerror(err));
+ if(err == PM_ERR_HANDLE_LOCK) {
fprintf(stderr, _(" if you're sure a package manager is not already\n"
- " running, you can remove %s\n"), alpm_option_get_lockfile());
+ " running, you can remove %s\n"),
+ alpm_option_get_lockfile(config->handle));
}
- else if(pm_errno == PM_ERR_DB_VERSION) {
+ else if(err == PM_ERR_DB_VERSION) {
fprintf(stderr, _(" try running pacman-db-upgrade\n"));
}
@@ -77,9 +79,9 @@ int trans_init(pmtransflag_t flags)
int trans_release(void)
{
- if(alpm_trans_release() == -1) {
+ if(alpm_trans_release(config->handle) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
- alpm_strerrorlast());
+ alpm_strerror(alpm_errno(config->handle)));
return -1;
}
return 0;
@@ -106,7 +108,7 @@ int needs_root(void)
static int flush_term_input(void) {
#ifdef HAVE_TCFLUSH
if(isatty(fileno(stdin))) {
- return(tcflush(fileno(stdin), TCIFLUSH));
+ return tcflush(fileno(stdin), TCIFLUSH);
}
#endif
@@ -115,7 +117,7 @@ static int flush_term_input(void) {
}
/* gets the current screen column width */
-int getcols(void)
+int getcols(int def)
{
#ifdef TIOCGSIZE
struct ttysize win;
@@ -128,7 +130,7 @@ int getcols(void)
return win.ws_col;
}
#endif
- return 0;
+ return def;
}
/* does the same thing as 'rm -rf' */
@@ -223,16 +225,16 @@ void indentprint(const char *str, int indent)
{
wchar_t *wcstr;
const wchar_t *p;
- int len, cidx, cols;
+ int len, cidx;
+ const int cols = getcols(0);
if(!str) {
return;
}
- cols = getcols();
-
- /* if we're not a tty, print without indenting */
- if(cols == 0) {
+ /* if we're not a tty, or our tty is not wide enough that wrapping even makes
+ * sense, print without indenting */
+ if(cols == 0 || indent > cols) {
printf("%s", str);
return;
}
@@ -439,8 +441,6 @@ static int string_length(const char *s)
void string_display(const char *title, const char *string)
{
- int len = 0;
-
if(title) {
printf("%s ", title);
}
@@ -448,7 +448,7 @@ void string_display(const char *title, const char *string)
printf(_("None"));
} else {
/* compute the length of title + a space */
- len = string_length(title) + 1;
+ int len = string_length(title) + 1;
indentprint(string, len);
}
printf("\n");
@@ -516,13 +516,13 @@ static alpm_list_t *table_create_format(const alpm_list_t *header,
alpm_list_free(longest_strs);
/* return NULL if terminal is not wide enough */
- if(totalwidth > getcols()) {
+ if(totalwidth > getcols(80)) {
fprintf(stderr, _("insufficient columns available for table display\n"));
FREELIST(formats);
- return(NULL);
+ return NULL;
}
- return(formats);
+ return formats;
}
/** Displays the list in table format
@@ -542,12 +542,12 @@ int table_display(const char *title, const alpm_list_t *header,
alpm_list_t *formats;
if(rows == NULL || header == NULL) {
- return(0);
+ return 0;
}
formats = table_create_format(header, rows);
if(formats == NULL) {
- return(-1);
+ return -1;
}
if(title != NULL) {
@@ -562,13 +562,13 @@ int table_display(const char *title, const alpm_list_t *header,
}
FREELIST(formats);
- return(0);
+ return 0;
}
void list_display(const char *title, const alpm_list_t *list)
{
const alpm_list_t *i;
- int cols, len = 0;
+ int len = 0;
if(title) {
len = string_length(title) + 1;
@@ -578,11 +578,16 @@ void list_display(const char *title, const alpm_list_t *list)
if(!list) {
printf("%s\n", _("None"));
} else {
- for(i = list, cols = len; i; i = alpm_list_next(i)) {
- char *str = alpm_list_getdata(i);
+ const int maxcols = getcols(0);
+ int cols = len;
+ const char *str = alpm_list_getdata(list);
+ printf("%s", str);
+ cols += string_length(str);
+ for(i = alpm_list_next(list), cols = len; i; i = alpm_list_next(i)) {
+ const char *str = alpm_list_getdata(i);
int s = string_length(str);
- int maxcols = getcols();
- if(maxcols > 0 && (cols + s + 2) >= maxcols) {
+ /* wrap only if we have enough usable column space */
+ if(maxcols > len && cols + s + 2 >= maxcols) {
int j;
cols = len;
printf("\n");
@@ -646,7 +651,7 @@ static alpm_list_t *create_verbose_header(int install)
pm_asprintf(&str, "%s", _("Size"));
res = alpm_list_add(res, str);
- return(res);
+ return res;
}
/* returns package info as list of strings */
@@ -656,7 +661,7 @@ static alpm_list_t *create_verbose_row(pmpkg_t *pkg, int install)
double size;
const char *label;
alpm_list_t *ret = NULL;
- pmdb_t *ldb = alpm_option_get_localdb();
+ pmdb_t *ldb = alpm_option_get_localdb(config->handle);
/* a row consists of the package name, */
pm_asprintf(&str, "%s", alpm_pkg_get_name(pkg));
@@ -678,7 +683,7 @@ static alpm_list_t *create_verbose_row(pmpkg_t *pkg, int install)
pm_asprintf(&str, "%.2f %s", size, label);
ret = alpm_list_add(ret, str);
- return(ret);
+ return ret;
}
/* prepare a list of pkgs to display */
@@ -688,8 +693,9 @@ void display_targets(const alpm_list_t *pkgs, int install)
const char *title, *label;
double size;
const alpm_list_t *i;
- off_t isize = 0, dlsize = 0;
+ off_t isize = 0, rsize = 0, dlsize = 0;
alpm_list_t *j, *lp, *header = NULL, *targets = NULL;
+ pmdb_t *db_local = alpm_option_get_localdb(config->handle);
if(!pkgs) {
return;
@@ -700,7 +706,12 @@ void display_targets(const alpm_list_t *pkgs, int install)
pmpkg_t *pkg = alpm_list_getdata(i);
if(install) {
+ pmpkg_t *lpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg));
dlsize += alpm_pkg_download_size(pkg);
+ if(lpkg) {
+ /* add up size of all removed packages */
+ rsize += alpm_pkg_get_isize(lpkg);
+ }
}
isize += alpm_pkg_get_isize(pkg);
@@ -736,6 +747,11 @@ void display_targets(const alpm_list_t *pkgs, int install)
if(!(config->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
size = humanize_size(isize, 'M', 1, &label);
printf(_("Total Installed Size: %.2f %s\n"), size, label);
+ /* only show this net value if different from raw installed size */
+ if(rsize > 0) {
+ size = humanize_size(isize - rsize, 'M', 1, &label);
+ printf(_("Net Upgrade Size: %.2f %s\n"), size, label);
+ }
}
} else {
size = humanize_size(isize, 'M', 1, &label);
@@ -772,22 +788,19 @@ static off_t pkg_get_size(pmpkg_t *pkg)
static char *pkg_get_location(pmpkg_t *pkg)
{
- pmdb_t *db;
- const char *dburl;
- char *string;
+ alpm_list_t *servers;
+ char *string = NULL;
switch(config->op) {
case PM_OP_SYNC:
- db = alpm_pkg_get_db(pkg);
- dburl = alpm_db_get_url(db);
- if(dburl) {
- char *pkgurl = NULL;
- pm_asprintf(&pkgurl, "%s/%s", dburl, alpm_pkg_get_filename(pkg));
- return pkgurl;
+ servers = alpm_db_get_servers(alpm_pkg_get_db(pkg));
+ if(servers) {
+ pm_asprintf(&string, "%s/%s", alpm_list_getdata(servers),
+ alpm_pkg_get_filename(pkg));
+ return string;
}
case PM_OP_UPGRADE:
return strdup(alpm_pkg_get_filename(pkg));
default:
- string = NULL;
pm_asprintf(&string, "%s-%s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
return string;
}
@@ -828,7 +841,7 @@ double humanize_size(off_t bytes, const char target_unit, int long_labels,
*label = labels[index];
}
- return(val);
+ return val;
}
void print_packages(const alpm_list_t *packages)
diff --git a/src/pacman/util.h b/src/pacman/util.h
index d8ae7d80..95c1ce92 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -42,7 +42,7 @@
int trans_init(pmtransflag_t flags);
int trans_release(void);
int needs_root(void);
-int getcols(void);
+int getcols(int def);
int rmrf(const char *path);
const char *mbasename(const char *path);
char *mdirname(const char *path);
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;