summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/add.c231
-rw-r--r--lib/libalpm/add.h2
-rw-r--r--lib/libalpm/alpm.c80
-rw-r--r--lib/libalpm/alpm.h203
-rw-r--r--lib/libalpm/alpm_list.c2
-rw-r--r--lib/libalpm/backup.c2
-rw-r--r--lib/libalpm/be_local.c116
-rw-r--r--lib/libalpm/be_package.c108
-rw-r--r--lib/libalpm/be_sync.c164
-rw-r--r--lib/libalpm/conflict.c197
-rw-r--r--lib/libalpm/conflict.h7
-rw-r--r--lib/libalpm/db.c221
-rw-r--r--lib/libalpm/db.h10
-rw-r--r--lib/libalpm/delta.c33
-rw-r--r--lib/libalpm/delta.h2
-rw-r--r--lib/libalpm/deps.c135
-rw-r--r--lib/libalpm/deps.h4
-rw-r--r--lib/libalpm/diskspace.c57
-rw-r--r--lib/libalpm/diskspace.h2
-rw-r--r--lib/libalpm/dload.c68
-rw-r--r--lib/libalpm/dload.h3
-rw-r--r--lib/libalpm/error.c13
-rw-r--r--lib/libalpm/graph.c13
-rw-r--r--lib/libalpm/group.c17
-rw-r--r--lib/libalpm/handle.c419
-rw-r--r--lib/libalpm/handle.h14
-rw-r--r--lib/libalpm/log.c22
-rw-r--r--lib/libalpm/log.h10
-rw-r--r--lib/libalpm/package.c63
-rw-r--r--lib/libalpm/package.h9
-rw-r--r--lib/libalpm/pkghash.c15
-rw-r--r--lib/libalpm/remove.c188
-rw-r--r--lib/libalpm/remove.h7
-rw-r--r--lib/libalpm/signing.c90
-rw-r--r--lib/libalpm/signing.h3
-rw-r--r--lib/libalpm/sync.c224
-rw-r--r--lib/libalpm/sync.h4
-rw-r--r--lib/libalpm/trans.c161
-rw-r--r--lib/libalpm/trans.h6
-rw-r--r--lib/libalpm/util.c177
-rw-r--r--lib/libalpm/util.h28
41 files changed, 1402 insertions, 1728 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index ee56e876..6f93c61d 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -37,7 +37,9 @@
/* libalpm */
#include "add.h"
+#include "alpm.h"
#include "alpm_list.h"
+#include "handle.h"
#include "trans.h"
#include "util.h"
#include "log.h"
@@ -48,33 +50,31 @@
#include "handle.h"
/** Add a package to the transaction. */
-int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
+int SYMEXPORT alpm_add_pkg(pmhandle_t *handle, pmpkg_t *pkg)
{
const char *pkgname, *pkgver;
pmtrans_t *trans;
- pmdb_t *db_local;
pmpkg_t *local;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- db_local = handle->db_local;
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_INITIALIZED,
+ RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1));
pkgname = pkg->name;
pkgver = pkg->version;
- _alpm_log(PM_LOG_DEBUG, "adding package '%s'\n", pkgname);
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package '%s'\n", pkgname);
if(_alpm_pkg_find(trans->add, pkgname)) {
- RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
+ RET_ERR(handle, PM_ERR_TRANS_DUP_TARGET, -1);
}
- local = _alpm_db_get_pkgfromcache(db_local, pkgname);
+ local = _alpm_db_get_pkgfromcache(handle->db_local, pkgname);
if(local) {
const char *localpkgname = alpm_pkg_get_name(local);
const char *localpkgver = alpm_pkg_get_version(local);
@@ -83,30 +83,30 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
if(cmp == 0) {
if(trans->flags & PM_TRANS_FLAG_NEEDED) {
/* with the NEEDED flag, packages up to date are not reinstalled */
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
localpkgname, localpkgver);
return 0;
- } else {
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"),
+ } else if(!(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
+ _alpm_log(handle, PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"),
localpkgname, localpkgver);
}
} else if(cmp < 0) {
/* local version is newer */
- _alpm_log(PM_LOG_WARNING, _("downgrading package %s (%s => %s)\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("downgrading package %s (%s => %s)\n"),
localpkgname, localpkgver, pkgver);
}
}
/* add the package to the transaction */
pkg->reason = PM_PKG_REASON_EXPLICIT;
- _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction add list\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package %s-%s to the transaction add list\n",
pkgname, pkgver);
trans->add = alpm_list_add(trans->add, pkg);
return 0;
}
-static int perform_extraction(struct archive *archive,
+static int perform_extraction(pmhandle_t *handle, struct archive *archive,
struct archive_entry *entry, const char *filename, const char *origname)
{
int ret;
@@ -119,21 +119,20 @@ static int perform_extraction(struct archive *archive,
ret = archive_read_extract(archive, entry, archive_flags);
if(ret == ARCHIVE_WARN && archive_errno(archive) != ENOSPC) {
/* operation succeeded but a "non-critical" error was encountered */
- _alpm_log(PM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
origname, archive_error_string(archive));
} else if(ret != ARCHIVE_OK) {
- _alpm_log(PM_LOG_ERROR, _("could not extract %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not extract %s (%s)\n"),
origname, archive_error_string(archive));
- alpm_logaction("error: could not extract %s (%s)\n",
+ alpm_logaction(handle, "error: could not extract %s (%s)\n",
origname, archive_error_string(archive));
return 1;
}
return 0;
}
-static int extract_single_file(struct archive *archive,
- struct archive_entry *entry, pmpkg_t *newpkg, pmpkg_t *oldpkg,
- pmtrans_t *trans, pmdb_t *db)
+static int extract_single_file(pmhandle_t *handle, struct archive *archive,
+ struct archive_entry *entry, pmpkg_t *newpkg, pmpkg_t *oldpkg)
{
const char *entryname;
mode_t entrymode;
@@ -151,17 +150,17 @@ static int extract_single_file(struct archive *archive,
if(strcmp(entryname, ".INSTALL") == 0) {
/* the install script goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(strcmp(entryname, ".CHANGELOG") == 0) {
/* the changelog goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/changelog",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(*entryname == '.') {
/* for now, ignore all files starting with '.' that haven't
* already been handled (for future possibilities) */
- _alpm_log(PM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
+ _alpm_log(handle, PM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
archive_read_data_skip(archive);
return 0;
} else {
@@ -171,9 +170,9 @@ static int extract_single_file(struct archive *archive,
/* if a file is in NoExtract then we never extract it */
if(alpm_list_find_str(handle->noextract, entryname)) {
- _alpm_log(PM_LOG_DEBUG, "%s is in NoExtract, skipping extraction\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s is in NoExtract, skipping extraction\n",
entryname);
- alpm_logaction("note: %s is in NoExtract, skipping extraction\n",
+ alpm_logaction(handle, "note: %s is in NoExtract, skipping extraction\n",
entryname);
archive_read_data_skip(archive);
return 0;
@@ -210,20 +209,20 @@ static int extract_single_file(struct archive *archive,
if(lsbuf.st_mode != entrymode) {
/* if filesystem perms are different than pkg perms, warn user */
mode_t mask = 07777;
- _alpm_log(PM_LOG_WARNING, _("directory permissions differ on %s\n"
+ _alpm_log(handle, PM_LOG_WARNING, _("directory permissions differ on %s\n"
"filesystem: %o package: %o\n"), entryname, lsbuf.st_mode & mask,
entrymode & mask);
- alpm_logaction("warning: directory permissions differ on %s\n"
+ alpm_logaction(handle, "warning: directory permissions differ on %s\n"
"filesystem: %o package: %o\n", entryname, lsbuf.st_mode & mask,
entrymode & mask);
}
- _alpm_log(PM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
entryname);
archive_read_data_skip(archive);
return 0;
} else {
/* case 10/11: trying to overwrite dir with file/symlink, don't allow it */
- _alpm_log(PM_LOG_ERROR, _("extract: not overwriting dir with file %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("extract: not overwriting dir with file %s\n"),
entryname);
archive_read_data_skip(archive);
return 1;
@@ -232,20 +231,20 @@ static int extract_single_file(struct archive *archive,
/* case 9: existing symlink, dir in package */
if(S_ISDIR(sbuf.st_mode)) {
/* the symlink on FS is to a directory, so we'll use it */
- _alpm_log(PM_LOG_DEBUG, "extract: skipping symlink overwrite of %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "extract: skipping symlink overwrite of %s\n",
entryname);
archive_read_data_skip(archive);
return 0;
} else {
/* this is BAD. symlink was not to a directory */
- _alpm_log(PM_LOG_ERROR, _("extract: symlink %s does not point to dir\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("extract: symlink %s does not point to dir\n"),
entryname);
archive_read_data_skip(archive);
return 1;
}
} else if(S_ISREG(lsbuf.st_mode) && S_ISDIR(entrymode)) {
/* case 6: trying to overwrite file with dir */
- _alpm_log(PM_LOG_DEBUG, "extract: overwriting file with dir %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "extract: overwriting file with dir %s\n",
entryname);
} else if(S_ISREG(entrymode)) {
/* case 4,7: */
@@ -269,7 +268,7 @@ static int extract_single_file(struct archive *archive,
/* if we force hash_orig to be non-NULL retroactive backup works */
if(needbackup && !hash_orig) {
- STRDUP(hash_orig, "", RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(hash_orig, "", RET_ERR(handle, PM_ERR_MEMORY, -1));
}
}
}
@@ -279,7 +278,7 @@ static int extract_single_file(struct archive *archive,
/* we need access to the original entryname later after calls to
* archive_entry_set_pathname(), so we need to dupe it and free() later */
- STRDUP(entryname_orig, entryname, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(entryname_orig, entryname, RET_ERR(handle, PM_ERR_MEMORY, -1));
if(needbackup) {
char checkfile[PATH_MAX];
@@ -288,7 +287,7 @@ static int extract_single_file(struct archive *archive,
snprintf(checkfile, PATH_MAX, "%s.paccheck", filename);
- ret = perform_extraction(archive, entry, checkfile, entryname_orig);
+ ret = perform_extraction(handle, archive, entry, checkfile, entryname_orig);
if(ret == 1) {
/* error */
FREE(hash_orig);
@@ -311,7 +310,7 @@ static int extract_single_file(struct archive *archive,
char *backup = NULL;
/* length is tab char, null byte and MD5 (32 char) */
size_t backup_len = strlen(oldbackup) + 34;
- MALLOC(backup, backup_len, RET_ERR(PM_ERR_MEMORY, -1));
+ MALLOC(backup, backup_len, RET_ERR(handle, PM_ERR_MEMORY, -1));
sprintf(backup, "%s\t%s", oldbackup, hash_pkg);
backup[backup_len-1] = '\0';
@@ -319,10 +318,10 @@ static int extract_single_file(struct archive *archive,
backups->data = backup;
}
- _alpm_log(PM_LOG_DEBUG, "checking hashes for %s\n", entryname_orig);
- _alpm_log(PM_LOG_DEBUG, "current: %s\n", hash_local);
- _alpm_log(PM_LOG_DEBUG, "new: %s\n", hash_pkg);
- _alpm_log(PM_LOG_DEBUG, "original: %s\n", hash_orig);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking hashes for %s\n", entryname_orig);
+ _alpm_log(handle, PM_LOG_DEBUG, "current: %s\n", hash_local);
+ _alpm_log(handle, PM_LOG_DEBUG, "new: %s\n", hash_pkg);
+ _alpm_log(handle, PM_LOG_DEBUG, "original: %s\n", hash_orig);
if(!oldpkg) {
if(strcmp(hash_local, hash_pkg) != 0) {
@@ -333,22 +332,22 @@ static int extract_single_file(struct archive *archive,
/* move the existing file to the "pacorig" */
if(rename(filename, newpath)) {
- _alpm_log(PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
filename, newpath, strerror(errno));
- alpm_logaction("error: could not rename %s to %s (%s)\n",
+ alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
filename, newpath, strerror(errno));
errors++;
} else {
/* rename the file we extracted to the real name */
if(rename(checkfile, filename)) {
- _alpm_log(PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
checkfile, filename, strerror(errno));
- alpm_logaction("error: could not rename %s to %s (%s)\n",
+ alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
checkfile, filename, strerror(errno));
errors++;
} else {
- _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), filename, newpath);
- alpm_logaction("warning: %s saved as %s\n", filename, newpath);
+ _alpm_log(handle, PM_LOG_WARNING, _("%s saved as %s\n"), filename, newpath);
+ alpm_logaction(handle, "warning: %s saved as %s\n", filename, newpath);
}
}
} else {
@@ -361,48 +360,48 @@ static int extract_single_file(struct archive *archive,
if(strcmp(hash_orig, hash_local) == 0) {
/* installed file has NOT been changed by user */
if(strcmp(hash_orig, hash_pkg) != 0) {
- _alpm_log(PM_LOG_DEBUG, "action: installing new file: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "action: installing new file: %s\n",
entryname_orig);
if(rename(checkfile, filename)) {
- _alpm_log(PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
checkfile, filename, strerror(errno));
- alpm_logaction("error: could not rename %s to %s (%s)\n",
+ alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
checkfile, filename, strerror(errno));
errors++;
}
} else {
/* there's no sense in installing the same file twice, install
* ONLY is the original and package hashes differ */
- _alpm_log(PM_LOG_DEBUG, "action: leaving existing file in place\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile);
}
} else if(strcmp(hash_orig, hash_pkg) == 0) {
/* originally installed file and new file are the same - this
* implies the case above failed - i.e. the file was changed by a
* user */
- _alpm_log(PM_LOG_DEBUG, "action: leaving existing file in place\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile);
} else if(strcmp(hash_local, hash_pkg) == 0) {
/* this would be magical. The above two cases failed, but the
* user changes just so happened to make the new file exactly the
* same as the one in the package... skip it */
- _alpm_log(PM_LOG_DEBUG, "action: leaving existing file in place\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile);
} else {
char newpath[PATH_MAX];
- _alpm_log(PM_LOG_DEBUG, "action: keeping current file and installing"
+ _alpm_log(handle, PM_LOG_DEBUG, "action: keeping current file and installing"
" new one with .pacnew ending\n");
snprintf(newpath, PATH_MAX, "%s.pacnew", filename);
if(rename(checkfile, newpath)) {
- _alpm_log(PM_LOG_ERROR, _("could not install %s as %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not install %s as %s (%s)\n"),
filename, newpath, strerror(errno));
- alpm_logaction("error: could not install %s as %s (%s)\n",
+ alpm_logaction(handle, "error: could not install %s as %s (%s)\n",
filename, newpath, strerror(errno));
} else {
- _alpm_log(PM_LOG_WARNING, _("%s installed as %s\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("%s installed as %s\n"),
filename, newpath);
- alpm_logaction("warning: %s installed as %s\n",
+ alpm_logaction(handle, "warning: %s installed as %s\n",
filename, newpath);
}
}
@@ -417,22 +416,22 @@ static int extract_single_file(struct archive *archive,
/* we didn't need a backup */
if(notouch) {
/* change the path to a .pacnew extension */
- _alpm_log(PM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
- _alpm_log(PM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename);
- alpm_logaction("warning: extracting %s as %s.pacnew\n", filename, filename);
+ _alpm_log(handle, PM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
+ _alpm_log(handle, PM_LOG_WARNING, _("extracting %s as %s.pacnew\n"), filename, filename);
+ alpm_logaction(handle, "warning: extracting %s as %s.pacnew\n", filename, filename);
strncat(filename, ".pacnew", PATH_MAX - strlen(filename));
} else {
- _alpm_log(PM_LOG_DEBUG, "extracting %s\n", filename);
+ _alpm_log(handle, PM_LOG_DEBUG, "extracting %s\n", filename);
}
- if(trans->flags & PM_TRANS_FLAG_FORCE) {
+ if(handle->trans->flags & PM_TRANS_FLAG_FORCE) {
/* if FORCE was used, unlink() each file (whether it's there
* or not) before extracting. This prevents the old "Text file busy"
* error that crops up if forcing a glibc or pacman upgrade. */
unlink(filename);
}
- ret = perform_extraction(archive, entry, filename, entryname_orig);
+ ret = perform_extraction(handle, archive, entry, filename, entryname_orig);
if(ret == 1) {
/* error */
FREE(entryname_orig);
@@ -450,10 +449,10 @@ static int extract_single_file(struct archive *archive,
if(!oldbackup || strcmp(oldbackup, entryname_orig) != 0) {
continue;
}
- _alpm_log(PM_LOG_DEBUG, "appending backup entry for %s\n", filename);
+ _alpm_log(handle, PM_LOG_DEBUG, "appending backup entry for %s\n", filename);
hash = alpm_compute_md5sum(filename);
- MALLOC(backup, backup_len, RET_ERR(PM_ERR_MEMORY, -1));
+ MALLOC(backup, backup_len, RET_ERR(handle, PM_ERR_MEMORY, -1));
sprintf(backup, "%s\t%s", oldbackup, hash);
backup[backup_len-1] = '\0';
@@ -466,17 +465,15 @@ static int extract_single_file(struct archive *archive,
return errors;
}
-static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
- size_t pkg_count, pmtrans_t *trans, pmdb_t *db)
+static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg,
+ size_t pkg_current, size_t pkg_count)
{
int i, ret = 0, errors = 0;
- char scriptlet[PATH_MAX+1];
+ char scriptlet[PATH_MAX];
int is_upgrade = 0;
pmpkg_t *oldpkg = NULL;
-
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmdb_t *db = handle->db_local;
+ pmtrans_t *trans = handle->trans;
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
_alpm_db_path(db), alpm_pkg_get_name(newpkg),
@@ -494,7 +491,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
_alpm_local_db_read(oldpkg->origin_data.db, oldpkg, INFRQ_ALL);
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg);
- _alpm_log(PM_LOG_DEBUG, "upgrading package %s-%s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "upgrading package %s-%s\n",
newpkg->name, newpkg->version);
/* copy over the install reason */
@@ -502,20 +499,20 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, newpkg->origin_data.file,
- "pre_upgrade", newpkg->version, oldpkg->version, trans);
+ _alpm_runscriptlet(handle, newpkg->origin_data.file,
+ "pre_upgrade", newpkg->version, oldpkg->version);
}
} else {
is_upgrade = 0;
EVENT(trans, PM_TRANS_EVT_ADD_START, newpkg, NULL);
- _alpm_log(PM_LOG_DEBUG, "adding package %s-%s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package %s-%s\n",
newpkg->name, newpkg->version);
/* pre_install scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, newpkg->origin_data.file,
- "pre_install", newpkg->version, NULL, trans);
+ _alpm_runscriptlet(handle, newpkg->origin_data.file,
+ "pre_install", newpkg->version, NULL);
}
}
@@ -528,8 +525,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(oldpkg) {
/* set up fake remove transaction */
- if(_alpm_upgraderemove_package(oldpkg, newpkg, trans) == -1) {
- pm_errno = PM_ERR_TRANS_ABORT;
+ if(_alpm_upgraderemove_package(handle, oldpkg, newpkg) == -1) {
+ handle->pm_errno = PM_ERR_TRANS_ABORT;
ret = -1;
goto cleanup;
}
@@ -538,9 +535,9 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* prepare directory for database entries so permission are correct after
changelog/install script installation (FS#12263) */
if(_alpm_local_db_prepare(db, newpkg)) {
- alpm_logaction("error: could not create database entry %s-%s\n",
+ alpm_logaction(handle, "error: could not create database entry %s-%s\n",
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
- pm_errno = PM_ERR_DB_WRITE;
+ handle->pm_errno = PM_ERR_DB_WRITE;
ret = -1;
goto cleanup;
}
@@ -551,10 +548,10 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
char cwd[PATH_MAX] = "";
int restore_cwd = 0;
- _alpm_log(PM_LOG_DEBUG, "extracting files\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "extracting files\n");
if((archive = archive_read_new()) == NULL) {
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
ret = -1;
goto cleanup;
}
@@ -562,24 +559,25 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
- _alpm_log(PM_LOG_DEBUG, "archive: %s\n", newpkg->origin_data.file);
+ _alpm_log(handle, PM_LOG_DEBUG, "archive: %s\n", newpkg->origin_data.file);
if(archive_read_open_filename(archive, newpkg->origin_data.file,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- pm_errno = PM_ERR_PKG_OPEN;
+ handle->pm_errno = PM_ERR_PKG_OPEN;
ret = -1;
goto cleanup;
}
/* save the cwd so we can restore it later */
if(getcwd(cwd, PATH_MAX) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not get current working directory\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not get current working directory\n"));
} else {
restore_cwd = 1;
}
/* libarchive requires this for extracting hard links */
if(chdir(handle->root) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), handle->root, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
+ handle->root, strerror(errno));
ret = -1;
goto cleanup;
}
@@ -602,7 +600,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
* (missing metadata sizes) */
int64_t pos = archive_position_compressed(archive);
percent = (pos * 100) / newpkg->size;
- _alpm_log(PM_LOG_DEBUG, "decompression progress: "
+ _alpm_log(handle, PM_LOG_DEBUG, "decompression progress: "
"%d%% (%"PRId64" / %jd)\n",
percent, pos, (intmax_t)newpkg->size);
if(percent >= 100) {
@@ -623,27 +621,26 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
}
/* extract the next file from the archive */
- errors += extract_single_file(archive, entry, newpkg, oldpkg,
- trans, db);
+ errors += extract_single_file(handle, archive, entry, newpkg, oldpkg);
}
archive_read_finish(archive);
/* restore the old cwd if we have it */
if(restore_cwd && chdir(cwd) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
}
if(errors) {
ret = -1;
if(is_upgrade) {
- _alpm_log(PM_LOG_ERROR, _("problem occurred while upgrading %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("problem occurred while upgrading %s\n"),
newpkg->name);
- alpm_logaction("error: problem occurred while upgrading %s\n",
+ alpm_logaction(handle, "error: problem occurred while upgrading %s\n",
newpkg->name);
} else {
- _alpm_log(PM_LOG_ERROR, _("problem occurred while installing %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("problem occurred while installing %s\n"),
newpkg->name);
- alpm_logaction("error: problem occurred while installing %s\n",
+ alpm_logaction(handle, "error: problem occurred while installing %s\n",
newpkg->name);
}
}
@@ -652,21 +649,21 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* make an install date (in UTC) */
newpkg->installdate = time(NULL);
- _alpm_log(PM_LOG_DEBUG, "updating database\n");
- _alpm_log(PM_LOG_DEBUG, "adding database entry '%s'\n", newpkg->name);
+ _alpm_log(handle, PM_LOG_DEBUG, "updating database\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "adding database entry '%s'\n", newpkg->name);
if(_alpm_local_db_write(db, newpkg, INFRQ_ALL)) {
- _alpm_log(PM_LOG_ERROR, _("could not update database entry %s-%s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not update database entry %s-%s\n"),
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
- alpm_logaction("error: could not update database entry %s-%s\n",
+ alpm_logaction(handle, "error: could not update database entry %s-%s\n",
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
- pm_errno = PM_ERR_DB_WRITE;
+ handle->pm_errno = PM_ERR_DB_WRITE;
ret = -1;
goto cleanup;
}
if(_alpm_db_add_pkgincache(db, newpkg) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not add entry '%s' in cache\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not add entry '%s' in cache\n"),
alpm_pkg_get_name(newpkg));
}
@@ -682,12 +679,12 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(alpm_pkg_has_scriptlet(newpkg)
&& !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
if(is_upgrade) {
- _alpm_runscriptlet(handle->root, scriptlet, "post_upgrade",
+ _alpm_runscriptlet(handle, scriptlet, "post_upgrade",
alpm_pkg_get_version(newpkg),
- oldpkg ? alpm_pkg_get_version(oldpkg) : NULL, trans);
+ oldpkg ? alpm_pkg_get_version(oldpkg) : NULL);
} else {
- _alpm_runscriptlet(handle->root, scriptlet, "post_install",
- alpm_pkg_get_version(newpkg), NULL, trans);
+ _alpm_runscriptlet(handle, scriptlet, "post_install",
+ alpm_pkg_get_version(newpkg), NULL);
}
}
@@ -702,16 +699,12 @@ cleanup:
return ret;
}
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
+int _alpm_upgrade_packages(pmhandle_t *handle)
{
size_t pkg_count, pkg_current;
int skip_ldconfig = 0, ret = 0;
alpm_list_t *targ;
-
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ pmtrans_t *trans = handle->trans;
if(trans->add == NULL) {
return 0;
@@ -727,10 +720,10 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
}
pmpkg_t *newpkg = (pmpkg_t *)targ->data;
- if(commit_single_pkg(newpkg, pkg_current, pkg_count, trans, db)) {
+ if(commit_single_pkg(handle, newpkg, pkg_current, pkg_count)) {
/* something screwed up on the commit, abort the trans */
trans->state = STATE_INTERRUPTED;
- pm_errno = PM_ERR_TRANS_ABORT;
+ handle->pm_errno = PM_ERR_TRANS_ABORT;
/* running ldconfig at this point could possibly screw system */
skip_ldconfig = 1;
ret = -1;
@@ -741,7 +734,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
if(!skip_ldconfig) {
/* run ldconfig if it exists */
- _alpm_ldconfig(handle->root);
+ _alpm_ldconfig(handle);
}
return ret;
diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h
index afc7be26..1baab8d4 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/add.h
@@ -24,7 +24,7 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
+int _alpm_upgrade_packages(pmhandle_t *handle);
#endif /* _ALPM_ADD_H */
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index bafd922b..5d475ce4 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -31,11 +31,9 @@
#include "alpm.h"
#include "alpm_list.h"
#include "handle.h"
+#include "log.h"
#include "util.h"
-/* Globals */
-enum _pmerrno_t pm_errno SYMEXPORT;
-
/** \addtogroup alpm_interface Interface Functions
* @brief Functions to initialize and release libalpm
* @{
@@ -43,21 +41,37 @@ enum _pmerrno_t pm_errno SYMEXPORT;
/** Initializes the library. This must be called before any other
* functions are called.
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ * @param root the root path for all filesystem operations
+ * @param dbpath the absolute path to the libalpm database
+ * @param err an optional variable to hold any error return codes
+ * @return a context handle on success, NULL on error, err will be set if provided
*/
-int SYMEXPORT alpm_initialize(void)
+pmhandle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
+ enum _pmerrno_t *err)
{
- ASSERT(handle == NULL, RET_ERR(PM_ERR_HANDLE_NOT_NULL, -1));
-
- handle = _alpm_handle_new();
- if(handle == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ enum _pmerrno_t myerr;
+ const char *lf = "db.lck";
+ size_t lockfilelen;
+ pmhandle_t *myhandle = _alpm_handle_new();
+
+ if(myhandle == NULL) {
+ myerr = PM_ERR_MEMORY;
+ goto cleanup;
+ }
+ if((myerr = _alpm_set_directory_option(root, &(myhandle->root), 1))) {
+ goto cleanup;
}
- if(_alpm_db_register_local() == NULL) {
- /* error code should be set */
- _alpm_handle_free(handle);
- handle = NULL;
- return -1;
+ if((myerr = _alpm_set_directory_option(dbpath, &(myhandle->dbpath), 1))) {
+ goto cleanup;
+ }
+
+ lockfilelen = strlen(myhandle->dbpath) + strlen(lf) + 1;
+ myhandle->lockfile = calloc(lockfilelen, sizeof(char));
+ snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
+
+ if(_alpm_db_register_local(myhandle) == NULL) {
+ myerr = PM_ERR_DB_CREATE;
+ goto cleanup;
}
#ifdef ENABLE_NLS
@@ -66,42 +80,50 @@ int SYMEXPORT alpm_initialize(void)
#ifdef HAVE_LIBCURL
curl_global_init(CURL_GLOBAL_SSL);
- handle->curl = curl_easy_init();
+ myhandle->curl = curl_easy_init();
#endif
- return 0;
+ return myhandle;
+
+cleanup:
+ _alpm_handle_free(myhandle);
+ if(err && myerr) {
+ *err = myerr;
+ }
+ return NULL;
}
/** Release the library. This should be the last alpm call you make.
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ * After this returns, handle should be considered invalid and cannot be reused
+ * in any way.
+ * @param handle the context handle
+ * @return 0 on success, -1 on error
*/
-int SYMEXPORT alpm_release(void)
+int SYMEXPORT alpm_release(pmhandle_t *myhandle)
{
+ int ret = 0;
pmdb_t *db;
- ALPM_LOG_FUNC;
-
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(myhandle != NULL, return -1);
/* close local database */
- db = handle->db_local;
+ db = myhandle->db_local;
if(db) {
db->ops->unregister(db);
- handle->db_local = NULL;
+ myhandle->db_local = NULL;
}
- if(alpm_db_unregister_all() == -1) {
- return -1;
+ if(alpm_db_unregister_all(myhandle) == -1) {
+ ret = -1;
}
- _alpm_handle_free(handle);
- handle = NULL;
+ _alpm_handle_free(myhandle);
#ifdef HAVE_LIBCURL
curl_global_cleanup();
#endif
- return 0;
+ return ret;
}
/** @} */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 5af843c4..845bd478 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -74,6 +74,7 @@ typedef enum _pgp_verify_t {
* Structures
*/
+typedef struct __pmhandle_t pmhandle_t;
typedef struct __pmdb_t pmdb_t;
typedef struct __pmpkg_t pmpkg_t;
typedef struct __pmdelta_t pmdelta_t;
@@ -85,14 +86,6 @@ typedef struct __pmconflict_t pmconflict_t;
typedef struct __pmfileconflict_t pmfileconflict_t;
/*
- * Library
- */
-
-int alpm_initialize(void);
-int alpm_release(void);
-const char *alpm_version(void);
-
-/*
* Logging facilities
*/
@@ -107,7 +100,7 @@ typedef enum _pmloglevel_t {
} pmloglevel_t;
typedef void (*alpm_cb_log)(pmloglevel_t, const char *, va_list);
-int alpm_logaction(const char *fmt, ...);
+int alpm_logaction(pmhandle_t *handle, const char *fmt, ...);
/*
* Downloading
@@ -134,10 +127,11 @@ typedef int (*alpm_cb_fetch)(const char *url, const char *localpath,
int force);
/** Fetch a remote pkg.
+ * @param handle the context handle
* @param url URL of the package to download
* @return the downloaded filepath on success, NULL on error
*/
-char *alpm_fetch_pkgurl(const char *url);
+char *alpm_fetch_pkgurl(pmhandle_t *handle, const char *url);
/** @addtogroup alpm_api_options Options
* Libalpm option getters and setters
@@ -145,77 +139,67 @@ char *alpm_fetch_pkgurl(const char *url);
*/
/** Returns the callback used for logging. */
-alpm_cb_log alpm_option_get_logcb(void);
+alpm_cb_log alpm_option_get_logcb(pmhandle_t *handle);
/** Sets the callback used for logging. */
-int alpm_option_set_logcb(alpm_cb_log cb);
+int alpm_option_set_logcb(pmhandle_t *handle, alpm_cb_log cb);
/** Returns the callback used to report download progress. */
-alpm_cb_download alpm_option_get_dlcb(void);
+alpm_cb_download alpm_option_get_dlcb(pmhandle_t *handle);
/** Sets the callback used to report download progress. */
-int alpm_option_set_dlcb(alpm_cb_download cb);
+int alpm_option_set_dlcb(pmhandle_t *handle, alpm_cb_download cb);
/** Returns the downloading callback. */
-alpm_cb_fetch alpm_option_get_fetchcb(void);
+alpm_cb_fetch alpm_option_get_fetchcb(pmhandle_t *handle);
/** Sets the downloading callback. */
-int alpm_option_set_fetchcb(alpm_cb_fetch cb);
+int alpm_option_set_fetchcb(pmhandle_t *handle, alpm_cb_fetch cb);
/** Returns the callback used to report total download size. */
-alpm_cb_totaldl alpm_option_get_totaldlcb(void);
+alpm_cb_totaldl alpm_option_get_totaldlcb(pmhandle_t *handle);
/** Sets the callback used to report total download size. */
-int alpm_option_set_totaldlcb(alpm_cb_totaldl cb);
+int alpm_option_set_totaldlcb(pmhandle_t *handle, alpm_cb_totaldl cb);
+
+/** Returns the root of the destination filesystem. Read-only. */
+const char *alpm_option_get_root(pmhandle_t *handle);
-/** Returns the root of the destination filesystem. */
-const char *alpm_option_get_root(void);
-/** Sets the root of the destination filesystem. */
-int alpm_option_set_root(const char *root);
+/** Returns the path to the database directory. Read-only. */
+const char *alpm_option_get_dbpath(pmhandle_t *handle);
-/** Returns the path to the database directory. */
-const char *alpm_option_get_dbpath(void);
-/** Sets the path to the database directory. */
-int alpm_option_set_dbpath(const char *dbpath);
+/** Get the name of the database lock file. Read-only. */
+const char *alpm_option_get_lockfile(pmhandle_t *handle);
/** @name Accessors to the list of package cache directories.
* @{
*/
-alpm_list_t *alpm_option_get_cachedirs(void);
-int alpm_option_set_cachedirs(alpm_list_t *cachedirs);
-int alpm_option_add_cachedir(const char *cachedir);
-int alpm_option_remove_cachedir(const char *cachedir);
+alpm_list_t *alpm_option_get_cachedirs(pmhandle_t *handle);
+int alpm_option_set_cachedirs(pmhandle_t *handle, alpm_list_t *cachedirs);
+int alpm_option_add_cachedir(pmhandle_t *handle, const char *cachedir);
+int alpm_option_remove_cachedir(pmhandle_t *handle, const char *cachedir);
/** @} */
/** Returns the logfile name. */
-const char *alpm_option_get_logfile(void);
+const char *alpm_option_get_logfile(pmhandle_t *handle);
/** Sets the logfile name. */
-int alpm_option_set_logfile(const char *logfile);
-
-/** Get the name of the database lock file.
- *
- * This properly is read-only, and determined from
- * the database path.
- *
- * @sa alpm_option_set_dbpath(const char*)
- */
-const char *alpm_option_get_lockfile(void);
+int alpm_option_set_logfile(pmhandle_t *handle, const char *logfile);
/** Returns the signature directory path. */
-const char *alpm_option_get_signaturedir(void);
+const char *alpm_option_get_signaturedir(pmhandle_t *handle);
/** Sets the signature directory path. */
-int alpm_option_set_signaturedir(const char *signaturedir);
+int alpm_option_set_signaturedir(pmhandle_t *handle, const char *signaturedir);
/** Returns whether to use syslog (0 is FALSE, TRUE otherwise). */
-int alpm_option_get_usesyslog(void);
+int alpm_option_get_usesyslog(pmhandle_t *handle);
/** Sets whether to use syslog (0 is FALSE, TRUE otherwise). */
-int alpm_option_set_usesyslog(int usesyslog);
+int alpm_option_set_usesyslog(pmhandle_t *handle, int usesyslog);
/** @name Accessors to the list of no-upgrade files.
* These functions modify the list of files which should
* not be updated by package installation.
* @{
*/
-alpm_list_t *alpm_option_get_noupgrades(void);
-int alpm_option_add_noupgrade(const char *pkg);
-int alpm_option_set_noupgrades(alpm_list_t *noupgrade);
-int alpm_option_remove_noupgrade(const char *pkg);
+alpm_list_t *alpm_option_get_noupgrades(pmhandle_t *handle);
+int alpm_option_add_noupgrade(pmhandle_t *handle, const char *pkg);
+int alpm_option_set_noupgrades(pmhandle_t *handle, alpm_list_t *noupgrade);
+int alpm_option_remove_noupgrade(pmhandle_t *handle, const char *pkg);
/** @} */
/** @name Accessors to the list of no-extract files.
@@ -224,10 +208,10 @@ int alpm_option_remove_noupgrade(const char *pkg);
* not be upgraded by a sysupgrade operation.
* @{
*/
-alpm_list_t *alpm_option_get_noextracts(void);
-int alpm_option_add_noextract(const char *pkg);
-int alpm_option_set_noextracts(alpm_list_t *noextract);
-int alpm_option_remove_noextract(const char *pkg);
+alpm_list_t *alpm_option_get_noextracts(pmhandle_t *handle);
+int alpm_option_add_noextract(pmhandle_t *handle, const char *pkg);
+int alpm_option_set_noextracts(pmhandle_t *handle, alpm_list_t *noextract);
+int alpm_option_remove_noextract(pmhandle_t *handle, const char *pkg);
/** @} */
/** @name Accessors to the list of ignored packages.
@@ -235,10 +219,10 @@ int alpm_option_remove_noextract(const char *pkg);
* should be ignored by a sysupgrade.
* @{
*/
-alpm_list_t *alpm_option_get_ignorepkgs(void);
-int alpm_option_add_ignorepkg(const char *pkg);
-int alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs);
-int alpm_option_remove_ignorepkg(const char *pkg);
+alpm_list_t *alpm_option_get_ignorepkgs(pmhandle_t *handle);
+int alpm_option_add_ignorepkg(pmhandle_t *handle, const char *pkg);
+int alpm_option_set_ignorepkgs(pmhandle_t *handle, alpm_list_t *ignorepkgs);
+int alpm_option_remove_ignorepkg(pmhandle_t *handle, const char *pkg);
/** @} */
/** @name Accessors to the list of ignored groups.
@@ -246,25 +230,25 @@ int alpm_option_remove_ignorepkg(const char *pkg);
* should be ignored by a sysupgrade.
* @{
*/
-alpm_list_t *alpm_option_get_ignoregrps(void);
-int alpm_option_add_ignoregrp(const char *grp);
-int alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
-int alpm_option_remove_ignoregrp(const char *grp);
+alpm_list_t *alpm_option_get_ignoregrps(pmhandle_t *handle);
+int alpm_option_add_ignoregrp(pmhandle_t *handle, const char *grp);
+int alpm_option_set_ignoregrps(pmhandle_t *handle, alpm_list_t *ignoregrps);
+int alpm_option_remove_ignoregrp(pmhandle_t *handle, const char *grp);
/** @} */
/** Returns the targeted architecture. */
-const char *alpm_option_get_arch(void);
+const char *alpm_option_get_arch(pmhandle_t *handle);
/** Sets the targeted architecture. */
-int alpm_option_set_arch(const char *arch);
+int alpm_option_set_arch(pmhandle_t *handle, const char *arch);
-int alpm_option_get_usedelta(void);
-int alpm_option_set_usedelta(int usedelta);
+int alpm_option_get_usedelta(pmhandle_t *handle);
+int alpm_option_set_usedelta(pmhandle_t *handle, int usedelta);
-int alpm_option_get_checkspace(void);
-int alpm_option_set_checkspace(int checkspace);
+int alpm_option_get_checkspace(pmhandle_t *handle);
+int alpm_option_set_checkspace(pmhandle_t *handle, int checkspace);
-pgp_verify_t alpm_option_get_default_sigverify(void);
-int alpm_option_set_default_sigverify(pgp_verify_t level);
+pgp_verify_t alpm_option_get_default_sigverify(pmhandle_t *handle);
+int alpm_option_set_default_sigverify(pmhandle_t *handle, pgp_verify_t level);
/** @} */
@@ -279,20 +263,22 @@ int alpm_option_set_default_sigverify(pgp_verify_t level);
* libalpm functions.
* @return a reference to the local database
*/
-pmdb_t *alpm_option_get_localdb(void);
+pmdb_t *alpm_option_get_localdb(pmhandle_t *handle);
/** Get the list of sync databases.
* Returns a list of pmdb_t structures, one for each registered
* sync database.
+ * @param handle the context handle
* @return a reference to an internal list of pmdb_t structures
*/
-alpm_list_t *alpm_option_get_syncdbs(void);
+alpm_list_t *alpm_option_get_syncdbs(pmhandle_t *handle);
/** Register a sync database of packages.
+ * @param handle the context handle
* @param treename the name of the sync repository
* @return a pmdb_t* on success (the value), NULL on error
*/
-pmdb_t *alpm_db_register_sync(const char *treename);
+pmdb_t *alpm_db_register_sync(pmhandle_t *handle, const char *treename);
/** Unregister a package database.
* @param db pointer to the package database to unregister
@@ -301,9 +287,10 @@ pmdb_t *alpm_db_register_sync(const char *treename);
int alpm_db_unregister(pmdb_t *db);
/** Unregister all package databases.
+ * @param handle the context handle
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_db_unregister_all(void);
+int alpm_db_unregister_all(pmhandle_t *handle);
/** Get the name of a package database.
* @param db pointer to the package database
@@ -311,12 +298,6 @@ int alpm_db_unregister_all(void);
*/
const char *alpm_db_get_name(const pmdb_t *db);
-/** Get a download URL for the package database.
- * @param db pointer to the package database
- * @return a fully-specified download URL, NULL on error
- */
-const char *alpm_db_get_url(const pmdb_t *db);
-
/** @name Accessors to the list of servers for a database.
* @{
*/
@@ -381,6 +362,7 @@ int alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason);
* metadata is found. If it is true, the entire archive is read, which
* serves as a verification of integrity and the filelist can be created.
* The allocated structure should be freed using alpm_pkg_free().
+ * @param handle the context handle
* @param filename location of the package tarball
* @param full whether to stop the load after metadata is read or continue
* through the full archive
@@ -389,8 +371,8 @@ int alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason);
* @param pkg address of the package pointer
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_pkg_load(const char *filename, int full, pgp_verify_t check_sig,
- pmpkg_t **pkg);
+int alpm_pkg_load(pmhandle_t *handle, const char *filename, int full,
+ pgp_verify_t check_sig, pmpkg_t **pkg);
/** Free a package.
* @param pkg package pointer to free
@@ -809,78 +791,89 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, size_t, size_t);
/** Returns the bitfield of flags for the current transaction.
- * @sa _pmtransflag_t
+ * @param handle the context handle
+ * @return the bitfield of transaction flags
*/
-int alpm_trans_get_flags(void);
+pmtransflag_t alpm_trans_get_flags(pmhandle_t *handle);
/** Returns a list of packages added by the transaction.
+ * @param handle the context handle
* @return a list of pmpkg_t structures
*/
-alpm_list_t * alpm_trans_get_add(void);
+alpm_list_t * alpm_trans_get_add(pmhandle_t *handle);
/** Returns the list of packages removed by the transaction.
+ * @param handle the context handle
* @return a list of pmpkg_t structures
*/
-alpm_list_t * alpm_trans_get_remove(void);
+alpm_list_t * alpm_trans_get_remove(pmhandle_t *handle);
/** Initialize the transaction.
+ * @param handle the context handle
* @param flags flags of the transaction (like nodeps, etc)
* @param event event callback function pointer
* @param conv question callback function pointer
* @param progress progress callback function pointer
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_trans_init(pmtransflag_t flags,
+int alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress cb_progress);
/** Prepare a transaction.
+ * @param handle the context handle
* @param data the address of an alpm_list where a list
* of pmdepmissing_t objects is dumped (conflicting packages)
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_trans_prepare(alpm_list_t **data);
+int alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data);
/** Commit a transaction.
+ * @param handle the context handle
* @param data the address of an alpm_list where detailed description
* of an error can be dumped (ie. list of conflicting files)
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_trans_commit(alpm_list_t **data);
+int alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data);
/** Interrupt a transaction.
+ * @param handle the context handle
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_trans_interrupt(void);
+int alpm_trans_interrupt(pmhandle_t *handle);
/** Release a transaction.
+ * @param handle the context handle
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_trans_release(void);
+int alpm_trans_release(pmhandle_t *handle);
/** @} */
/** @name Common Transactions */
/** @{ */
/** Search for packages to upgrade and add them to the transaction.
+ * @param handle the context handle
* @param enable_downgrade allow downgrading of packages if the remote version is lower
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_sync_sysupgrade(int enable_downgrade);
+int alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade);
/** Add a package to the transaction.
* If the package was loaded by alpm_pkg_load(), it will be freed upon
* alpm_trans_release() invocation.
+ * @param handle the context handle
* @param pkg the package to add
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_add_pkg(pmpkg_t *pkg);
+int alpm_add_pkg(pmhandle_t *handle, pmpkg_t *pkg);
/** Add a package removal action to the transaction.
+ * @param handle the context handle
* @param pkg the package to uninstall
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int alpm_remove_pkg(pmpkg_t *pkg);
+int alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg);
/** @} */
@@ -906,16 +899,17 @@ typedef enum _pmdepmod_t {
PM_DEP_MOD_LT
} pmdepmod_t;
-alpm_list_t *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
- alpm_list_t *remove, alpm_list_t *upgrade);
+alpm_list_t *alpm_checkdeps(pmhandle_t *handle, alpm_list_t *pkglist,
+ alpm_list_t *remove, alpm_list_t *upgrade, int reversedeps);
pmpkg_t *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring);
-pmpkg_t *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstring);
+pmpkg_t *alpm_find_dbs_satisfier(pmhandle_t *handle,
+ alpm_list_t *dbs, const char *depstring);
const char *alpm_miss_get_target(const pmdepmissing_t *miss);
pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss);
const char *alpm_miss_get_causingpkg(const pmdepmissing_t *miss);
-alpm_list_t *alpm_checkconflicts(alpm_list_t *pkglist);
+alpm_list_t *alpm_checkconflicts(pmhandle_t *handle, alpm_list_t *pkglist);
const char *alpm_conflict_get_package1(pmconflict_t *conflict);
const char *alpm_conflict_get_package2(pmconflict_t *conflict);
@@ -1032,7 +1026,6 @@ enum _pmerrno_t {
PM_ERR_FILE_CONFLICTS,
/* Misc */
PM_ERR_RETRIEVE,
- PM_ERR_WRITE,
PM_ERR_INVALID_REGEX,
/* External library errors */
PM_ERR_LIBARCHIVE,
@@ -1041,18 +1034,20 @@ enum _pmerrno_t {
PM_ERR_GPGME
};
-/** The number of the last error that occurred. */
-extern enum _pmerrno_t pm_errno;
+/** Returns the current error code from the handle. */
+enum _pmerrno_t alpm_errno(pmhandle_t *handle);
/** Returns the string corresponding to an error number. */
-const char *alpm_strerror(int err);
-
-/** Returns the string corresponding to pm_errno. */
-const char *alpm_strerrorlast(void);
+const char *alpm_strerror(enum _pmerrno_t err);
/* End of alpm_api_errors */
/** @} */
+pmhandle_t *alpm_initialize(const char *root, const char *dbpath,
+ enum _pmerrno_t *err);
+int alpm_release(pmhandle_t *handle);
+const char *alpm_version(void);
+
/* End of alpm_api */
/** @} */
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index d2e09478..c2b30adc 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -286,7 +286,7 @@ alpm_list_t SYMEXPORT *alpm_list_msort(alpm_list_t *list, size_t n, alpm_list_fn
/**
* @brief Remove an item from the list.
- * item is not freed; this is the responsiblity of the caller.
+ * item is not freed; this is the responsibility of the caller.
*
* @param haystack the list to remove the item from
* @param item the item to remove from the list
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 7df97471..6431b286 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -83,8 +83,6 @@ char *_alpm_needbackup(const char *file, const alpm_list_t *backup)
{
const alpm_list_t *lp;
- ALPM_LOG_FUNC;
-
if(file == NULL || backup == NULL) {
return NULL;
}
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 36105452..d9a76cc2 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -41,11 +41,8 @@
#include "package.h"
#include "deps.h"
-
#define LAZY_LOAD(info, errret) \
do { \
- ALPM_LOG_FUNC; \
- ASSERT(handle != NULL, return (errret)); \
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
_alpm_local_db_read(pkg->origin_data.db, pkg, info); \
} \
@@ -138,11 +135,6 @@ static alpm_list_t *_cache_get_groups(pmpkg_t *pkg)
static int _cache_has_scriptlet(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return -1);
-
if(!(pkg->infolevel & INFRQ_SCRIPTLET)) {
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
}
@@ -187,11 +179,6 @@ static alpm_list_t *_cache_get_deltas(pmpkg_t UNUSED *pkg)
static alpm_list_t *_cache_get_files(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
-
if(pkg->origin == PKG_FROM_LOCALDB
&& !(pkg->infolevel & INFRQ_FILES)) {
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
@@ -201,11 +188,6 @@ static alpm_list_t *_cache_get_files(pmpkg_t *pkg)
static alpm_list_t *_cache_get_backup(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
-
if(pkg->origin == PKG_FROM_LOCALDB
&& !(pkg->infolevel & INFRQ_FILES)) {
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
@@ -221,14 +203,9 @@ static alpm_list_t *_cache_get_backup(pmpkg_t *pkg)
*/
static void *_cache_changelog_open(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
-
char clfile[PATH_MAX];
snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
- alpm_option_get_dbpath(),
+ alpm_option_get_dbpath(pkg->handle),
alpm_db_get_name(alpm_pkg_get_db(pkg)),
alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
@@ -302,15 +279,15 @@ static int checkdbdir(pmdb_t *db)
const char *path = _alpm_db_path(db);
if(stat(path, &buf) != 0) {
- _alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
path);
if(_alpm_makepath(path) != 0) {
- RET_ERR(PM_ERR_SYSTEM, -1);
+ RET_ERR(db->handle, PM_ERR_SYSTEM, -1);
}
} else if(!S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_WARNING, _("removing invalid database: %s\n"), path);
+ _alpm_log(db->handle, PM_LOG_WARNING, _("removing invalid database: %s\n"), path);
if(unlink(path) != 0 || _alpm_makepath(path) != 0) {
- RET_ERR(PM_ERR_SYSTEM, -1);
+ RET_ERR(db->handle, PM_ERR_SYSTEM, -1);
}
}
return 0;
@@ -346,10 +323,6 @@ static int local_db_populate(pmdb_t *db)
const char *dbpath;
DIR *dbdir;
- ALPM_LOG_FUNC;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
-
dbpath = _alpm_db_path(db);
if(dbpath == NULL) {
/* pm_errno set in _alpm_db_path() */
@@ -361,10 +334,10 @@ static int local_db_populate(pmdb_t *db)
/* no database existing yet is not an error */
return 0;
}
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
if(fstat(dirfd(dbdir), &buf) != 0) {
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
if(buf.st_nlink >= 2) {
est_count = buf.st_nlink;
@@ -388,7 +361,7 @@ static int local_db_populate(pmdb_t *db)
db->pkgcache = _alpm_pkghash_create(est_count * 2);
if(db->pkgcache == NULL){
closedir(dbdir);
- RET_ERR(PM_ERR_MEMORY, -1);
+ RET_ERR(db->handle, PM_ERR_MEMORY, -1);
}
while((ent = readdir(dbdir)) != NULL) {
@@ -406,11 +379,11 @@ static int local_db_populate(pmdb_t *db)
pkg = _alpm_pkg_new();
if(pkg == NULL) {
closedir(dbdir);
- RET_ERR(PM_ERR_MEMORY, -1);
+ RET_ERR(db->handle, PM_ERR_MEMORY, -1);
}
/* split the db entry name */
if(_alpm_splitname(name, pkg) != 0) {
- _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
+ _alpm_log(db->handle, PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
name);
_alpm_pkg_free(pkg);
continue;
@@ -418,7 +391,7 @@ static int local_db_populate(pmdb_t *db)
/* duplicated database entries are not allowed */
if(_alpm_pkghash_find(db->pkgcache, pkg->name)) {
- _alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
+ _alpm_log(db->handle, PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
_alpm_pkg_free(pkg);
continue;
}
@@ -426,16 +399,17 @@ static int local_db_populate(pmdb_t *db)
pkg->origin = PKG_FROM_LOCALDB;
pkg->origin_data.db = db;
pkg->ops = &local_pkg_ops;
+ pkg->handle = db->handle;
/* explicitly read with only 'BASE' data, accessors will handle the rest */
if(_alpm_local_db_read(db, pkg, INFRQ_BASE) == -1) {
- _alpm_log(PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
+ _alpm_log(db->handle, PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
_alpm_pkg_free(pkg);
continue;
}
/* add to the collection */
- _alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
+ _alpm_log(db->handle, PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
pkg->name, db->treename);
db->pkgcache = _alpm_pkghash_add(db->pkgcache, pkg);
count++;
@@ -445,7 +419,7 @@ static int local_db_populate(pmdb_t *db)
if(count > 0) {
db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
}
- _alpm_log(PM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
count, db->treename);
return count;
@@ -460,7 +434,7 @@ static char *get_pkgpath(pmdb_t *db, pmpkg_t *info)
dbpath = _alpm_db_path(db);
len = strlen(dbpath) + strlen(info->name) + strlen(info->version) + 3;
- MALLOC(pkgpath, len, RET_ERR(PM_ERR_MEMORY, NULL));
+ MALLOC(pkgpath, len, RET_ERR(db->handle, PM_ERR_MEMORY, NULL));
sprintf(pkgpath, "%s%s-%s/", dbpath, info->name, info->version);
return pkgpath;
}
@@ -473,19 +447,14 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
char line[1024];
char *pkgpath = NULL;
- ALPM_LOG_FUNC;
-
- if(db == NULL) {
- RET_ERR(PM_ERR_DB_NULL, -1);
- }
-
if(info == NULL || info->name == NULL || info->version == NULL) {
- _alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_local_db_read, skipping\n");
+ _alpm_log(db->handle, PM_LOG_DEBUG,
+ "invalid package entry provided to _alpm_local_db_read, skipping\n");
return -1;
}
if(info->origin != PKG_FROM_LOCALDB) {
- _alpm_log(PM_LOG_DEBUG,
+ _alpm_log(db->handle, PM_LOG_DEBUG,
"request to read info for a non-local package '%s', skipping...\n",
info->name);
return -1;
@@ -500,7 +469,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* already loaded all of this info, do nothing */
return 0;
}
- _alpm_log(PM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
+ _alpm_log(db->handle, PM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
info->name, inforeq);
/* clear out 'line', to be certain - and to make valgrind happy */
@@ -510,7 +479,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(access(pkgpath, F_OK)) {
/* directory doesn't exist or can't be opened */
- _alpm_log(PM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
info->name, info->version, db->treename);
goto error;
}
@@ -519,7 +488,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(inforeq & INFRQ_DESC && !(info->infolevel & INFRQ_DESC)) {
snprintf(path, PATH_MAX, "%sdesc", pkgpath);
if((fp = fopen(path, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
goto error;
}
while(!feof(fp)) {
@@ -532,7 +501,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
goto error;
}
if(strcmp(_alpm_strtrim(line), info->name) != 0) {
- _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: name "
+ _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: name "
"mismatch on package %s\n"), db->treename, info->name);
}
} else if(strcmp(line, "%VERSION%") == 0) {
@@ -540,7 +509,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
goto error;
}
if(strcmp(_alpm_strtrim(line), info->version) != 0) {
- _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: version "
+ _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: version "
"mismatch on package %s\n"), db->treename, info->name);
}
} else if(strcmp(line, "%DESC%") == 0) {
@@ -643,7 +612,7 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(inforeq & INFRQ_FILES && !(info->infolevel & INFRQ_FILES)) {
snprintf(path, PATH_MAX, "%sfiles", pkgpath);
if((fp = fopen(path, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
goto error;
}
while(fgets(line, sizeof(line), fp)) {
@@ -702,7 +671,7 @@ int _alpm_local_db_prepare(pmdb_t *db, pmpkg_t *info)
pkgpath = get_pkgpath(db, info);
if((retval = mkdir(pkgpath, 0755)) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not create directory %s: %s\n"),
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not create directory %s: %s\n"),
pkgpath, strerror(errno));
}
@@ -721,8 +690,6 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
int retval = 0;
char *pkgpath = NULL;
- ALPM_LOG_FUNC;
-
if(db == NULL || info == NULL) {
return -1;
}
@@ -738,11 +705,12 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* DESC */
if(inforeq & INFRQ_DESC) {
- _alpm_log(PM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
info->name, info->version);
snprintf(path, PATH_MAX, "%sdesc", pkgpath);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"),
+ path, strerror(errno));
retval = -1;
goto cleanup;
}
@@ -839,11 +807,12 @@ int _alpm_local_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* FILES */
if(inforeq & INFRQ_FILES) {
- _alpm_log(PM_LOG_DEBUG, "writing %s-%s FILES information back to db\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "writing %s-%s FILES information back to db\n",
info->name, info->version);
snprintf(path, PATH_MAX, "%sfiles", pkgpath);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"),
+ path, strerror(errno));
retval = -1;
goto cleanup;
}
@@ -884,12 +853,6 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
int ret = 0;
char *pkgpath = NULL;
- ALPM_LOG_FUNC;
-
- if(db == NULL || info == NULL) {
- RET_ERR(PM_ERR_DB_NULL, -1);
- }
-
pkgpath = get_pkgpath(db, info);
ret = _alpm_rmrf(pkgpath);
@@ -909,7 +872,7 @@ static int local_db_version(pmdb_t *db)
dbpath = _alpm_db_path(db);
if(dbpath == NULL) {
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
dbdir = opendir(dbpath);
if(dbdir == NULL) {
@@ -918,7 +881,7 @@ static int local_db_version(pmdb_t *db)
version = 2;
goto done;
} else {
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
}
@@ -948,7 +911,7 @@ done:
closedir(dbdir);
}
- _alpm_log(PM_LOG_DEBUG, "local database version %d\n", version);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "local database version %d\n", version);
return version;
}
@@ -958,19 +921,18 @@ struct db_operations local_db_ops = {
.version = local_db_version,
};
-pmdb_t *_alpm_db_register_local(void)
+pmdb_t *_alpm_db_register_local(pmhandle_t *handle)
{
pmdb_t *db;
- ALPM_LOG_FUNC;
-
- _alpm_log(PM_LOG_DEBUG, "registering local database\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "registering local database\n");
db = _alpm_db_new("local", 1);
if(db == NULL) {
- RET_ERR(PM_ERR_DB_CREATE, NULL);
+ return NULL;
}
db->ops = &local_db_ops;
+ db->handle = handle;
handle->db_local = db;
return db;
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 9e59d69a..e65db498 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -30,8 +30,10 @@
/* libalpm */
#include "alpm_list.h"
+#include "alpm.h"
#include "util.h"
#include "log.h"
+#include "handle.h"
#include "package.h"
#include "deps.h" /* _alpm_splitdep */
@@ -43,8 +45,6 @@
*/
static void *_package_changelog_open(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
ASSERT(pkg != NULL, return NULL);
struct archive *archive = NULL;
@@ -52,7 +52,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
const char *pkgfile = pkg->origin_data.file;
if((archive = archive_read_new()) == NULL) {
- RET_ERR(PM_ERR_LIBARCHIVE, NULL);
+ RET_ERR(pkg->handle, PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@@ -60,7 +60,7 @@ static void *_package_changelog_open(pmpkg_t *pkg)
if(archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(pkg->handle, PM_ERR_PKG_OPEN, NULL);
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
@@ -92,7 +92,7 @@ static size_t _package_changelog_read(void *ptr, size_t size,
ssize_t sret = archive_read_data((struct archive *)fp, ptr, size);
/* Report error (negative values) */
if(sret < 0) {
- pm_errno = PM_ERR_LIBARCHIVE;
+ pkg->handle->pm_errno = PM_ERR_LIBARCHIVE;
return 0;
} else {
return (size_t)sret;
@@ -135,23 +135,21 @@ static struct pkg_operations *get_file_pkg_ops(void)
* @param archive the archive to read from, pointed at the .PKGINFO entry
* @param newpkg an empty pmpkg_t struct to fill with package info
*
- * @return 0 on success, 1 on error
+ * @return 0 on success, -1 on error
*/
-static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
+static int parse_descfile(pmhandle_t *handle, struct archive *a, pmpkg_t *newpkg)
{
char *ptr = NULL;
char *key = NULL;
- int linenum = 0;
+ int ret, linenum = 0;
struct archive_read_buffer buf;
- ALPM_LOG_FUNC;
-
memset(&buf, 0, sizeof(buf));
/* 512K for a line length seems reasonable */
buf.max_line_size = 512 * 1024;
/* loop until we reach EOF or other error */
- while(_alpm_archive_fgets(a, &buf) == ARCHIVE_OK) {
+ while((ret = _alpm_archive_fgets(a, &buf)) == ARCHIVE_OK) {
char *line = _alpm_strtrim(buf.line);
linenum++;
@@ -161,33 +159,33 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
ptr = line;
key = strsep(&ptr, "=");
if(key == NULL || ptr == NULL) {
- _alpm_log(PM_LOG_DEBUG, "%s: syntax error in description file line %d\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s: syntax error in description file line %d\n",
newpkg->name ? newpkg->name : "error", linenum);
} else {
key = _alpm_strtrim(key);
while(*ptr == ' ') ptr++;
ptr = _alpm_strtrim(ptr);
if(strcmp(key, "pkgname") == 0) {
- STRDUP(newpkg->name, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
} else if(strcmp(key, "pkgbase") == 0) {
/* not used atm */
} else if(strcmp(key, "pkgver") == 0) {
- STRDUP(newpkg->version, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->version, ptr, return -1);
} else if(strcmp(key, "pkgdesc") == 0) {
- STRDUP(newpkg->desc, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->desc, ptr, return -1);
} else if(strcmp(key, "group") == 0) {
newpkg->groups = alpm_list_add(newpkg->groups, strdup(ptr));
} else if(strcmp(key, "url") == 0) {
- STRDUP(newpkg->url, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->url, ptr, return -1);
} else if(strcmp(key, "license") == 0) {
newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr));
} else if(strcmp(key, "builddate") == 0) {
newpkg->builddate = _alpm_parsedate(ptr);
} else if(strcmp(key, "packager") == 0) {
- STRDUP(newpkg->packager, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->packager, ptr, return -1);
} else if(strcmp(key, "arch") == 0) {
- STRDUP(newpkg->arch, ptr, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(newpkg->arch, ptr, return -1);
} else if(strcmp(key, "size") == 0) {
/* size in the raw package is uncompressed (installed) size */
newpkg->isize = atol(ptr);
@@ -209,25 +207,31 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg)
} else if(strcmp(key, "makepkgopt") == 0) {
/* not used atm */
} else {
- _alpm_log(PM_LOG_DEBUG, "%s: unknown key '%s' in description file line %d\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s: unknown key '%s' in description file line %d\n",
newpkg->name ? newpkg->name : "error", key, linenum);
}
}
line[0] = '\0';
}
+ if(ret != ARCHIVE_EOF) {
+ _alpm_log(handle, PM_LOG_DEBUG, "error parsing package descfile\n");
+ return -1;
+ }
return 0;
}
/**
* Load a package and create the corresponding pmpkg_t struct.
+ * @param handle the context handle
* @param pkgfile path to the package file
* @param full whether to stop the load after metadata is read or continue
* through the full archive
* @return An information filled pmpkg_t struct
*/
-pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
- const char *md5sum, const char *base64_sig, pgp_verify_t check_sig)
+pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile,
+ int full, const char *md5sum, const char *base64_sig,
+ pgp_verify_t check_sig)
{
int ret;
int config = 0;
@@ -236,49 +240,48 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
pmpkg_t *newpkg = NULL;
struct stat st;
- ALPM_LOG_FUNC;
-
if(pkgfile == NULL || strlen(pkgfile) == 0) {
- RET_ERR(PM_ERR_WRONG_ARGS, NULL);
+ RET_ERR(handle, PM_ERR_WRONG_ARGS, NULL);
}
/* attempt to stat the package file, ensure it exists */
if(stat(pkgfile, &st) == 0) {
newpkg = _alpm_pkg_new();
if(newpkg == NULL) {
- RET_ERR(PM_ERR_MEMORY, NULL);
+ RET_ERR(handle, PM_ERR_MEMORY, NULL);
}
newpkg->filename = strdup(pkgfile);
newpkg->size = st.st_size;
} else {
/* couldn't stat the pkgfile, return an error */
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(handle, PM_ERR_PKG_OPEN, NULL);
}
/* first steps- validate the package file */
- _alpm_log(PM_LOG_DEBUG, "md5sum: %s\n", md5sum);
+ _alpm_log(handle, PM_LOG_DEBUG, "md5sum: %s\n", md5sum);
if(md5sum) {
- _alpm_log(PM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking md5sum for %s\n", pkgfile);
if(_alpm_test_md5sum(pkgfile, md5sum) != 0) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_PKG_INVALID, NULL);
+ RET_ERR(handle, PM_ERR_PKG_INVALID, NULL);
}
}
- _alpm_log(PM_LOG_DEBUG, "base64_sig: %s\n", base64_sig);
+ _alpm_log(handle, PM_LOG_DEBUG, "base64_sig: %s\n", base64_sig);
if(check_sig != PM_PGP_VERIFY_NEVER) {
- _alpm_log(PM_LOG_DEBUG, "checking signature for %s\n", pkgfile);
- ret = _alpm_gpgme_checksig(pkgfile, base64_sig);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking signature for %s\n", pkgfile);
+ ret = _alpm_gpgme_checksig(handle, pkgfile, base64_sig);
if((check_sig == PM_PGP_VERIFY_ALWAYS && ret != 0) ||
(check_sig == PM_PGP_VERIFY_OPTIONAL && ret == 1)) {
- RET_ERR(PM_ERR_SIG_INVALID, NULL);
+ alpm_pkg_free(newpkg);
+ RET_ERR(handle, PM_ERR_SIG_INVALID, NULL);
}
}
/* next- try to create an archive object to read in the package */
if((archive = archive_read_new()) == NULL) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_LIBARCHIVE, NULL);
+ RET_ERR(handle, PM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
@@ -287,10 +290,10 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
if(archive_read_open_filename(archive, pkgfile,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
alpm_pkg_free(newpkg);
- RET_ERR(PM_ERR_PKG_OPEN, NULL);
+ RET_ERR(handle, PM_ERR_PKG_OPEN, NULL);
}
- _alpm_log(PM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
/* If full is false, only read through the archive until we find our needed
* metadata. If it is true, read through the entire archive, which serves
@@ -300,17 +303,17 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
if(strcmp(entry_name, ".PKGINFO") == 0) {
/* parse the info file */
- if(parse_descfile(archive, newpkg) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not parse package description file in %s\n"),
+ if(parse_descfile(handle, archive, newpkg) != 0) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not parse package description file in %s\n"),
pkgfile);
goto pkg_invalid;
}
if(newpkg->name == NULL || strlen(newpkg->name) == 0) {
- _alpm_log(PM_LOG_ERROR, _("missing package name in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package name in %s\n"), pkgfile);
goto pkg_invalid;
}
if(newpkg->version == NULL || strlen(newpkg->version) == 0) {
- _alpm_log(PM_LOG_ERROR, _("missing package version in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package version in %s\n"), pkgfile);
goto pkg_invalid;
}
config = 1;
@@ -326,9 +329,9 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
}
if(archive_read_data_skip(archive)) {
- _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}
@@ -339,14 +342,14 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
}
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occured */
- _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
goto error;
}
if(!config) {
- _alpm_log(PM_LOG_ERROR, _("missing package metadata in %s\n"), pkgfile);
+ _alpm_log(handle, PM_LOG_ERROR, _("missing package metadata in %s\n"), pkgfile);
goto pkg_invalid;
}
@@ -356,10 +359,11 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
newpkg->origin = PKG_FROM_FILE;
newpkg->origin_data.file = strdup(pkgfile);
newpkg->ops = get_file_pkg_ops();
+ newpkg->handle = handle;
if(full) {
/* "checking for conflicts" requires a sorted list, ensure that here */
- _alpm_log(PM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "sorting package filelist for %s\n", pkgfile);
newpkg->files = alpm_list_msort(newpkg->files, alpm_list_count(newpkg->files),
_alpm_str_cmp);
newpkg->infolevel = INFRQ_ALL;
@@ -372,7 +376,7 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full,
return newpkg;
pkg_invalid:
- pm_errno = PM_ERR_PKG_INVALID;
+ handle->pm_errno = PM_ERR_PKG_INVALID;
error:
_alpm_pkg_free(newpkg);
archive_read_finish(archive);
@@ -380,15 +384,13 @@ error:
return NULL;
}
-int SYMEXPORT alpm_pkg_load(const char *filename, int full,
+int SYMEXPORT alpm_pkg_load(pmhandle_t *handle, const char *filename, int full,
pgp_verify_t check_sig, pmpkg_t **pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
- *pkg = _alpm_pkg_load_internal(filename, full, NULL, NULL, check_sig);
+ *pkg = _alpm_pkg_load_internal(handle, filename, full, NULL, NULL, check_sig);
if(*pkg == NULL) {
/* pm_errno is set by pkg_load */
return -1;
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 9d85a454..ccc8fdbe 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -37,6 +37,34 @@
#include "deps.h"
#include "dload.h"
+static char *get_sync_dir(pmhandle_t *handle)
+{
+ const char *dbpath = alpm_option_get_dbpath(handle);
+ size_t len = strlen(dbpath) + 6;
+ char *syncpath;
+ struct stat buf;
+
+ MALLOC(syncpath, len, RET_ERR(handle, PM_ERR_MEMORY, NULL));
+ sprintf(syncpath, "%s%s", dbpath, "sync/");
+
+ if(stat(syncpath, &buf) != 0) {
+ _alpm_log(handle, PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
+ syncpath);
+ if(_alpm_makepath(syncpath) != 0) {
+ free(syncpath);
+ RET_ERR(handle, PM_ERR_SYSTEM, NULL);
+ }
+ } else if(!S_ISDIR(buf.st_mode)) {
+ _alpm_log(handle, PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath);
+ if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) {
+ free(syncpath);
+ RET_ERR(handle, PM_ERR_SYSTEM, NULL);
+ }
+ }
+
+ return syncpath;
+}
+
/** Update a package database
*
* An update of the package database \a db will be attempted. Unless
@@ -79,44 +107,25 @@
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
{
char *syncpath;
- const char *dbpath;
alpm_list_t *i;
- struct stat buf;
- size_t len;
int ret = -1;
mode_t oldmask;
+ pmhandle_t *handle;
pgp_verify_t check_sig;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- ASSERT(db->servers != NULL, RET_ERR(PM_ERR_SERVER_NONE, -1));
-
- dbpath = alpm_option_get_dbpath();
- len = strlen(dbpath) + 6;
- MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1));
- sprintf(syncpath, "%s%s", dbpath, "sync/");
+ ASSERT(db != NULL, return -1);
+ handle = db->handle;
+ ASSERT(db != handle->db_local, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db->servers != NULL, RET_ERR(handle, PM_ERR_SERVER_NONE, -1));
/* make sure we have a sane umask */
oldmask = umask(0022);
- if(stat(syncpath, &buf) != 0) {
- _alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n",
- syncpath);
- if(_alpm_makepath(syncpath) != 0) {
- free(syncpath);
- RET_ERR(PM_ERR_SYSTEM, -1);
- }
- } else if(!S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath);
- if(unlink(syncpath) != 0 || _alpm_makepath(syncpath) != 0) {
- free(syncpath);
- RET_ERR(PM_ERR_SYSTEM, -1);
- }
+ syncpath = get_sync_dir(handle);
+ if(!syncpath) {
+ return -1;
}
-
check_sig = _alpm_db_get_sigverify_level(db);
for(i = db->servers; i; i = i->next) {
@@ -127,10 +136,10 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
/* print server + filename into a buffer (leave space for .sig) */
len = strlen(server) + strlen(db->treename) + 9;
- CALLOC(fileurl, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(fileurl, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, -1));
snprintf(fileurl, len, "%s/%s.db", server, db->treename);
- ret = _alpm_download(fileurl, syncpath, force, 0, 0);
+ ret = _alpm_download(handle, fileurl, syncpath, force, 0, 0);
if(ret == 0 && (check_sig == PM_PGP_VERIFY_ALWAYS ||
check_sig == PM_PGP_VERIFY_OPTIONAL)) {
@@ -138,7 +147,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
/* if we downloaded a DB, we want the .sig from the same server */
snprintf(fileurl, len, "%s/%s.db.sig", server, db->treename);
- sig_ret = _alpm_download(fileurl, syncpath, 1, 0, errors_ok);
+ sig_ret = _alpm_download(handle, fileurl, syncpath, 1, 0, errors_ok);
/* errors_ok suppresses error messages, but not the return code */
sig_ret = errors_ok ? 0 : sig_ret;
}
@@ -151,11 +160,12 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
if(ret == 1) {
/* files match, do nothing */
- pm_errno = 0;
+ handle->pm_errno = 0;
goto cleanup;
} else if(ret == -1) {
/* pm_errno was set by the download code */
- _alpm_log(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerrorlast());
+ _alpm_log(handle, PM_LOG_DEBUG, "failed to sync db: %s\n",
+ alpm_strerror(handle->pm_errno));
goto cleanup;
}
@@ -242,12 +252,8 @@ static int sync_db_populate(pmdb_t *db)
struct archive_entry *entry;
pmpkg_t *pkg = NULL;
- ALPM_LOG_FUNC;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
-
if((archive = archive_read_new()) == NULL) {
- RET_ERR(PM_ERR_LIBARCHIVE, -1);
+ RET_ERR(db->handle, PM_ERR_LIBARCHIVE, -1);
}
archive_read_support_compression_all(archive);
@@ -259,24 +265,24 @@ static int sync_db_populate(pmdb_t *db)
return -1;
}
- _alpm_log(PM_LOG_DEBUG, "opening database archive %s\n", dbpath);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "opening database archive %s\n", dbpath);
if(archive_read_open_filename(archive, dbpath,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath,
+ _alpm_log(db->handle, PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath,
archive_error_string(archive));
archive_read_finish(archive);
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
if(stat(dbpath, &buf) != 0) {
- RET_ERR(PM_ERR_DB_OPEN, -1);
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, -1);
}
est_count = estimate_package_count(&buf, archive);
/* initialize hash at 66% full */
db->pkgcache = _alpm_pkghash_create(est_count * 3 / 2);
if(db->pkgcache == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ RET_ERR(db->handle, PM_ERR_MEMORY, -1);
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
@@ -290,37 +296,47 @@ static int sync_db_populate(pmdb_t *db)
pkg = _alpm_pkg_new();
if(pkg == NULL) {
archive_read_finish(archive);
- RET_ERR(PM_ERR_MEMORY, -1);
+ RET_ERR(db->handle, PM_ERR_MEMORY, -1);
}
name = archive_entry_pathname(entry);
if(_alpm_splitname(name, pkg) != 0) {
- _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
+ _alpm_log(db->handle, PM_LOG_ERROR, _("invalid name for database entry '%s'\n"),
name);
_alpm_pkg_free(pkg);
+ pkg = NULL;
continue;
}
/* duplicated database entries are not allowed */
if(_alpm_pkghash_find(db->pkgcache, pkg->name)) {
- _alpm_log(PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
+ _alpm_log(db->handle, PM_LOG_ERROR, _("duplicated database entry '%s'\n"), pkg->name);
_alpm_pkg_free(pkg);
+ pkg = NULL;
continue;
}
pkg->origin = PKG_FROM_SYNCDB;
- pkg->ops = &default_pkg_ops;
pkg->origin_data.db = db;
+ pkg->ops = &default_pkg_ops;
+ pkg->handle = db->handle;
/* add to the collection */
- _alpm_log(PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
+ _alpm_log(db->handle, PM_LOG_FUNCTION, "adding '%s' to package cache for db '%s'\n",
pkg->name, db->treename);
db->pkgcache = _alpm_pkghash_add(db->pkgcache, pkg);
count++;
} else {
/* we have desc, depends or deltas - parse it */
- sync_db_read(db, archive, entry, pkg);
+ if(sync_db_read(db, archive, entry, pkg) != 0) {
+ _alpm_log(db->handle, PM_LOG_ERROR,
+ _("could not parse package '%s' description file from db '%s'\n"),
+ pkg->name, db->treename);
+ _alpm_pkg_free(pkg);
+ pkg = NULL;
+ continue;
+ }
}
}
@@ -328,7 +344,7 @@ static int sync_db_populate(pmdb_t *db)
db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
}
archive_read_finish(archive);
- _alpm_log(PM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
count, db->treename);
return count;
@@ -355,26 +371,19 @@ static int sync_db_populate(pmdb_t *db)
static int sync_db_read(pmdb_t *db, struct archive *archive,
struct archive_entry *entry, pmpkg_t *likely_pkg)
{
- const char *entryname = NULL, *filename;
+ const char *entryname, *filename;
char *pkgname, *p, *q;
pmpkg_t *pkg;
struct archive_read_buffer buf;
- ALPM_LOG_FUNC;
-
- if(db == NULL) {
- RET_ERR(PM_ERR_DB_NULL, -1);
- }
-
- if(entry != NULL) {
- entryname = archive_entry_pathname(entry);
- }
+ entryname = archive_entry_pathname(entry);
if(entryname == NULL) {
- _alpm_log(PM_LOG_DEBUG, "invalid archive entry provided to _alpm_sync_db_read, skipping\n");
+ _alpm_log(db->handle, PM_LOG_DEBUG,
+ "invalid archive entry provided to _alpm_sync_db_read, skipping\n");
return -1;
}
- _alpm_log(PM_LOG_FUNCTION, "loading package data from archive entry %s\n",
+ _alpm_log(db->handle, PM_LOG_FUNCTION, "loading package data from archive entry %s\n",
entryname);
memset(&buf, 0, sizeof(buf));
@@ -382,7 +391,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
buf.max_line_size = 512 * 1024;
/* get package and db file names */
- STRDUP(pkgname, entryname, RET_ERR(PM_ERR_MEMORY, -1));
+ STRDUP(pkgname, entryname, RET_ERR(db->handle, PM_ERR_MEMORY, -1));
p = pkgname + strlen(pkgname);
for(q = --p; *q && *q != '/'; q--);
filename = q + 1;
@@ -395,31 +404,32 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
pkg = likely_pkg;
} else {
if(db->pkgcache == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ RET_ERR(db->handle, PM_ERR_MEMORY, -1);
}
pkg = _alpm_pkghash_find(db->pkgcache, pkgname);
}
if(pkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, "package %s not found in %s sync database",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "package %s not found in %s sync database",
pkgname, db->treename);
return -1;
}
if(strcmp(filename, "desc") == 0 || strcmp(filename, "depends") == 0
|| strcmp(filename, "deltas") == 0) {
- while(_alpm_archive_fgets(archive, &buf) == ARCHIVE_OK) {
+ int ret;
+ while((ret = _alpm_archive_fgets(archive, &buf)) == ARCHIVE_OK) {
char *line = _alpm_strtrim(buf.line);
if(strcmp(line, "%NAME%") == 0) {
READ_NEXT(line);
if(strcmp(line, pkg->name) != 0) {
- _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: name "
+ _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: name "
"mismatch on package %s\n"), db->treename, pkg->name);
}
} else if(strcmp(line, "%VERSION%") == 0) {
READ_NEXT(line);
if(strcmp(line, pkg->version) != 0) {
- _alpm_log(PM_LOG_ERROR, _("%s database is inconsistent: version "
+ _alpm_log(db->handle, PM_LOG_ERROR, _("%s database is inconsistent: version "
"mismatch on package %s\n"), db->treename, pkg->name);
}
} else if(strcmp(line, "%FILENAME%") == 0) {
@@ -484,17 +494,23 @@ static int sync_db_read(pmdb_t *db, struct archive *archive,
}
}
}
+ if(ret != ARCHIVE_EOF) {
+ goto error;
+ }
} else if(strcmp(filename, "files") == 0) {
/* currently do nothing with this file */
} else {
/* unknown database file */
- _alpm_log(PM_LOG_DEBUG, "unknown database file: %s\n", filename);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "unknown database file: %s\n", filename);
}
-error:
FREE(pkgname);
- /* TODO: return 0 always? */
return 0;
+
+error:
+ _alpm_log(db->handle, PM_LOG_DEBUG, "error parsing database file: %s\n", filename);
+ FREE(pkgname);
+ return -1;
}
static int sync_db_version(pmdb_t UNUSED *db)
@@ -508,18 +524,18 @@ struct db_operations sync_db_ops = {
.version = sync_db_version,
};
-pmdb_t *_alpm_db_register_sync(const char *treename)
+pmdb_t *_alpm_db_register_sync(pmhandle_t *handle, const char *treename)
{
pmdb_t *db;
- ALPM_LOG_FUNC;
- _alpm_log(PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
+ _alpm_log(handle, PM_LOG_DEBUG, "registering sync database '%s'\n", treename);
db = _alpm_db_new(treename, 0);
if(db == NULL) {
- RET_ERR(PM_ERR_DB_CREATE, NULL);
+ RET_ERR(handle, PM_ERR_DB_CREATE, NULL);
}
db->ops = &sync_db_ops;
+ db->handle = handle;
handle->dbs_sync = alpm_list_add(handle->dbs_sync, db);
return db;
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index fbc988bd..66441a77 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -40,18 +40,16 @@
#include "log.h"
#include "deps.h"
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2,
+static pmconflict_t *conflict_new(const char *package1, const char *package2,
const char *reason)
{
pmconflict_t *conflict;
- ALPM_LOG_FUNC;
+ MALLOC(conflict, sizeof(pmconflict_t), return NULL);
- MALLOC(conflict, sizeof(pmconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
-
- STRDUP(conflict->package1, package1, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(conflict->package2, package2, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(conflict->reason, reason, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(conflict->package1, package1, return NULL);
+ STRDUP(conflict->package2, package2, return NULL);
+ STRDUP(conflict->reason, reason, return NULL);
return conflict;
}
@@ -67,11 +65,11 @@ void _alpm_conflict_free(pmconflict_t *conflict)
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
{
pmconflict_t *newconflict;
- CALLOC(newconflict, 1, sizeof(pmconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(newconflict, 1, sizeof(pmconflict_t), );
- STRDUP(newconflict->package1, conflict->package1, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(newconflict->package2, conflict->package2, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(newconflict->reason, conflict->reason, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newconflict->package1, conflict->package1, return NULL);
+ STRDUP(newconflict->package2, conflict->package2, return NULL);
+ STRDUP(newconflict->reason, conflict->reason, return NULL);
return newconflict;
}
@@ -82,8 +80,6 @@ static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
const char *npkg1 = needle->package1;
const char *npkg2 = needle->package2;
- ALPM_LOG_FUNC;
-
for(i = haystack; i; i = i->next) {
pmconflict_t *conflict = i->data;
const char *cpkg1 = conflict->package1;
@@ -97,22 +93,28 @@ static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack)
return 0;
}
-/** Adds the pkg1/pkg2 conflict to the baddeps list
- * @param *baddeps list to add conflict to
+/** Adds the pkg1/pkg2 conflict to the baddeps list.
+ * @param handle the context handle
+ * @param baddeps list to add conflict to
* @param pkg1 first package
* @param pkg2 package causing conflict
+ * @param reason reason for this conflict
*/
-static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
- const char *pkg2, const char *reason)
+static int add_conflict(pmhandle_t *handle, alpm_list_t **baddeps,
+ const char *pkg1, const char *pkg2, const char *reason)
{
- pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
- _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
+ pmconflict_t *conflict = conflict_new(pkg1, pkg2, reason);
+ if(!conflict) {
+ return -1;
+ }
+ _alpm_log(handle, PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n",
pkg1, pkg2, reason);
- if(conflict && !conflict_isin(conflict, *baddeps)) {
+ if(!conflict_isin(conflict, *baddeps)) {
*baddeps = alpm_list_add(*baddeps, conflict);
} else {
_alpm_conflict_free(conflict);
}
+ return 0;
}
/** Check if packages from list1 conflict with packages from list2.
@@ -121,14 +123,16 @@ static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
* If a conflict (pkg1, pkg2) is found, it is added to the baddeps list
* in this order if order >= 0, or reverse order (pkg2,pkg1) otherwise.
*
+ * @param handle the context handle
* @param list1 first list of packages
* @param list2 second list of packages
- * @param *baddeps list to store conflicts
+ * @param baddeps list to store conflicts
* @param order if >= 0 the conflict order is preserved, if < 0 it's reversed
*/
-static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
+static void check_conflict(pmhandle_t *handle,
+ alpm_list_t *list1, alpm_list_t *list2,
alpm_list_t **baddeps, int order) {
- alpm_list_t *i, *j, *k;
+ alpm_list_t *i;
if(!baddeps) {
return;
@@ -136,9 +140,11 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
for(i = list1; i; i = i->next) {
pmpkg_t *pkg1 = i->data;
const char *pkg1name = alpm_pkg_get_name(pkg1);
+ alpm_list_t *j;
for(j = alpm_pkg_get_conflicts(pkg1); j; j = j->next) {
const char *conflict = j->data;
+ alpm_list_t *k;
pmdepend_t *parsed_conflict = _alpm_splitdep(conflict);
for(k = list2; k; k = k->next) {
@@ -152,9 +158,9 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
if(_alpm_depcmp(pkg2, parsed_conflict)) {
if(order >= 0) {
- add_conflict(baddeps, pkg1name, pkg2name, conflict);
+ add_conflict(handle, baddeps, pkg1name, pkg2name, conflict);
} else {
- add_conflict(baddeps, pkg2name, pkg1name, conflict);
+ add_conflict(handle, baddeps, pkg2name, pkg1name, conflict);
}
}
}
@@ -164,14 +170,12 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
}
/* Check for inter-conflicts */
-alpm_list_t *_alpm_innerconflicts(alpm_list_t *packages)
+alpm_list_t *_alpm_innerconflicts(pmhandle_t *handle, alpm_list_t *packages)
{
alpm_list_t *baddeps = NULL;
- ALPM_LOG_FUNC;
-
- _alpm_log(PM_LOG_DEBUG, "check targets vs targets\n");
- check_conflict(packages, packages, &baddeps, 0);
+ _alpm_log(handle, PM_LOG_DEBUG, "check targets vs targets\n");
+ check_conflict(handle, packages, packages, &baddeps, 0);
return baddeps;
}
@@ -184,8 +188,6 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
{
alpm_list_t *baddeps = NULL;
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return NULL;
}
@@ -194,10 +196,10 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
packages, _alpm_pkg_cmp);
/* two checks to be done here for conflicts */
- _alpm_log(PM_LOG_DEBUG, "check targets vs db\n");
- check_conflict(packages, dblist, &baddeps, 1);
- _alpm_log(PM_LOG_DEBUG, "check db vs targets\n");
- check_conflict(dblist, packages, &baddeps, -1);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "check targets vs db\n");
+ check_conflict(db->handle, packages, dblist, &baddeps, 1);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "check db vs targets\n");
+ check_conflict(db->handle, dblist, packages, &baddeps, -1);
alpm_list_free(dblist);
return baddeps;
@@ -205,11 +207,14 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages)
/** Check the package conflicts in a database
*
+ * @param handle the context handle
* @param pkglist the list of packages to check
* @return an alpm_list_t of pmconflict_t
*/
-alpm_list_t SYMEXPORT *alpm_checkconflicts(alpm_list_t *pkglist) {
- return _alpm_innerconflicts(pkglist);
+alpm_list_t SYMEXPORT *alpm_checkconflicts(pmhandle_t *handle,
+ alpm_list_t *pkglist)
+{
+ return _alpm_innerconflicts(handle, pkglist);
}
static const int DIFFERENCE = 0;
@@ -274,24 +279,24 @@ static alpm_list_t *filelist_operation(alpm_list_t *filesA, alpm_list_t *filesB,
* two package names or one package name and NULL. This is a wrapper for former
* functionality that was done inline.
*/
-static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
- pmfileconflicttype_t type, const char *filestr,
- const char* name1, const char* name2)
+static alpm_list_t *add_fileconflict(pmhandle_t *handle,
+ alpm_list_t *conflicts, pmfileconflicttype_t type, const char *filestr,
+ const char *name1, const char *name2)
{
pmfileconflict_t *conflict;
- MALLOC(conflict, sizeof(pmfileconflict_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ MALLOC(conflict, sizeof(pmfileconflict_t), return NULL);
conflict->type = type;
- STRDUP(conflict->target, name1, RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(conflict->file, filestr, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(conflict->target, name1, return NULL);
+ STRDUP(conflict->file, filestr, return NULL);
if(name2) {
- STRDUP(conflict->ctarget, name2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(conflict->ctarget, name2, return NULL);
} else {
- STRDUP(conflict->ctarget, "", RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(conflict->ctarget, "", return NULL);
}
conflicts = alpm_list_add(conflicts, conflict);
- _alpm_log(PM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "found file conflict %s, packages %s and %s\n",
filestr, name1, name2 ? name2 : "(filesystem)");
return conflicts;
@@ -305,7 +310,8 @@ void _alpm_fileconflict_free(pmfileconflict_t *conflict)
FREE(conflict);
}
-static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
+static int dir_belongsto_pkg(const char *root, const char *dirpath,
+ pmpkg_t *pkg)
{
struct dirent *ent = NULL;
struct stat sbuf;
@@ -313,7 +319,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
char abspath[PATH_MAX];
DIR *dir;
- snprintf(abspath, PATH_MAX, "%s%s", handle->root, dirpath);
+ snprintf(abspath, PATH_MAX, "%s%s", root, dirpath);
dir = opendir(abspath);
if(dir == NULL) {
return 1;
@@ -325,12 +331,12 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
continue;
}
snprintf(path, PATH_MAX, "%s/%s", dirpath, name);
- snprintf(abspath, PATH_MAX, "%s%s", handle->root, path);
+ snprintf(abspath, PATH_MAX, "%s%s", root, path);
if(stat(abspath, &sbuf) != 0) {
continue;
}
if(S_ISDIR(sbuf.st_mode)) {
- if(dir_belongsto_pkg(path, pkg)) {
+ if(dir_belongsto_pkg(root, path, pkg)) {
continue;
} else {
closedir(dir);
@@ -352,16 +358,15 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
/* Find file conflicts that may occur during the transaction with two checks:
* 1: check every target against every target
* 2: check every target against the filesystem */
-alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
+alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
alpm_list_t *upgrade, alpm_list_t *remove)
{
alpm_list_t *i, *j, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade);
size_t current;
+ pmtrans_t *trans = handle->trans;
- ALPM_LOG_FUNC;
-
- if(db == NULL || upgrade == NULL || trans == NULL) {
+ if(!upgrade) {
return NULL;
}
@@ -372,7 +377,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
for(current = 0, i = upgrade; i; i = i->next, current++) {
alpm_list_t *k, *tmpfiles = NULL;
pmpkg_t *p1, *p2, *dbpkg;
- char path[PATH_MAX+1];
+ char path[PATH_MAX];
p1 = i->data;
if(!p1) {
@@ -383,7 +388,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
PROGRESS(trans, PM_TRANS_PROGRESS_CONFLICTS_START, "", percent,
numtargs, current);
/* CHECK 1: check every target against every target */
- _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "searching for file conflicts: %s\n",
alpm_pkg_get_name(p1));
for(j = i->next; j; j = j->next) {
p2 = j->data;
@@ -396,8 +401,13 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
if(tmpfiles) {
for(k = tmpfiles; k; k = k->next) {
snprintf(path, PATH_MAX, "%s%s", handle->root, (char *)k->data);
- conflicts = add_fileconflict(conflicts, PM_FILECONFLICT_TARGET, path,
+ conflicts = add_fileconflict(handle, conflicts, PM_FILECONFLICT_TARGET, path,
alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
+ if(!conflicts) {
+ FREELIST(conflicts);
+ FREELIST(tmpfiles);
+ RET_ERR(handle, PM_ERR_MEMORY, NULL);
+ }
}
FREELIST(tmpfiles);
}
@@ -408,8 +418,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
char *filestr = NULL;
/* CHECK 2: check every target against the filesystem */
- _alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", p1->name);
- dbpkg = _alpm_db_get_pkgfromcache(db, p1->name);
+ _alpm_log(handle, PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", p1->name);
+ dbpkg = _alpm_db_get_pkgfromcache(handle->db_local, p1->name);
/* Do two different checks here. If the package is currently installed,
* then only check files that are new in the new package. If the package
@@ -436,15 +446,15 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
if(path[strlen(path)-1] == '/') {
if(S_ISDIR(lsbuf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path);
+ _alpm_log(handle, PM_LOG_DEBUG, "%s is a directory, not a conflict\n", path);
continue;
} else if(S_ISLNK(lsbuf.st_mode) && S_ISDIR(sbuf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG,
+ _alpm_log(handle, PM_LOG_DEBUG,
"%s is a symlink to a dir, hopefully not a conflict\n", path);
continue;
}
}
- _alpm_log(PM_LOG_DEBUG, "checking possible conflict: %s\n", path);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking possible conflict: %s\n", path);
int resolved_conflict = 0; /* have we acted on this conflict? */
@@ -452,7 +462,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
for(k = remove; k && !resolved_conflict; k = k->next) {
pmpkg_t *rempkg = k->data;
if(rempkg && alpm_list_find_str(alpm_pkg_get_files(rempkg), filestr)) {
- _alpm_log(PM_LOG_DEBUG, "local file will be removed, not a conflict: %s\n", filestr);
+ _alpm_log(handle, PM_LOG_DEBUG, "local file will be removed, not a conflict: %s\n", filestr);
resolved_conflict = 1;
}
}
@@ -463,15 +473,16 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
if(!p2 || strcmp(p1->name, p2->name) == 0) {
continue;
}
- pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(db, p2->name);
+ pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(handle->db_local, p2->name);
/* localp2->files will be removed (target conflicts are handled by CHECK 1) */
if(localp2 && alpm_list_find_str(alpm_pkg_get_files(localp2), filestr)) {
/* skip removal of file, but not add. this will prevent a second
* package from removing the file when it was already installed
* by its new owner (whether the file is in backup array or not */
- trans->skip_remove = alpm_list_add(trans->skip_remove, strdup(filestr));
- _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr);
+ handle->trans->skip_remove =
+ alpm_list_add(handle->trans->skip_remove, strdup(filestr));
+ _alpm_log(handle, PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr);
resolved_conflict = 1;
}
}
@@ -481,17 +492,17 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
char *dir = malloc(strlen(filestr) + 2);
sprintf(dir, "%s/", filestr);
if(alpm_list_find_str(alpm_pkg_get_files(dbpkg),dir)) {
- _alpm_log(PM_LOG_DEBUG, "check if all files in %s belongs to %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "check if all files in %s belongs to %s\n",
dir, dbpkg->name);
- resolved_conflict = dir_belongsto_pkg(filestr, dbpkg);
+ resolved_conflict = dir_belongsto_pkg(handle->root, filestr, dbpkg);
}
free(dir);
}
if(!resolved_conflict && dbpkg) {
- char *rpath = calloc(PATH_MAX+1, sizeof(char));
+ char *rpath = calloc(PATH_MAX, sizeof(char));
if(!realpath(path, rpath)) {
- FREE(rpath);
+ free(rpath);
continue;
}
char *filestr = rpath + strlen(handle->root);
@@ -502,9 +513,13 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
}
if(!resolved_conflict) {
- _alpm_log(PM_LOG_DEBUG, "file found in conflict: %s\n", path);
- conflicts = add_fileconflict(conflicts, PM_FILECONFLICT_FILESYSTEM,
+ conflicts = add_fileconflict(handle, conflicts, PM_FILECONFLICT_FILESYSTEM,
path, p1->name, NULL);
+ if(!conflicts) {
+ FREELIST(conflicts);
+ FREELIST(tmpfiles);
+ RET_ERR(handle, PM_ERR_MEMORY, NULL);
+ }
}
}
FREELIST(tmpfiles);
@@ -517,78 +532,44 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->package1;
}
const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->package2;
}
const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->reason;
}
const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->target;
}
pmfileconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return -1);
ASSERT(conflict != NULL, return -1);
-
return conflict->type;
}
const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->file;
}
const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(conflict != NULL, return NULL);
-
return conflict->ctarget;
}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 418d3f61..7a3784a2 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -37,13 +37,12 @@ struct __pmfileconflict_t {
char *ctarget;
};
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason);
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
void _alpm_conflict_free(pmconflict_t *conflict);
-alpm_list_t *_alpm_innerconflicts(alpm_list_t *packages);
+alpm_list_t *_alpm_innerconflicts(pmhandle_t *handle, alpm_list_t *packages);
alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages);
-alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
- alpm_list_t *upgrade, alpm_list_t *remove);
+alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
+ alpm_list_t *upgrade, alpm_list_t *remove);
void _alpm_fileconflict_free(pmfileconflict_t *conflict);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 31336144..0584a36f 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -45,17 +45,16 @@
*/
/** Register a sync database of packages. */
-pmdb_t SYMEXPORT *alpm_db_register_sync(const char *treename)
+pmdb_t SYMEXPORT *alpm_db_register_sync(pmhandle_t *handle, const char *treename)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL));
- ASSERT(treename != NULL && strlen(treename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+ ASSERT(handle != NULL, return NULL);
+ ASSERT(treename != NULL && strlen(treename) != 0,
+ RET_ERR(handle, PM_ERR_WRONG_ARGS, NULL));
/* Do not register a database if a transaction is on-going */
- ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
+ ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, NULL));
- return _alpm_db_register_sync(treename);
+ return _alpm_db_register_sync(handle, treename);
}
/* Helper function for alpm_db_unregister{_all} */
@@ -65,22 +64,20 @@ void _alpm_db_unregister(pmdb_t *db)
return;
}
- _alpm_log(PM_LOG_DEBUG, "unregistering database '%s'\n", db->treename);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "unregistering database '%s'\n", db->treename);
_alpm_db_free(db);
}
/** Unregister all package databases. */
-int SYMEXPORT alpm_db_unregister_all(void)
+int SYMEXPORT alpm_db_unregister_all(pmhandle_t *handle)
{
alpm_list_t *i;
pmdb_t *db;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
- ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
+ ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
/* unregister all sync dbs */
for(i = handle->dbs_sync; i; i = i->next) {
@@ -96,14 +93,13 @@ int SYMEXPORT alpm_db_unregister_all(void)
int SYMEXPORT alpm_db_unregister(pmdb_t *db)
{
int found = 0;
-
- ALPM_LOG_FUNC;
+ pmhandle_t *handle;
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
- ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
+ handle = db->handle;
+ ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
handle->db_local = NULL;
@@ -122,7 +118,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
}
if(!found) {
- RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
+ RET_ERR(handle, PM_ERR_DB_NOT_FOUND, -1);
}
db->ops->unregister(db);
@@ -132,22 +128,14 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db)
/** Get the serverlist of a database. */
alpm_list_t SYMEXPORT *alpm_db_get_servers(const pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, NULL));
-
- return(db->servers);
+ ASSERT(db != NULL, return NULL);
+ return db->servers;
}
/** Set the serverlist of a database. */
int SYMEXPORT alpm_db_set_servers(pmdb_t *db, alpm_list_t *servers)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
-
+ ASSERT(db != NULL, return -1);
if(db->servers) FREELIST(db->servers);
db->servers = servers;
return 0;
@@ -158,7 +146,7 @@ static char *sanitize_url(const char *url)
char *newurl;
size_t len = strlen(url);
- STRDUP(newurl, url, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newurl, url, return NULL);
/* strip the trailing slash if one exists */
if(newurl[len - 1] == '/') {
newurl[len - 1] = '\0';
@@ -175,18 +163,16 @@ int SYMEXPORT alpm_db_add_server(pmdb_t *db, const char *url)
{
char *newurl;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(url != NULL && strlen(url) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL, return -1);
+ ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
if(!newurl) {
return -1;
}
db->servers = alpm_list_add(db->servers, newurl);
- _alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
db->treename, newurl);
return 0;
@@ -202,11 +188,9 @@ int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url)
{
char *newurl, *vdata = NULL;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(url != NULL && strlen(url) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL, return -1);
+ ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
if(!newurl) {
@@ -215,7 +199,7 @@ int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url)
db->servers = alpm_list_remove_str(db->servers, newurl, &vdata);
free(newurl);
if(vdata) {
- _alpm_log(PM_LOG_DEBUG, "removed server URL from database '%s': %s\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "removed server URL from database '%s': %s\n",
db->treename, newurl);
free(vdata);
return 0;
@@ -230,55 +214,26 @@ int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url)
*/
int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify)
{
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ ASSERT(db != NULL, return -1);
db->pgp_verify = verify;
- _alpm_log(PM_LOG_DEBUG, "adding VerifySig option to database '%s': %d\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "adding VerifySig option to database '%s': %d\n",
db->treename, verify);
- return(0);
+ return 0;
}
/** Get the name of a package database. */
const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
-
return db->treename;
}
-/** Get a download URL for the package database. */
-const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
-{
- char *url;
-
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
- ASSERT(db != NULL, return NULL);
- ASSERT(db->servers != NULL, return NULL);
-
- url = (char *)db->servers->data;
-
- return url;
-}
-
-
/** Get a package entry from a package database. */
pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
ASSERT(name != NULL && strlen(name) != 0, return NULL);
@@ -288,22 +243,13 @@ pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
/** Get the package cache of a package database. */
alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
-
return _alpm_db_get_pkgcache(db);
}
/** Get a group entry from a package database. */
pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
ASSERT(name != NULL && strlen(name) != 0, return NULL);
@@ -313,10 +259,6 @@ pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
/** Get the group cache of a package database. */
alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
return _alpm_db_get_grpcache(db);
@@ -325,10 +267,6 @@ alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
/** Searches a database. */
alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return NULL);
ASSERT(db != NULL, return NULL);
return _alpm_db_search(db, needles);
@@ -337,18 +275,16 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
/** Set install reason for a package in db. */
int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL && name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(db != NULL, return -1);
+ /* TODO assert db == db_local ? shouldn't need a db param at all here... */
+ ASSERT(name != NULL, RET_ERR(db->handle, PM_ERR_WRONG_ARGS, -1));
pmpkg_t *pkg = _alpm_db_get_pkgfromcache(db, name);
if(pkg == NULL) {
- RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ RET_ERR(db->handle, PM_ERR_PKG_NOT_FOUND, -1);
}
- _alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
if(alpm_pkg_get_reason(pkg) == reason) {
/* we are done */
return 0;
@@ -357,7 +293,7 @@ int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t
pkg->reason = reason;
/* write DESC */
if(_alpm_local_db_write(db, pkg, INFRQ_DESC)) {
- RET_ERR(PM_ERR_DB_WRITE, -1);
+ RET_ERR(db->handle, PM_ERR_DB_WRITE, -1);
}
return 0;
@@ -369,19 +305,16 @@ pmdb_t *_alpm_db_new(const char *treename, int is_local)
{
pmdb_t *db;
- ALPM_LOG_FUNC;
-
- CALLOC(db, 1, sizeof(pmdb_t), RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(db->treename, treename, RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(db, 1, sizeof(pmdb_t), return NULL);
+ STRDUP(db->treename, treename, return NULL);
db->is_local = is_local;
+ db->pgp_verify = PM_PGP_VERIFY_UNKNOWN;
return db;
}
void _alpm_db_free(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
/* cleanup pkgcache */
_alpm_db_free_pkgcache(db);
/* cleanup server list */
@@ -402,23 +335,23 @@ const char *_alpm_db_path(pmdb_t *db)
const char *dbpath;
size_t pathsize;
- dbpath = alpm_option_get_dbpath();
+ dbpath = alpm_option_get_dbpath(db->handle);
if(!dbpath) {
- _alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
- RET_ERR(PM_ERR_DB_OPEN, NULL);
+ _alpm_log(db->handle, PM_LOG_ERROR, _("database path is undefined\n"));
+ RET_ERR(db->handle, PM_ERR_DB_OPEN, NULL);
}
if(db->is_local) {
pathsize = strlen(dbpath) + strlen(db->treename) + 2;
- CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, PM_ERR_MEMORY, NULL));
sprintf(db->_path, "%s%s/", dbpath, db->treename);
} else {
pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 4;
- CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, PM_ERR_MEMORY, NULL));
/* all sync DBs now reside in the sync/ subdir of the dbpath */
sprintf(db->_path, "%ssync/%s.db", dbpath, db->treename);
}
- _alpm_log(PM_LOG_DEBUG, "database path for tree %s set to %s\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "database path for tree %s set to %s\n",
db->treename, db->_path);
}
return db->_path;
@@ -432,6 +365,20 @@ int _alpm_db_version(pmdb_t *db)
return db->ops->version(db);
}
+char *_alpm_db_sig_path(pmdb_t *db)
+{
+ char *sigpath;
+ size_t len;
+ const char *dbfile = _alpm_db_path(db);
+ if(!db || !dbfile) {
+ return NULL;
+ }
+ len = strlen(dbfile) + strlen(".sig") + 1;
+ CALLOC(sigpath, len, sizeof(char), RET_ERR(db->handle, PM_ERR_MEMORY, NULL));
+ sprintf(sigpath, "%s.sig", dbfile);
+ return sigpath;
+}
+
int _alpm_db_cmp(const void *d1, const void *d2)
{
pmdb_t *db1 = (pmdb_t *)d1;
@@ -446,8 +393,6 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
/* copy the pkgcache- we will free the list var after each needle */
alpm_list_t *list = alpm_list_copy(_alpm_db_get_pkgcache(db));
- ALPM_LOG_FUNC;
-
for(i = needles; i; i = i->next) {
char *targ;
regex_t reg;
@@ -457,10 +402,10 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
}
ret = NULL;
targ = i->data;
- _alpm_log(PM_LOG_DEBUG, "searching for target '%s'\n", targ);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "searching for target '%s'\n", targ);
if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
- RET_ERR(PM_ERR_INVALID_REGEX, NULL);
+ RET_ERR(db->handle, PM_ERR_INVALID_REGEX, NULL);
}
for(j = list; j; j = j->next) {
@@ -499,7 +444,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
}
if(matched != NULL) {
- _alpm_log(PM_LOG_DEBUG, " search target '%s' matched '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, " search target '%s' matched '%s'\n",
targ, matched);
ret = alpm_list_add(ret, pkg);
}
@@ -520,17 +465,15 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
*/
int _alpm_db_load_pkgcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return -1;
}
_alpm_db_free_pkgcache(db);
- _alpm_log(PM_LOG_DEBUG, "loading package cache for repository '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "loading package cache for repository '%s'\n",
db->treename);
if(db->ops->populate(db) == -1) {
- _alpm_log(PM_LOG_DEBUG,
+ _alpm_log(db->handle, PM_LOG_DEBUG,
"failed to load package cache for repository '%s'\n", db->treename);
return -1;
}
@@ -541,13 +484,11 @@ int _alpm_db_load_pkgcache(pmdb_t *db)
void _alpm_db_free_pkgcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
if(db == NULL || !db->pkgcache_loaded) {
return;
}
- _alpm_log(PM_LOG_DEBUG, "freeing package cache for repository '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "freeing package cache for repository '%s'\n",
db->treename);
alpm_list_free_inner(_alpm_db_get_pkgcache(db),
@@ -560,8 +501,6 @@ void _alpm_db_free_pkgcache(pmdb_t *db)
pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return NULL;
}
@@ -572,7 +511,7 @@ pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
/* hmmm, still NULL ?*/
if(!db->pkgcache) {
- _alpm_log(PM_LOG_DEBUG, "warning: pkgcache is NULL for db '%s'\n", db->treename);
+ _alpm_log(db->handle, PM_LOG_DEBUG, "warning: pkgcache is NULL for db '%s'\n", db->treename);
}
return db->pkgcache;
@@ -580,8 +519,6 @@ pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
pmpkghash_t *hash = _alpm_db_get_pkgcache_hash(db);
if(hash == NULL) {
@@ -596,8 +533,6 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
{
pmpkg_t *newpkg;
- ALPM_LOG_FUNC;
-
if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
return -1;
}
@@ -607,7 +542,7 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
return -1;
}
- _alpm_log(PM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n",
alpm_pkg_get_name(newpkg), db->treename);
db->pkgcache = _alpm_pkghash_add_sorted(db->pkgcache, newpkg);
@@ -620,19 +555,17 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
{
pmpkg_t *data = NULL;
- ALPM_LOG_FUNC;
-
if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
return -1;
}
- _alpm_log(PM_LOG_DEBUG, "removing entry '%s' from '%s' cache\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "removing entry '%s' from '%s' cache\n",
alpm_pkg_get_name(pkg), db->treename);
db->pkgcache = _alpm_pkghash_remove(db->pkgcache, pkg, &data);
if(data == NULL) {
/* package not found */
- _alpm_log(PM_LOG_DEBUG, "cannot remove entry '%s' from '%s' cache: not found\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "cannot remove entry '%s' from '%s' cache: not found\n",
alpm_pkg_get_name(pkg), db->treename);
return -1;
}
@@ -646,15 +579,13 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
{
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return NULL;
}
pmpkghash_t *pkgcache = _alpm_db_get_pkgcache_hash(db);
if(!pkgcache) {
- _alpm_log(PM_LOG_DEBUG, "warning: failed to get '%s' from NULL pkgcache\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "warning: failed to get '%s' from NULL pkgcache\n",
target);
return NULL;
}
@@ -668,13 +599,11 @@ int _alpm_db_load_grpcache(pmdb_t *db)
{
alpm_list_t *lp;
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return -1;
}
- _alpm_log(PM_LOG_DEBUG, "loading group cache for repository '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "loading group cache for repository '%s'\n",
db->treename);
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
@@ -703,6 +632,10 @@ int _alpm_db_load_grpcache(pmdb_t *db)
}
/* we didn't find the group, so create a new one with this name */
grp = _alpm_grp_new(grpname);
+ if(!grp) {
+ _alpm_db_free_grpcache(db);
+ return -1;
+ }
grp->packages = alpm_list_add(grp->packages, pkg);
db->grpcache = alpm_list_add(db->grpcache, grp);
}
@@ -716,13 +649,11 @@ void _alpm_db_free_grpcache(pmdb_t *db)
{
alpm_list_t *lg;
- ALPM_LOG_FUNC;
-
if(db == NULL || !db->grpcache_loaded) {
return;
}
- _alpm_log(PM_LOG_DEBUG, "freeing group cache for repository '%s'\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "freeing group cache for repository '%s'\n",
db->treename);
for(lg = db->grpcache; lg; lg = lg->next) {
@@ -735,8 +666,6 @@ void _alpm_db_free_grpcache(pmdb_t *db)
alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db)
{
- ALPM_LOG_FUNC;
-
if(db == NULL) {
return NULL;
}
@@ -752,8 +681,6 @@ pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
{
alpm_list_t *i;
- ALPM_LOG_FUNC;
-
if(db == NULL || target == NULL || strlen(target) == 0) {
return NULL;
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 399e2d56..e3faeeb4 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -22,9 +22,6 @@
#ifndef _ALPM_DB_H
#define _ALPM_DB_H
-#include "alpm.h"
-#include "pkghash.h"
-
#include <time.h>
/* libarchive */
@@ -32,6 +29,7 @@
#include <archive_entry.h>
#include "alpm.h"
+#include "pkghash.h"
#include "signing.h"
/* Database entries */
@@ -53,6 +51,7 @@ struct db_operations {
/* Database */
struct __pmdb_t {
+ pmhandle_t *handle;
char *treename;
/* do not access directly, use _alpm_db_path(db) for lazy access */
char *_path;
@@ -73,11 +72,12 @@ struct __pmdb_t {
pmdb_t *_alpm_db_new(const char *treename, int is_local);
void _alpm_db_free(pmdb_t *db);
const char *_alpm_db_path(pmdb_t *db);
+char *_alpm_db_sig_path(pmdb_t *db);
int _alpm_db_version(pmdb_t *db);
int _alpm_db_cmp(const void *d1, const void *d2);
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles);
-pmdb_t *_alpm_db_register_local(void);
-pmdb_t *_alpm_db_register_sync(const char *treename);
+pmdb_t *_alpm_db_register_local(pmhandle_t *handle);
+pmdb_t *_alpm_db_register_sync(pmhandle_t *handle, const char *treename);
void _alpm_db_unregister(pmdb_t *db);
/* be_*.c, backend specific calls */
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index d3213fd1..aa76b492 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -78,6 +78,10 @@ static alpm_list_t *graph_init(alpm_list_t *deltas, int reverse)
/* create the vertices */
for(i = deltas; i; i = i->next) {
pmgraph_t *v = _alpm_graph_new();
+ if(!v) {
+ alpm_list_free(vertices);
+ return NULL;
+ }
pmdelta_t *vdelta = i->data;
vdelta->download_size = vdelta->delta_size;
v->weight = LONG_MAX;
@@ -111,7 +115,7 @@ static alpm_list_t *graph_init(alpm_list_t *deltas, int reverse)
return vertices;
}
-static void graph_init_size(alpm_list_t *vertices)
+static void graph_init_size(pmhandle_t *handle, alpm_list_t *vertices)
{
alpm_list_t *i;
@@ -121,7 +125,7 @@ static void graph_init_size(alpm_list_t *vertices)
pmdelta_t *vdelta = v->data;
/* determine whether the delta file already exists */
- fpath = _alpm_filecache_find(vdelta->delta);
+ fpath = _alpm_filecache_find(handle, vdelta->delta);
md5sum = alpm_compute_md5sum(fpath);
if(fpath && md5sum && strcmp(md5sum, vdelta->delta_md5) == 0) {
vdelta->download_size = 0;
@@ -130,7 +134,7 @@ static void graph_init_size(alpm_list_t *vertices)
FREE(md5sum);
/* determine whether a base 'from' file exists */
- fpath = _alpm_filecache_find(vdelta->from);
+ fpath = _alpm_filecache_find(handle, vdelta->from);
if(fpath) {
v->weight = vdelta->download_size;
}
@@ -211,6 +215,7 @@ static off_t shortest_path(alpm_list_t *vertices, const char *to, alpm_list_t **
/** Calculates the shortest path from one version to another.
* The shortest path is defined as the path with the smallest combined
* size, not the length of the path.
+ * @param handle the context handle
* @param deltas the list of pmdelta_t * objects that a file has
* @param to the file to start the search at
* @param path the pointer to a list location where pmdelta_t * objects that
@@ -218,28 +223,26 @@ static off_t shortest_path(alpm_list_t *vertices, const char *to, alpm_list_t **
* possible with the files available.
* @return the size of the path stored, or LONG_MAX if path is unfindable
*/
-off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
+off_t _alpm_shortest_delta_path(pmhandle_t *handle, alpm_list_t *deltas,
const char *to, alpm_list_t **path)
{
alpm_list_t *bestpath = NULL;
alpm_list_t *vertices;
off_t bestsize = LONG_MAX;
- ALPM_LOG_FUNC;
-
if(deltas == NULL) {
*path = NULL;
return bestsize;
}
- _alpm_log(PM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);
+ _alpm_log(handle, PM_LOG_DEBUG, "started delta shortest-path search for '%s'\n", to);
vertices = graph_init(deltas, 0);
- graph_init_size(vertices);
+ graph_init_size(handle, vertices);
dijkstra(vertices);
bestsize = shortest_path(vertices, to, &bestpath);
- _alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize);
+ _alpm_log(handle, PM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize);
alpm_list_free_inner(vertices, _alpm_graph_free);
alpm_list_free(vertices);
@@ -312,17 +315,17 @@ pmdelta_t *_alpm_delta_parse(char *line)
}
regfree(&reg);
- CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(delta, 1, sizeof(pmdelta_t), return NULL);
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- STRDUP(delta->delta, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(delta->delta, tmp2, return NULL);
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- STRDUP(delta->delta_md5, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(delta->delta_md5, tmp2, return NULL);
tmp2 = tmp;
tmp = strchr(tmp, ' ');
@@ -332,12 +335,10 @@ pmdelta_t *_alpm_delta_parse(char *line)
tmp2 = tmp;
tmp = strchr(tmp, ' ');
*(tmp++) = '\0';
- STRDUP(delta->from, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(delta->from, tmp2, return NULL);
tmp2 = tmp;
- STRDUP(delta->to, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
-
- _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%jd'\n", delta->from, delta->to, (intmax_t)delta->delta_size);
+ STRDUP(delta->to, tmp2, return NULL);
return delta;
}
diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h
index bd196bab..d7725f5a 100644
--- a/lib/libalpm/delta.h
+++ b/lib/libalpm/delta.h
@@ -43,7 +43,7 @@ struct __pmdelta_t {
pmdelta_t *_alpm_delta_parse(char *line);
void _alpm_delta_free(pmdelta_t *delta);
-off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
+off_t _alpm_shortest_delta_path(pmhandle_t *handle, alpm_list_t *deltas,
const char *to, alpm_list_t **path);
/* max percent of package size to download deltas */
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index c5fb92ef..db4130c3 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -35,6 +35,7 @@
#include "package.h"
#include "db.h"
#include "handle.h"
+#include "trans.h"
void _alpm_dep_free(pmdepend_t *dep)
{
@@ -48,13 +49,11 @@ static pmdepmissing_t *depmiss_new(const char *target, pmdepend_t *dep,
{
pmdepmissing_t *miss;
- ALPM_LOG_FUNC;
+ MALLOC(miss, sizeof(pmdepmissing_t), return NULL);
- MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL));
-
- STRDUP(miss->target, target, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(miss->target, target, return NULL);
miss->depend = _alpm_dep_dup(dep);
- STRDUP(miss->causingpkg, causingpkg, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(miss->causingpkg, causingpkg, return NULL);
return miss;
}
@@ -127,20 +126,19 @@ static alpm_list_t *dep_graph_init(alpm_list_t *targets)
* This function returns the new alpm_list_t* target list.
*
*/
-alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
+alpm_list_t *_alpm_sortbydeps(pmhandle_t *handle,
+ alpm_list_t *targets, int reverse)
{
alpm_list_t *newtargs = NULL;
alpm_list_t *vertices = NULL;
alpm_list_t *vptr;
pmgraph_t *vertex;
- ALPM_LOG_FUNC;
-
if(targets == NULL) {
return NULL;
}
- _alpm_log(PM_LOG_DEBUG, "started sorting dependencies\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "started sorting dependencies\n");
vertices = dep_graph_init(targets);
@@ -163,13 +161,13 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
pmpkg_t *childpkg = nextchild->data;
const char *message;
- _alpm_log(PM_LOG_WARNING, _("dependency cycle detected:\n"));
+ _alpm_log(handle, PM_LOG_WARNING, _("dependency cycle detected:\n"));
if(reverse) {
message =_("%s will be removed after its %s dependency\n");
} else {
message =_("%s will be installed before its %s dependency\n");
}
- _alpm_log(PM_LOG_WARNING, message, vertexpkg->name, childpkg->name);
+ _alpm_log(handle, PM_LOG_WARNING, message, vertexpkg->name, childpkg->name);
}
}
if(!found) {
@@ -188,7 +186,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
}
}
- _alpm_log(PM_LOG_DEBUG, "sorting dependencies finished\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "sorting dependencies finished\n");
if(reverse) {
/* reverse the order */
@@ -204,9 +202,9 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse)
return newtargs;
}
-static int no_dep_version(void)
+static int no_dep_version(pmhandle_t *handle)
{
- int flags = alpm_trans_get_flags();
+ int flags = alpm_trans_get_flags(handle);
return flags != -1 && (flags & PM_TRANS_FLAG_NODEPVERSION);
}
@@ -250,6 +248,9 @@ static pmpkg_t *find_dep_satisfier(alpm_list_t *pkgs, pmdepend_t *dep)
pmpkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
{
pmdepend_t *dep = _alpm_splitdep(depstring);
+ if(!dep) {
+ return NULL;
+ }
pmpkg_t *pkg = find_dep_satisfier(pkgs, dep);
_alpm_dep_free(dep);
return pkg;
@@ -257,22 +258,21 @@ pmpkg_t SYMEXPORT *alpm_find_satisfier(alpm_list_t *pkgs, const char *depstring)
/** Checks dependencies and returns missing ones in a list.
* Dependencies can include versions with depmod operators.
+ * @param handle the context handle
* @param pkglist the list of local packages
- * @param reversedeps handles the backward dependencies
* @param remove an alpm_list_t* of packages to be removed
* @param upgrade an alpm_list_t* of packages to be upgraded (remove-then-upgrade)
+ * @param reversedeps handles the backward dependencies
* @return an alpm_list_t* of pmdepmissing_t pointers.
*/
-alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
- alpm_list_t *remove, alpm_list_t *upgrade)
+alpm_list_t SYMEXPORT *alpm_checkdeps(pmhandle_t *handle, alpm_list_t *pkglist,
+ alpm_list_t *remove, alpm_list_t *upgrade, int reversedeps)
{
alpm_list_t *i, *j;
alpm_list_t *targets, *dblist = NULL, *modified = NULL;
alpm_list_t *baddeps = NULL;
int nodepversion;
- ALPM_LOG_FUNC;
-
targets = alpm_list_join(alpm_list_copy(remove), alpm_list_copy(upgrade));
for(i = pkglist; i; i = i->next) {
pmpkg_t *pkg = i->data;
@@ -284,12 +284,12 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
}
alpm_list_free(targets);
- nodepversion = no_dep_version();
+ nodepversion = no_dep_version(handle);
/* look for unsatisfied dependencies of the upgrade list */
for(i = upgrade; i; i = i->next) {
pmpkg_t *tp = i->data;
- _alpm_log(PM_LOG_DEBUG, "checkdeps: package %s-%s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "checkdeps: package %s-%s\n",
alpm_pkg_get_name(tp), alpm_pkg_get_version(tp));
for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
@@ -302,7 +302,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
/* Unsatisfied dependency in the upgrade list */
pmdepmissing_t *miss;
char *missdepstring = alpm_dep_compute_string(depend);
- _alpm_log(PM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n",
missdepstring, alpm_pkg_get_name(tp));
free(missdepstring);
miss = depmiss_new(alpm_pkg_get_name(tp), depend, NULL);
@@ -329,7 +329,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_list_t *pkglist, int reversedeps,
!find_dep_satisfier(dblist, depend)) {
pmdepmissing_t *miss;
char *missdepstring = alpm_dep_compute_string(depend);
- _alpm_log(PM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n",
missdepstring, alpm_pkg_get_name(lp));
free(missdepstring);
miss = depmiss_new(lp->name, depend, alpm_pkg_get_name(causingpkg));
@@ -418,7 +418,7 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
return NULL;
}
- CALLOC(depend, 1, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(depend, 1, sizeof(pmdepend_t), return NULL);
/* Find a version comparator if one exists. If it does, set the type and
* increment the ptr accordingly so we can copy the right strings. */
@@ -444,11 +444,10 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
}
/* copy the right parts to the right places */
- STRNDUP(depend->name, depstring, ptr - depstring,
- RET_ERR(PM_ERR_MEMORY, NULL));
+ STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
depend->name_hash = _alpm_hash_sdbm(depend->name);
if(version) {
- STRDUP(depend->version, version, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(depend->version, version, return NULL);
}
return depend;
@@ -457,11 +456,11 @@ pmdepend_t *_alpm_splitdep(const char *depstring)
pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
{
pmdepend_t *newdep;
- CALLOC(newdep, 1, sizeof(pmdepend_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(newdep, 1, sizeof(pmdepend_t), return NULL);
- STRDUP(newdep->name, dep->name, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newdep->name, dep->name, return NULL);
newdep->name_hash = dep->name_hash;
- STRDUP(newdep->version, dep->version, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newdep->version, dep->version, return NULL);
newdep->mod = dep->mod;
return newdep;
@@ -483,7 +482,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets,
if(!include_explicit) {
/* see if it was explicitly installed */
if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) {
- _alpm_log(PM_LOG_DEBUG, "excluding %s -- explicitly installed\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "excluding %s -- explicitly installed\n",
alpm_pkg_get_name(pkg));
return 0;
}
@@ -521,8 +520,6 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
{
alpm_list_t *i, *j;
- ALPM_LOG_FUNC;
-
if(db == NULL || targs == NULL) {
return;
}
@@ -533,7 +530,7 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
pmpkg_t *deppkg = j->data;
if(_alpm_dep_edge(pkg, deppkg)
&& can_remove_package(db, deppkg, targs, include_explicit)) {
- _alpm_log(PM_LOG_DEBUG, "adding '%s' to the targets\n",
+ _alpm_log(db->handle, PM_LOG_DEBUG, "adding '%s' to the targets\n",
alpm_pkg_get_name(deppkg));
/* add it to the target list */
targs = alpm_list_add(targs, _alpm_pkg_dup(deppkg));
@@ -545,6 +542,7 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
/**
* helper function for resolvedeps: search for dep satisfier in dbs
*
+ * @param handle the context handle
* @param dep is the dependency to search for
* @param dbs are the databases to search
* @param excluding are the packages to exclude from the search
@@ -554,8 +552,8 @@ void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit)
* an error code without prompting
* @return the resolved package
**/
-static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
- alpm_list_t *excluding, int prompt)
+static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep,
+ alpm_list_t *dbs, alpm_list_t *excluding, int prompt)
{
alpm_list_t *i, *j;
int ignored = 0;
@@ -573,7 +571,7 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install);
} else {
- _alpm_log(PM_LOG_WARNING, _("ignoring package %s-%s\n"), pkg->name, pkg->version);
+ _alpm_log(handle, PM_LOG_WARNING, _("ignoring package %s-%s\n"), pkg->name, pkg->version);
}
if(!install) {
ignored = 1;
@@ -595,14 +593,14 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG,
pkg, NULL, NULL, &install);
} else {
- _alpm_log(PM_LOG_WARNING, _("ignoring package %s-%s\n"), pkg->name, pkg->version);
+ _alpm_log(handle, PM_LOG_WARNING, _("ignoring package %s-%s\n"), pkg->name, pkg->version);
}
if(!install) {
ignored = 1;
continue;
}
}
- _alpm_log(PM_LOG_DEBUG, "provider found (%s provides %s)\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "provider found (%s provides %s)\n",
pkg->name, dep->name);
providers = alpm_list_add(providers, pkg);
/* keep looking for other providers in the all dbs */
@@ -637,9 +635,9 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
}
if(ignored) { /* resolvedeps will override these */
- pm_errno = PM_ERR_PKG_IGNORED;
+ handle->pm_errno = PM_ERR_PKG_IGNORED;
} else {
- pm_errno = PM_ERR_PKG_NOT_FOUND;
+ handle->pm_errno = PM_ERR_PKG_NOT_FOUND;
}
return NULL;
}
@@ -648,11 +646,13 @@ static pmpkg_t *resolvedep(pmdepend_t *dep, alpm_list_t *dbs,
* First look for a literal, going through each db one by one. Then look for
* providers. The first satisfier found is returned.
* The dependency can include versions with depmod operators.
+ * @param handle the context handle
* @param dbs an alpm_list_t* of pmdb_t where the satisfier will be searched
* @param depstring package or provision name, versioned or not
* @return a pmpkg_t* satisfying depstring
*/
-pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstring)
+pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(pmhandle_t *handle,
+ alpm_list_t *dbs, const char *depstring)
{
pmdepend_t *dep;
pmpkg_t *pkg;
@@ -661,7 +661,7 @@ pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstri
dep = _alpm_splitdep(depstring);
ASSERT(dep, return NULL);
- pkg = resolvedep(dep, dbs, NULL, 1);
+ pkg = resolvedep(handle, dep, dbs, NULL, 1);
_alpm_dep_free(dep);
return pkg;
}
@@ -670,8 +670,8 @@ pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstri
* Computes resolvable dependencies for a given package and adds that package
* and those resolvable dependencies to a list.
*
+ * @param handle the context handle
* @param localpkgs is the list of local packages
- * @param dbs_sync are the sync databases
* @param pkg is the package to resolve
* @param packages is a pointer to a list of packages which will be
* searched first for any dependency packages needed to complete the
@@ -686,7 +686,7 @@ pmpkg_t SYMEXPORT *alpm_find_dbs_satisfier(alpm_list_t *dbs, const char *depstri
* unresolvable dependency, in which case the [*packages] list will be
* unmodified by this function
*/
-int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pkg,
+int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg,
alpm_list_t *preferred, alpm_list_t **packages,
alpm_list_t *remove, alpm_list_t **data)
{
@@ -696,8 +696,6 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
alpm_list_t *deps = NULL;
alpm_list_t *packages_copy;
- ALPM_LOG_FUNC;
-
if(_alpm_pkg_find(*packages, pkg->name) != NULL) {
return 0;
}
@@ -709,11 +707,11 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
on that list */
*packages = alpm_list_add(*packages, pkg);
- _alpm_log(PM_LOG_DEBUG, "started resolving dependencies\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "started resolving dependencies\n");
for(i = alpm_list_last(*packages); i; i = i->next) {
pmpkg_t *tpkg = i->data;
targ = alpm_list_add(NULL, tpkg);
- deps = alpm_checkdeps(localpkgs, 0, remove, targ);
+ deps = alpm_checkdeps(handle, localpkgs, remove, targ, 0);
alpm_list_free(targ);
for(j = deps; j; j = j->next) {
@@ -730,12 +728,12 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
pmpkg_t *spkg = find_dep_satisfier(preferred, missdep);
if(!spkg) {
/* find a satisfier package in the given repositories */
- spkg = resolvedep(missdep, dbs_sync, *packages, 0);
+ spkg = resolvedep(handle, missdep, handle->dbs_sync, *packages, 0);
}
if(!spkg) {
- pm_errno = PM_ERR_UNSATISFIED_DEPS;
+ handle->pm_errno = PM_ERR_UNSATISFIED_DEPS;
char *missdepstring = alpm_dep_compute_string(missdep);
- _alpm_log(PM_LOG_WARNING,
+ _alpm_log(handle, PM_LOG_WARNING,
_("cannot resolve \"%s\", a dependency of \"%s\"\n"),
missdepstring, tpkg->name);
free(missdepstring);
@@ -744,7 +742,7 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
}
ret = -1;
} else {
- _alpm_log(PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "pulling dependency %s (needed by %s)\n",
alpm_pkg_get_name(spkg), alpm_pkg_get_name(tpkg));
*packages = alpm_list_add(*packages, spkg);
_alpm_depmiss_free(miss);
@@ -759,67 +757,43 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk
} else {
alpm_list_free(packages_copy);
}
- _alpm_log(PM_LOG_DEBUG, "finished resolving dependencies\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "finished resolving dependencies\n");
return ret;
}
const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(miss != NULL, return NULL);
-
return miss->target;
}
const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(miss != NULL, return NULL);
-
return miss->causingpkg;
}
pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(miss != NULL, return NULL);
-
return miss->depend;
}
pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(dep != NULL, return -1);
-
return dep->mod;
}
const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(dep != NULL, return NULL);
-
return dep->name;
}
const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(dep != NULL, return NULL);
-
return dep->version;
}
@@ -834,9 +808,6 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
char *str;
size_t len;
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(dep != NULL, return NULL);
if(dep->name) {
@@ -879,7 +850,7 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep)
* and ver will be empty when PM_DEP_MOD_ANY is the depend type. the
* reassignments above also ensure we do not do a strlen(NULL). */
len = strlen(name) + strlen(opr) + strlen(ver) + 1;
- MALLOC(str, len, RET_ERR(PM_ERR_MEMORY, NULL));
+ MALLOC(str, len, return NULL);
snprintf(str, len, "%s%s%s", name, opr, ver);
return str;
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index f728cad0..97c0918e 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -45,9 +45,9 @@ struct __pmdepmissing_t {
void _alpm_dep_free(pmdepend_t *dep);
pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep);
void _alpm_depmiss_free(pmdepmissing_t *miss);
-alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse);
+alpm_list_t *_alpm_sortbydeps(pmhandle_t *handle, alpm_list_t *targets, int reverse);
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit);
-int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pkg,
+int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg,
alpm_list_t *preferred, alpm_list_t **packages, alpm_list_t *remove,
alpm_list_t **data);
pmdepend_t *_alpm_splitdep(const char *depstring);
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index 102b42c6..079e683e 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -59,7 +59,7 @@ static int mount_point_cmp(const void *p1, const void *p2)
return -strcmp(mp1->mount_dir, mp2->mount_dir);
}
-static alpm_list_t *mount_point_list(void)
+static alpm_list_t *mount_point_list(pmhandle_t *handle)
{
alpm_list_t *mount_points = NULL, *ptr;
alpm_mountpoint_t *mp;
@@ -77,17 +77,17 @@ static alpm_list_t *mount_point_list(void)
while((mnt = getmntent(fp))) {
if(!mnt) {
- _alpm_log(PM_LOG_WARNING, _("could not get filesystem information\n"));
+ _alpm_log(handle, PM_LOG_WARNING, _("could not get filesystem information\n"));
continue;
}
if(statvfs(mnt->mnt_dir, &fsp) != 0) {
- _alpm_log(PM_LOG_WARNING,
+ _alpm_log(handle, PM_LOG_WARNING,
_("could not get filesystem information for %s: %s\n"),
mnt->mnt_dir, strerror(errno));
continue;
}
- CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, PM_ERR_MEMORY, NULL));
mp->mount_dir = strdup(mnt->mnt_dir);
mp->mount_dir_len = strlen(mp->mount_dir);
memcpy(&(mp->fsp), &fsp, sizeof(struct statvfs));
@@ -126,7 +126,7 @@ static alpm_list_t *mount_point_list(void)
mount_point_cmp);
for(ptr = mount_points; ptr != NULL; ptr = ptr->next) {
mp = ptr->data;
- _alpm_log(PM_LOG_DEBUG, "mountpoint: %s\n", mp->mount_dir);
+ _alpm_log(handle, PM_LOG_DEBUG, "mountpoint: %s\n", mp->mount_dir);
}
return mount_points;
}
@@ -148,8 +148,8 @@ static alpm_mountpoint_t *match_mount_point(const alpm_list_t *mount_points,
return NULL;
}
-static int calculate_removed_size(const alpm_list_t *mount_points,
- pmpkg_t *pkg)
+static int calculate_removed_size(pmhandle_t *handle,
+ const alpm_list_t *mount_points, pmpkg_t *pkg)
{
alpm_list_t *file;
@@ -171,7 +171,7 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
mp = match_mount_point(mount_points, path);
if(mp == NULL) {
- _alpm_log(PM_LOG_WARNING,
+ _alpm_log(handle, PM_LOG_WARNING,
_("could not determine mount point for file %s\n"), filename);
continue;
}
@@ -185,15 +185,15 @@ static int calculate_removed_size(const alpm_list_t *mount_points,
return 0;
}
-static int calculate_installed_size(const alpm_list_t *mount_points,
- pmpkg_t *pkg)
+static int calculate_installed_size(pmhandle_t *handle,
+ const alpm_list_t *mount_points, pmpkg_t *pkg)
{
int ret=0;
struct archive *archive;
struct archive_entry *entry;
if((archive = archive_read_new()) == NULL) {
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
ret = -1;
goto cleanup;
}
@@ -203,7 +203,7 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
if(archive_read_open_filename(archive, pkg->origin_data.file,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- pm_errno = PM_ERR_PKG_OPEN;
+ handle->pm_errno = PM_ERR_PKG_OPEN;
ret = -1;
goto cleanup;
}
@@ -226,14 +226,14 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
/* approximate space requirements for db entries */
if(filename[0] == '.') {
- filename = alpm_option_get_dbpath();
+ filename = alpm_option_get_dbpath(handle);
}
snprintf(path, PATH_MAX, "%s%s", handle->root, filename);
mp = match_mount_point(mount_points, path);
if(mp == NULL) {
- _alpm_log(PM_LOG_WARNING,
+ _alpm_log(handle, PM_LOG_WARNING,
_("could not determine mount point for file %s\n"), filename);
continue;
}
@@ -244,9 +244,9 @@ static int calculate_installed_size(const alpm_list_t *mount_points,
mp->used |= USED_INSTALL;
if(archive_read_data_skip(archive)) {
- _alpm_log(PM_LOG_ERROR, _("error while reading package %s: %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkg->name, archive_error_string(archive));
- pm_errno = PM_ERR_LIBARCHIVE;
+ handle->pm_errno = PM_ERR_LIBARCHIVE;
break;
}
}
@@ -257,23 +257,24 @@ cleanup:
return ret;
}
-int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
+int _alpm_check_diskspace(pmhandle_t *handle)
{
alpm_list_t *mount_points, *i;
alpm_mountpoint_t *root_mp;
size_t replaces = 0, current = 0, numtargs;
int abort = 0;
alpm_list_t *targ;
+ pmtrans_t *trans = handle->trans;
numtargs = alpm_list_count(trans->add);
- mount_points = mount_point_list();
+ mount_points = mount_point_list(handle);
if(mount_points == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not determine filesystem mount points\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not determine filesystem mount points\n"));
return -1;
}
root_mp = match_mount_point(mount_points, handle->root);
if(root_mp == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not determine root mount point %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not determine root mount point %s\n"),
handle->root);
return -1;
}
@@ -288,7 +289,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
numtargs, current);
local_pkg = targ->data;
- calculate_removed_size(mount_points, local_pkg);
+ calculate_removed_size(handle, mount_points, local_pkg);
}
}
@@ -300,11 +301,11 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
pkg = targ->data;
/* is this package already installed? */
- local_pkg = _alpm_db_get_pkgfromcache(db_local, pkg->name);
+ local_pkg = _alpm_db_get_pkgfromcache(handle->db_local, pkg->name);
if(local_pkg) {
- calculate_removed_size(mount_points, local_pkg);
+ calculate_removed_size(handle, mount_points, local_pkg);
}
- calculate_installed_size(mount_points, pkg);
+ calculate_installed_size(handle, mount_points, pkg);
for(i = mount_points; i; i = alpm_list_next(i)) {
alpm_mountpoint_t *data = i->data;
@@ -320,7 +321,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
for(i = mount_points; i; i = alpm_list_next(i)) {
alpm_mountpoint_t *data = i->data;
if(data->used && data->read_only) {
- _alpm_log(PM_LOG_ERROR, _("Partition %s is mounted read only\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("Partition %s is mounted read only\n"),
data->mount_dir);
abort = 1;
} else if(data->used & USED_INSTALL) {
@@ -329,12 +330,12 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
long twentymb = (20 * 1024 * 1024 / (long)data->fsp.f_bsize) + 1;
long cushion = fivepc < twentymb ? fivepc : twentymb;
- _alpm_log(PM_LOG_DEBUG, "partition %s, needed %ld, cushion %ld, free %ld\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "partition %s, needed %ld, cushion %ld, free %ld\n",
data->mount_dir, data->max_blocks_needed, cushion,
(unsigned long)data->fsp.f_bfree);
if(data->max_blocks_needed + cushion >= 0 &&
(unsigned long)(data->max_blocks_needed + cushion) > data->fsp.f_bfree) {
- _alpm_log(PM_LOG_ERROR, _("Partition %s too full: %ld blocks needed, %ld blocks free\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("Partition %s too full: %ld blocks needed, %ld blocks free\n"),
data->mount_dir, data->max_blocks_needed + cushion,
(unsigned long)data->fsp.f_bfree);
abort = 1;
@@ -349,7 +350,7 @@ int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local)
FREELIST(mount_points);
if(abort) {
- RET_ERR(PM_ERR_DISK_SPACE, -1);
+ RET_ERR(handle, PM_ERR_DISK_SPACE, -1);
}
return 0;
diff --git a/lib/libalpm/diskspace.h b/lib/libalpm/diskspace.h
index 2894a0c2..28aca7e9 100644
--- a/lib/libalpm/diskspace.h
+++ b/lib/libalpm/diskspace.h
@@ -46,7 +46,7 @@ typedef struct __alpm_mountpoint_t {
FSSTATSTYPE fsp;
} alpm_mountpoint_t;
-int _alpm_check_diskspace(pmtrans_t *trans, pmdb_t *db_local);
+int _alpm_check_diskspace(pmhandle_t *handle);
#endif /* _ALPM_DISKSPACE_H */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index d024c736..46925a99 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -62,7 +62,7 @@ static char *get_fullpath(const char *path, const char *filename,
char *filepath;
/* len = localpath len + filename len + suffix len + null */
size_t len = strlen(path) + strlen(filename) + strlen(suffix) + 1;
- CALLOC(filepath, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(filepath, len, sizeof(char), return NULL);
snprintf(filepath, len, "%s%s%s", path, filename, suffix);
return filepath;
@@ -89,7 +89,7 @@ static int curl_progress(void *file, double dltotal, double dlnow,
}
/* none of what follows matters if the front end has no callback */
- if(handle->dlcb == NULL) {
+ if(dlfile->handle->dlcb == NULL) {
return 0;
}
@@ -103,10 +103,10 @@ static int curl_progress(void *file, double dltotal, double dlnow,
/* initialize the progress bar here to avoid displaying it when
* a repo is up to date and nothing gets downloaded */
if(DOUBLE_EQ(prevprogress, 0)) {
- handle->dlcb(dlfile->filename, 0, (long)dltotal);
+ dlfile->handle->dlcb(dlfile->filename, 0, (long)dltotal);
}
- handle->dlcb(dlfile->filename, (long)current_size, (long)total_size);
+ dlfile->handle->dlcb(dlfile->filename, (long)current_size, (long)total_size);
prevprogress = current_size;
@@ -129,7 +129,6 @@ static int curl_gethost(const char *url, char *buffer)
hostlen = strcspn(p, "/");
if(hostlen > 255) {
/* buffer overflow imminent */
- _alpm_log(PM_LOG_ERROR, _("buffer overflow detected"));
return 1;
}
snprintf(buffer, hostlen + 1, "%s", p);
@@ -150,7 +149,8 @@ static int utimes_long(const char *path, long time)
}
-static int curl_download_internal(const char *url, const char *localpath,
+static int curl_download_internal(pmhandle_t *handle,
+ const char *url, const char *localpath,
int force, int allow_resume, int errors_ok)
{
int ret = -1;
@@ -167,11 +167,12 @@ static int curl_download_internal(const char *url, const char *localpath,
struct sigaction sig_pipe[2], sig_int[2];
struct fileinfo dlfile;
+ dlfile.handle = handle;
dlfile.initial_size = 0.0;
dlfile.filename = get_filename(url);
if(!dlfile.filename || curl_gethost(url, hostname) != 0) {
- _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
- RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
+ _alpm_log(handle, PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
+ RET_ERR(handle, PM_ERR_SERVER_BAD_URL, -1);
}
destfile = get_fullpath(localpath, dlfile.filename, "");
@@ -194,23 +195,23 @@ static int curl_download_internal(const char *url, const char *localpath,
curl_easy_setopt(handle->curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(handle->curl, CURLOPT_PROGRESSFUNCTION, curl_progress);
curl_easy_setopt(handle->curl, CURLOPT_PROGRESSDATA, (void *)&dlfile);
+ curl_easy_setopt(handle->curl, CURLOPT_LOW_SPEED_LIMIT, 1024L);
+ curl_easy_setopt(handle->curl, CURLOPT_LOW_SPEED_TIME, 10L);
useragent = getenv("HTTP_USER_AGENT");
if(useragent != NULL) {
curl_easy_setopt(handle->curl, CURLOPT_USERAGENT, useragent);
}
- /* TODO: no assuming here. the calling function should tell us what's kosher */
- if(!force && stat(destfile, &st) == 0) {
- /* assume its a sync, so we're starting from scratch. but, only download
- * our local is out of date. */
+ if(!allow_resume && !force && stat(destfile, &st) == 0) {
+ /* start from scratch, but only download if our local is out of date. */
curl_easy_setopt(handle->curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
curl_easy_setopt(handle->curl, CURLOPT_TIMEVALUE, (long)st.st_mtime);
} else if(stat(tempfile, &st) == 0 && allow_resume) {
/* a previous partial download exists, resume from end of file. */
open_mode = "ab";
curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, (long)st.st_size);
- _alpm_log(PM_LOG_DEBUG, "tempfile found, attempting continuation");
+ _alpm_log(handle, PM_LOG_DEBUG, "tempfile found, attempting continuation");
dlfile.initial_size = (double)st.st_size;
}
@@ -247,11 +248,11 @@ static int curl_download_internal(const char *url, const char *localpath,
goto cleanup;
} else if(handle->curlerr != CURLE_OK) {
if(!errors_ok) {
- pm_errno = PM_ERR_LIBCURL;
- _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
+ handle->pm_errno = PM_ERR_LIBCURL;
+ _alpm_log(handle, PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"),
dlfile.filename, hostname, error_buffer);
} else {
- _alpm_log(PM_LOG_DEBUG, "failed retrieving file '%s' from %s : %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "failed retrieving file '%s' from %s : %s\n",
dlfile.filename, hostname, error_buffer);
}
unlink(tempfile);
@@ -277,8 +278,8 @@ static int curl_download_internal(const char *url, const char *localpath,
* as actually being transferred during curl_easy_perform() */
if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) &&
!DOUBLE_EQ(bytes_dl, remote_size)) {
- pm_errno = PM_ERR_RETRIEVE;
- _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
+ handle->pm_errno = PM_ERR_RETRIEVE;
+ _alpm_log(handle, PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
dlfile.filename, (intmax_t)bytes_dl, (intmax_t)remote_size);
goto cleanup;
}
@@ -310,45 +311,44 @@ cleanup:
}
#endif
-int _alpm_download(const char *url, const char *localpath,
+int _alpm_download(pmhandle_t *handle, const char *url, const char *localpath,
int force, int allow_resume, int errors_ok)
{
if(handle->fetchcb == NULL) {
#ifdef HAVE_LIBCURL
- return curl_download_internal(url, localpath, force, allow_resume, errors_ok);
+ return curl_download_internal(handle, url, localpath,
+ force, allow_resume, errors_ok);
#else
- RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+ RET_ERR(handle, PM_ERR_EXTERNAL_DOWNLOAD, -1);
#endif
} else {
int ret = handle->fetchcb(url, localpath, force);
if(ret == -1 && !errors_ok) {
- RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+ RET_ERR(handle, PM_ERR_EXTERNAL_DOWNLOAD, -1);
}
return ret;
}
}
/** Fetch a remote pkg. */
-char SYMEXPORT *alpm_fetch_pkgurl(const char *url)
+char SYMEXPORT *alpm_fetch_pkgurl(pmhandle_t *handle, const char *url)
{
char *filepath;
const char *filename, *cachedir;
int ret;
- ALPM_LOG_FUNC;
-
filename = get_filename(url);
/* find a valid cache dir to download to */
- cachedir = _alpm_filecache_setup();
+ cachedir = _alpm_filecache_setup(handle);
/* download the file */
- ret = _alpm_download(url, cachedir, 0, 1, 0);
+ ret = _alpm_download(handle, url, cachedir, 0, 1, 0);
if(ret == -1) {
- _alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), url);
+ _alpm_log(handle, PM_LOG_WARNING, _("failed to download %s\n"), url);
return NULL;
}
- _alpm_log(PM_LOG_DEBUG, "successfully downloaded %s\n", url);
+ _alpm_log(handle, PM_LOG_DEBUG, "successfully downloaded %s\n", url);
/* attempt to download the signature */
if(ret == 0 && (handle->sigverify == PM_PGP_VERIFY_ALWAYS ||
@@ -358,22 +358,22 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *url)
int errors_ok = (handle->sigverify == PM_PGP_VERIFY_OPTIONAL);
len = strlen(url) + 5;
- CALLOC(sig_url, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(sig_url, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, NULL));
snprintf(sig_url, len, "%s.sig", url);
- ret = _alpm_download(sig_url, cachedir, 1, 0, errors_ok);
+ ret = _alpm_download(handle, sig_url, cachedir, 1, 0, errors_ok);
if(ret == -1 && !errors_ok) {
- _alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), sig_url);
+ _alpm_log(handle, PM_LOG_WARNING, _("failed to download %s\n"), sig_url);
/* Warn now, but don't return NULL. We will fail later during package
* load time. */
} else if(ret == 0) {
- _alpm_log(PM_LOG_DEBUG, "successfully downloaded %s\n", sig_url);
+ _alpm_log(handle, PM_LOG_DEBUG, "successfully downloaded %s\n", sig_url);
}
FREE(sig_url);
}
/* we should be able to find the file the second time around */
- filepath = _alpm_filecache_find(filename);
+ filepath = _alpm_filecache_find(handle, filename);
return filepath;
}
diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h
index f4fd14cd..e409c32b 100644
--- a/lib/libalpm/dload.h
+++ b/lib/libalpm/dload.h
@@ -27,11 +27,12 @@
/* internal structure for communicating with curl progress callback */
struct fileinfo {
+ pmhandle_t *handle;
const char *filename;
double initial_size;
};
-int _alpm_download(const char *url, const char *localpath,
+int _alpm_download(pmhandle_t *handle, const char *url, const char *localpath,
int force, int allow_resume, int errors_ok);
#endif /* _ALPM_DLOAD_H */
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 4d4a065c..d893f866 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -29,12 +29,12 @@
#include "alpm.h"
#include "handle.h"
-const char SYMEXPORT *alpm_strerrorlast(void)
+enum _pmerrno_t SYMEXPORT alpm_errno(pmhandle_t *handle)
{
- return alpm_strerror(pm_errno);
+ return handle->pm_errno;
}
-const char SYMEXPORT *alpm_strerror(int err)
+const char SYMEXPORT *alpm_strerror(enum _pmerrno_t err)
{
switch(err) {
/* System */
@@ -137,8 +137,6 @@ const char SYMEXPORT *alpm_strerror(int err)
/* Miscellaenous */
case PM_ERR_RETRIEVE:
return _("failed to retrieve some files");
- case PM_ERR_WRITE:
- return _("failed to copy some file");
case PM_ERR_INVALID_REGEX:
return _("invalid regular expression");
/* Errors from external libraries- our own wrapper error */
@@ -148,12 +146,7 @@ const char SYMEXPORT *alpm_strerror(int err)
* error string instead. */
return _("libarchive error");
case PM_ERR_LIBCURL:
-#ifdef HAVE_LIBCURL
- return curl_easy_strerror(handle->curlerr);
-#else
- /* obviously shouldn't get here... */
return _("download library error");
-#endif
case PM_ERR_GPGME:
return _("gpgme error");
case PM_ERR_EXTERNAL_DOWNLOAD:
diff --git a/lib/libalpm/graph.c b/lib/libalpm/graph.c
index 2e2ba236..fc2c9e16 100644
--- a/lib/libalpm/graph.c
+++ b/lib/libalpm/graph.c
@@ -27,25 +27,14 @@ pmgraph_t *_alpm_graph_new(void)
{
pmgraph_t *graph = NULL;
- CALLOC(graph, 1, sizeof(pmgraph_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(graph, 1, sizeof(pmgraph_t), return NULL);
return graph;
}
void _alpm_graph_free(void *data)
{
pmgraph_t *graph = data;
- /* make my children forget about me */
- for(alpm_list_t *i = graph->children; i; i = i->next) {
- pmgraph_t *child = i->data;
- child->parent = NULL;
- }
alpm_list_free(graph->children);
- /* and make my parents forget about me too */
- if(graph->parent) {
- alpm_list_t *me = alpm_list_find_ptr(graph->parent->children, &data);
- graph->parent->children = alpm_list_remove_item(graph->parent->children,
- me);
- }
free(graph);
}
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index dbcc7554..13a216ee 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -34,18 +34,14 @@ pmgrp_t *_alpm_grp_new(const char *name)
{
pmgrp_t* grp;
- ALPM_LOG_FUNC;
-
- CALLOC(grp, 1, sizeof(pmgrp_t), RET_ERR(PM_ERR_MEMORY, NULL));
- STRDUP(grp->name, name, RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(grp, 1, sizeof(pmgrp_t), return NULL);
+ STRDUP(grp->name, name, free(grp); return NULL);
return grp;
}
void _alpm_grp_free(pmgrp_t *grp)
{
- ALPM_LOG_FUNC;
-
if(grp == NULL) {
return;
}
@@ -58,21 +54,14 @@ void _alpm_grp_free(pmgrp_t *grp)
const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(grp != NULL, return NULL);
-
return grp->name;
}
alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
ASSERT(grp != NULL, return NULL);
-
return grp->packages;
}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 2d6766a5..3c17e9d4 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -37,16 +37,11 @@
#include "trans.h"
#include "alpm.h"
-/* global var for handle (private to libalpm) */
-pmhandle_t *handle = NULL;
-
pmhandle_t *_alpm_handle_new()
{
pmhandle_t *handle;
- ALPM_LOG_FUNC;
-
- CALLOC(handle, 1, sizeof(pmhandle_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(handle, 1, sizeof(pmhandle_t), return NULL);
handle->sigverify = PM_PGP_VERIFY_OPTIONAL;
@@ -55,8 +50,6 @@ pmhandle_t *_alpm_handle_new()
void _alpm_handle_free(pmhandle_t *handle)
{
- ALPM_LOG_FUNC;
-
if(handle == NULL) {
return;
}
@@ -91,341 +84,242 @@ void _alpm_handle_free(pmhandle_t *handle)
FREELIST(handle->ignorepkg);
FREELIST(handle->ignoregrp);
FREE(handle);
-
}
-alpm_cb_log SYMEXPORT alpm_option_get_logcb()
+alpm_cb_log SYMEXPORT alpm_option_get_logcb(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->logcb;
}
-alpm_cb_download SYMEXPORT alpm_option_get_dlcb()
+alpm_cb_download SYMEXPORT alpm_option_get_dlcb(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->dlcb;
}
-alpm_cb_fetch SYMEXPORT alpm_option_get_fetchcb()
+alpm_cb_fetch SYMEXPORT alpm_option_get_fetchcb(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->fetchcb;
}
-alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb()
+alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->totaldlcb;
}
-const char SYMEXPORT *alpm_option_get_root()
+const char SYMEXPORT *alpm_option_get_root(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->root;
}
-const char SYMEXPORT *alpm_option_get_dbpath()
+const char SYMEXPORT *alpm_option_get_dbpath(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->dbpath;
}
-alpm_list_t SYMEXPORT *alpm_option_get_cachedirs()
+alpm_list_t SYMEXPORT *alpm_option_get_cachedirs(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->cachedirs;
}
-const char SYMEXPORT *alpm_option_get_logfile()
+const char SYMEXPORT *alpm_option_get_logfile(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->logfile;
}
-const char SYMEXPORT *alpm_option_get_lockfile()
+const char SYMEXPORT *alpm_option_get_lockfile(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->lockfile;
}
-const char SYMEXPORT *alpm_option_get_signaturedir()
+const char SYMEXPORT *alpm_option_get_signaturedir(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->signaturedir;
}
-int SYMEXPORT alpm_option_get_usesyslog()
+int SYMEXPORT alpm_option_get_usesyslog(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return -1;
- }
+ ASSERT(handle != NULL, return -1);
return handle->usesyslog;
}
-alpm_list_t SYMEXPORT *alpm_option_get_noupgrades()
+alpm_list_t SYMEXPORT *alpm_option_get_noupgrades(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->noupgrade;
}
-alpm_list_t SYMEXPORT *alpm_option_get_noextracts()
+alpm_list_t SYMEXPORT *alpm_option_get_noextracts(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->noextract;
}
-alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs()
+alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->ignorepkg;
}
-alpm_list_t SYMEXPORT *alpm_option_get_ignoregrps()
+alpm_list_t SYMEXPORT *alpm_option_get_ignoregrps(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->ignoregrp;
}
-const char SYMEXPORT *alpm_option_get_arch()
+const char SYMEXPORT *alpm_option_get_arch(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->arch;
}
-int SYMEXPORT alpm_option_get_usedelta()
+int SYMEXPORT alpm_option_get_usedelta(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return -1;
- }
+ ASSERT(handle != NULL, return -1);
return handle->usedelta;
}
-int SYMEXPORT alpm_option_get_checkspace()
+int SYMEXPORT alpm_option_get_checkspace(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return -1;
- }
+ ASSERT(handle != NULL, return -1);
return handle->checkspace;
}
-pmdb_t SYMEXPORT *alpm_option_get_localdb()
+pmdb_t SYMEXPORT *alpm_option_get_localdb(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->db_local;
}
-alpm_list_t SYMEXPORT *alpm_option_get_syncdbs()
+alpm_list_t SYMEXPORT *alpm_option_get_syncdbs(pmhandle_t *handle)
{
- if(handle == NULL) {
- pm_errno = PM_ERR_HANDLE_NULL;
- return NULL;
- }
+ ASSERT(handle != NULL, return NULL);
return handle->dbs_sync;
}
-int SYMEXPORT alpm_option_set_logcb(alpm_cb_log cb)
+int SYMEXPORT alpm_option_set_logcb(pmhandle_t *handle, alpm_cb_log cb)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->logcb = cb;
return 0;
}
-int SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb)
+int SYMEXPORT alpm_option_set_dlcb(pmhandle_t *handle, alpm_cb_download cb)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->dlcb = cb;
return 0;
}
-int SYMEXPORT alpm_option_set_fetchcb(alpm_cb_fetch cb)
+int SYMEXPORT alpm_option_set_fetchcb(pmhandle_t *handle, alpm_cb_fetch cb)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->fetchcb = cb;
return 0;
}
-int SYMEXPORT alpm_option_set_totaldlcb(alpm_cb_totaldl cb)
+int SYMEXPORT alpm_option_set_totaldlcb(pmhandle_t *handle, alpm_cb_totaldl cb)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->totaldlcb = cb;
return 0;
}
-int SYMEXPORT alpm_option_set_root(const char *root)
-{
- struct stat st;
- char *realroot;
- size_t rootlen;
-
- ALPM_LOG_FUNC;
-
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
-
- if(!root) {
- pm_errno = PM_ERR_WRONG_ARGS;
- return -1;
- }
- if(stat(root, &st) == -1 || !S_ISDIR(st.st_mode)) {
- pm_errno = PM_ERR_NOT_A_DIR;
- return -1;
- }
-
- realroot = calloc(PATH_MAX+1, sizeof(char));
- if(!realpath(root, realroot)) {
- FREE(realroot);
- pm_errno = PM_ERR_NOT_A_DIR;
- return -1;
- }
+static char *canonicalize_path(const char *path) {
+ char *new_path;
+ size_t len;
- /* verify root ends in a '/' */
- rootlen = strlen(realroot);
- if(realroot[rootlen-1] != '/') {
- rootlen += 1;
- }
- if(handle->root) {
- FREE(handle->root);
+ /* verify path ends in a '/' */
+ len = strlen(path);
+ if(path[len - 1] != '/') {
+ len += 1;
}
- handle->root = calloc(rootlen + 1, sizeof(char));
- strncpy(handle->root, realroot, rootlen);
- handle->root[rootlen-1] = '/';
- FREE(realroot);
- _alpm_log(PM_LOG_DEBUG, "option 'root' = %s\n", handle->root);
- return 0;
+ new_path = calloc(len + 1, sizeof(char));
+ strncpy(new_path, path, len);
+ new_path[len - 1] = '/';
+ return new_path;
}
-int SYMEXPORT alpm_option_set_dbpath(const char *dbpath)
-{
+enum _pmerrno_t _alpm_set_directory_option(const char *value,
+ char **storage, int must_exist)
+ {
struct stat st;
- size_t dbpathlen, lockfilelen;
- const char *lf = "db.lck";
-
- ALPM_LOG_FUNC;
-
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- if(!dbpath) {
- pm_errno = PM_ERR_WRONG_ARGS;
- return -1;
- }
- if(stat(dbpath, &st) == -1 || !S_ISDIR(st.st_mode)) {
- pm_errno = PM_ERR_NOT_A_DIR;
- return -1;
- }
- /* verify dbpath ends in a '/' */
- dbpathlen = strlen(dbpath);
- if(dbpath[dbpathlen-1] != '/') {
- dbpathlen += 1;
- }
- if(handle->dbpath) {
- FREE(handle->dbpath);
- }
- handle->dbpath = calloc(dbpathlen+1, sizeof(char));
- strncpy(handle->dbpath, dbpath, dbpathlen);
- handle->dbpath[dbpathlen-1] = '/';
- _alpm_log(PM_LOG_DEBUG, "option 'dbpath' = %s\n", handle->dbpath);
-
- if(handle->lockfile) {
- FREE(handle->lockfile);
- }
- lockfilelen = strlen(handle->dbpath) + strlen(lf) + 1;
- handle->lockfile = calloc(lockfilelen, sizeof(char));
- snprintf(handle->lockfile, lockfilelen, "%s%s", handle->dbpath, lf);
- _alpm_log(PM_LOG_DEBUG, "option 'lockfile' = %s\n", handle->lockfile);
+ char *real = NULL;
+ const char *path;
+
+ path = value;
+ if(!path) {
+ return PM_ERR_WRONG_ARGS;
+ }
+ if(must_exist) {
+ if(stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
+ return PM_ERR_NOT_A_DIR;
+ }
+ real = calloc(PATH_MAX, sizeof(char));
+ if(!realpath(path, real)) {
+ free(real);
+ return PM_ERR_NOT_A_DIR;
+ }
+ path = real;
+ }
+
+ if(*storage) {
+ FREE(*storage);
+ }
+ *storage = canonicalize_path(path);
+ free(real);
return 0;
}
-int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
+int SYMEXPORT alpm_option_add_cachedir(pmhandle_t *handle, const char *cachedir)
{
char *newcachedir;
- size_t cachedirlen;
-
- ALPM_LOG_FUNC;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(!cachedir) {
- pm_errno = PM_ERR_WRONG_ARGS;
+ handle->pm_errno = PM_ERR_WRONG_ARGS;
return -1;
}
/* don't stat the cachedir yet, as it may not even be needed. we can
* fail later if it is needed and the path is invalid. */
- /* verify cachedir ends in a '/' */
- cachedirlen = strlen(cachedir);
- if(cachedir[cachedirlen-1] != '/') {
- cachedirlen += 1;
- }
- newcachedir = calloc(cachedirlen + 1, sizeof(char));
- strncpy(newcachedir, cachedir, cachedirlen);
- newcachedir[cachedirlen-1] = '/';
+ newcachedir = canonicalize_path(cachedir);
handle->cachedirs = alpm_list_add(handle->cachedirs, newcachedir);
- _alpm_log(PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir);
+ _alpm_log(handle, PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir);
return 0;
}
-int SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs)
+int SYMEXPORT alpm_option_set_cachedirs(pmhandle_t *handle, alpm_list_t *cachedirs)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- if(handle->cachedirs) FREELIST(handle->cachedirs);
- handle->cachedirs = cachedirs;
+ alpm_list_t *i;
+ ASSERT(handle != NULL, return -1);
+ if(handle->cachedirs) {
+ FREELIST(handle->cachedirs);
+ }
+ for(i = cachedirs; i; i = i->next) {
+ int ret = alpm_option_add_cachedir(handle, i->data);
+ if(ret) {
+ return ret;
+ }
+ }
return 0;
}
-int SYMEXPORT alpm_option_remove_cachedir(const char *cachedir)
+int SYMEXPORT alpm_option_remove_cachedir(pmhandle_t *handle, const char *cachedir)
{
char *vdata = NULL;
char *newcachedir;
size_t cachedirlen;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
/* verify cachedir ends in a '/' */
cachedirlen = strlen(cachedir);
if(cachedir[cachedirlen-1] != '/') {
@@ -443,15 +337,13 @@ int SYMEXPORT alpm_option_remove_cachedir(const char *cachedir)
return 0;
}
-int SYMEXPORT alpm_option_set_logfile(const char *logfile)
+int SYMEXPORT alpm_option_set_logfile(pmhandle_t *handle, const char *logfile)
{
char *oldlogfile = handle->logfile;
- ALPM_LOG_FUNC;
-
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(!logfile) {
- pm_errno = PM_ERR_WRONG_ARGS;
+ handle->pm_errno = PM_ERR_WRONG_ARGS;
return -1;
}
@@ -466,16 +358,15 @@ int SYMEXPORT alpm_option_set_logfile(const char *logfile)
fclose(handle->logstream);
handle->logstream = NULL;
}
- _alpm_log(PM_LOG_DEBUG, "option 'logfile' = %s\n", handle->logfile);
+ _alpm_log(handle, PM_LOG_DEBUG, "option 'logfile' = %s\n", handle->logfile);
return 0;
}
-int SYMEXPORT alpm_option_set_signaturedir(const char *signaturedir)
+int SYMEXPORT alpm_option_set_signaturedir(pmhandle_t *handle, const char *signaturedir)
{
- ALPM_LOG_FUNC;
-
+ ASSERT(handle != NULL, return -1);
if(!signaturedir) {
- pm_errno = PM_ERR_WRONG_ARGS;
+ handle->pm_errno = PM_ERR_WRONG_ARGS;
return -1;
}
@@ -484,36 +375,36 @@ int SYMEXPORT alpm_option_set_signaturedir(const char *signaturedir)
}
handle->signaturedir = strdup(signaturedir);
- _alpm_log(PM_LOG_DEBUG, "option 'signaturedir' = %s\n", handle->signaturedir);
+ _alpm_log(handle, PM_LOG_DEBUG, "option 'signaturedir' = %s\n", handle->signaturedir);
return 0;
}
-int SYMEXPORT alpm_option_set_usesyslog(int usesyslog)
+int SYMEXPORT alpm_option_set_usesyslog(pmhandle_t *handle, int usesyslog)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->usesyslog = usesyslog;
return 0;
}
-int SYMEXPORT alpm_option_add_noupgrade(const char *pkg)
+int SYMEXPORT alpm_option_add_noupgrade(pmhandle_t *handle, const char *pkg)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg));
return 0;
}
-int SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade)
+int SYMEXPORT alpm_option_set_noupgrades(pmhandle_t *handle, alpm_list_t *noupgrade)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(handle->noupgrade) FREELIST(handle->noupgrade);
- handle->noupgrade = noupgrade;
+ handle->noupgrade = alpm_list_strdup(noupgrade);
return 0;
}
-int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
+int SYMEXPORT alpm_option_remove_noupgrade(pmhandle_t *handle, const char *pkg)
{
char *vdata = NULL;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->noupgrade = alpm_list_remove_str(handle->noupgrade, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
@@ -522,25 +413,25 @@ int SYMEXPORT alpm_option_remove_noupgrade(const char *pkg)
return 0;
}
-int SYMEXPORT alpm_option_add_noextract(const char *pkg)
+int SYMEXPORT alpm_option_add_noextract(pmhandle_t *handle, const char *pkg)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->noextract = alpm_list_add(handle->noextract, strdup(pkg));
return 0;
}
-int SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract)
+int SYMEXPORT alpm_option_set_noextracts(pmhandle_t *handle, alpm_list_t *noextract)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(handle->noextract) FREELIST(handle->noextract);
- handle->noextract = noextract;
+ handle->noextract = alpm_list_strdup(noextract);
return 0;
}
-int SYMEXPORT alpm_option_remove_noextract(const char *pkg)
+int SYMEXPORT alpm_option_remove_noextract(pmhandle_t *handle, const char *pkg)
{
char *vdata = NULL;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->noextract = alpm_list_remove_str(handle->noextract, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
@@ -549,25 +440,25 @@ int SYMEXPORT alpm_option_remove_noextract(const char *pkg)
return 0;
}
-int SYMEXPORT alpm_option_add_ignorepkg(const char *pkg)
+int SYMEXPORT alpm_option_add_ignorepkg(pmhandle_t *handle, const char *pkg)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->ignorepkg = alpm_list_add(handle->ignorepkg, strdup(pkg));
return 0;
}
-int SYMEXPORT alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
+int SYMEXPORT alpm_option_set_ignorepkgs(pmhandle_t *handle, alpm_list_t *ignorepkgs)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(handle->ignorepkg) FREELIST(handle->ignorepkg);
- handle->ignorepkg = ignorepkgs;
+ handle->ignorepkg = alpm_list_strdup(ignorepkgs);
return 0;
}
-int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
+int SYMEXPORT alpm_option_remove_ignorepkg(pmhandle_t *handle, const char *pkg)
{
char *vdata = NULL;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->ignorepkg = alpm_list_remove_str(handle->ignorepkg, pkg, &vdata);
if(vdata != NULL) {
FREE(vdata);
@@ -576,25 +467,25 @@ int SYMEXPORT alpm_option_remove_ignorepkg(const char *pkg)
return 0;
}
-int SYMEXPORT alpm_option_add_ignoregrp(const char *grp)
+int SYMEXPORT alpm_option_add_ignoregrp(pmhandle_t *handle, const char *grp)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->ignoregrp = alpm_list_add(handle->ignoregrp, strdup(grp));
return 0;
}
-int SYMEXPORT alpm_option_set_ignoregrps(alpm_list_t *ignoregrps)
+int SYMEXPORT alpm_option_set_ignoregrps(pmhandle_t *handle, alpm_list_t *ignoregrps)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(handle->ignoregrp) FREELIST(handle->ignoregrp);
- handle->ignoregrp = ignoregrps;
+ handle->ignoregrp = alpm_list_strdup(ignoregrps);
return 0;
}
-int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
+int SYMEXPORT alpm_option_remove_ignoregrp(pmhandle_t *handle, const char *grp)
{
char *vdata = NULL;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->ignoregrp = alpm_list_remove_str(handle->ignoregrp, grp, &vdata);
if(vdata != NULL) {
FREE(vdata);
@@ -603,9 +494,9 @@ int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
return 0;
}
-int SYMEXPORT alpm_option_set_arch(const char *arch)
+int SYMEXPORT alpm_option_set_arch(pmhandle_t *handle, const char *arch)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
if(handle->arch) FREE(handle->arch);
if(arch) {
handle->arch = strdup(arch);
@@ -615,31 +506,31 @@ int SYMEXPORT alpm_option_set_arch(const char *arch)
return 0;
}
-int SYMEXPORT alpm_option_set_usedelta(int usedelta)
+int SYMEXPORT alpm_option_set_usedelta(pmhandle_t *handle, int usedelta)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->usedelta = usedelta;
return 0;
}
-int SYMEXPORT alpm_option_set_checkspace(int checkspace)
+int SYMEXPORT alpm_option_set_checkspace(pmhandle_t *handle, int checkspace)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
handle->checkspace = checkspace;
return 0;
}
-int SYMEXPORT alpm_option_set_default_sigverify(pgp_verify_t level)
+int SYMEXPORT alpm_option_set_default_sigverify(pmhandle_t *handle, pgp_verify_t level)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(level != PM_PGP_VERIFY_UNKNOWN, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(level != PM_PGP_VERIFY_UNKNOWN, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
handle->sigverify = level;
return 0;
}
-pgp_verify_t SYMEXPORT alpm_option_get_default_sigverify()
+pgp_verify_t SYMEXPORT alpm_option_get_default_sigverify(pmhandle_t *handle)
{
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, PM_PGP_VERIFY_UNKNOWN));
+ ASSERT(handle != NULL, return PM_PGP_VERIFY_UNKNOWN);
return handle->sigverify;
}
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index aa00b6f0..bace8052 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -24,16 +24,13 @@
#include <sys/types.h>
#include "alpm_list.h"
-#include "db.h"
-#include "log.h"
#include "alpm.h"
-#include "trans.h"
#ifdef HAVE_LIBCURL
#include <curl/curl.h>
#endif
-typedef struct _pmhandle_t {
+struct __pmhandle_t {
/* internal usage */
pmdb_t *db_local; /* local db pointer */
alpm_list_t *dbs_sync; /* List of (pmdb_t *) */
@@ -73,14 +70,17 @@ typedef struct _pmhandle_t {
int usedelta; /* Download deltas if possible */
int checkspace; /* Check disk space before installing */
pgp_verify_t sigverify; /* Default signature verification level */
-} pmhandle_t;
-/* global handle variable */
-extern pmhandle_t *handle;
+ /* error code */
+ enum _pmerrno_t pm_errno;
+};
pmhandle_t *_alpm_handle_new(void);
void _alpm_handle_free(pmhandle_t *handle);
+enum _pmerrno_t _alpm_set_directory_option(const char *value,
+ char **storage, int must_exist);
+
#endif /* _ALPM_HANDLE_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index 9093af7b..91bcb823 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -36,18 +36,16 @@
*/
/** A printf-like function for logging.
+ * @param handle the context handle
* @param fmt output format
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int SYMEXPORT alpm_logaction(const char *fmt, ...)
+int SYMEXPORT alpm_logaction(pmhandle_t *handle, const char *fmt, ...)
{
int ret;
va_list args;
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
/* check if the logstream is open already, opening it if needed */
if(handle->logstream == NULL) {
@@ -55,18 +53,18 @@ int SYMEXPORT alpm_logaction(const char *fmt, ...)
/* if we couldn't open it, we have an issue */
if(handle->logstream == NULL) {
if(errno == EACCES) {
- pm_errno = PM_ERR_BADPERMS;
+ handle->pm_errno = PM_ERR_BADPERMS;
} else if(errno == ENOENT) {
- pm_errno = PM_ERR_NOT_A_DIR;
+ handle->pm_errno = PM_ERR_NOT_A_DIR;
} else {
- pm_errno = PM_ERR_SYSTEM;
+ handle->pm_errno = PM_ERR_SYSTEM;
}
- return -1;
+ return -1;
}
}
va_start(args, fmt);
- ret = _alpm_logaction(handle->usesyslog, handle->logstream, fmt, args);
+ ret = _alpm_logaction(handle, fmt, args);
va_end(args);
/* TODO We should add a prefix to log strings depending on who called us.
@@ -85,10 +83,10 @@ int SYMEXPORT alpm_logaction(const char *fmt, ...)
/** @} */
-void _alpm_log(pmloglevel_t flag, const char *fmt, ...)
+void _alpm_log(pmhandle_t *handle, pmloglevel_t flag, const char *fmt, ...)
{
va_list args;
- alpm_cb_log logcb = alpm_option_get_logcb();
+ alpm_cb_log logcb = alpm_option_get_logcb(handle);
if(logcb == NULL) {
return;
diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h
index 9a2961fb..105430c4 100644
--- a/lib/libalpm/log.h
+++ b/lib/libalpm/log.h
@@ -22,14 +22,8 @@
#include "alpm.h"
-#ifdef PACMAN_DEBUG
-/* Log funtion entry points if debugging is enabled */
-#define ALPM_LOG_FUNC _alpm_log(PM_LOG_FUNCTION, "Enter %s\n", __func__)
-#else
-#define ALPM_LOG_FUNC
-#endif
-
-void _alpm_log(pmloglevel_t flag, const char *fmt, ...) __attribute__((format(printf,2,3)));
+void _alpm_log(pmhandle_t *handle, pmloglevel_t flag,
+ const char *fmt, ...) __attribute__((format(printf,3,4)));
#endif /* _ALPM_LOG_H */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 990f532d..969458ac 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -45,9 +45,7 @@
/** Free a package. */
int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(pkg != NULL, return -1);
/* Only free packages loaded in user space */
if(pkg->origin == PKG_FROM_FILE) {
@@ -63,20 +61,18 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
char *fpath;
int retval;
- ALPM_LOG_FUNC;
-
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(pkg != NULL, return -1);
/* We only inspect packages from sync repositories */
- ASSERT(pkg->origin == PKG_FROM_SYNCDB, RET_ERR(PM_ERR_PKG_INVALID, -1));
+ ASSERT(pkg->origin == PKG_FROM_SYNCDB, return -1);
- fpath = _alpm_filecache_find(alpm_pkg_get_filename(pkg));
+ fpath = _alpm_filecache_find(pkg->handle, alpm_pkg_get_filename(pkg));
retval = _alpm_test_md5sum(fpath, alpm_pkg_get_md5sum(pkg));
if(retval == 0) {
return 0;
} else if(retval == 1) {
- pm_errno = PM_ERR_PKG_INVALID;
+ pkg->handle->pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
@@ -345,7 +341,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
if(pkg->origin == PKG_FROM_FILE) {
/* The sane option; search locally for things that require this. */
- db = alpm_option_get_localdb();
+ db = alpm_option_get_localdb(pkg->handle);
find_requiredby(pkg, db, &reqs);
} else {
/* We have a DB package. if it is a local package, then we should
@@ -354,7 +350,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
if(db->is_local) {
find_requiredby(pkg, db, &reqs);
} else {
- for(i = handle->dbs_sync; i; i = i->next) {
+ for(i = pkg->handle->dbs_sync; i; i = i->next) {
db = i->data;
find_requiredby(pkg, db, &reqs);
}
@@ -370,9 +366,7 @@ pmpkg_t *_alpm_pkg_new(void)
{
pmpkg_t* pkg;
- ALPM_LOG_FUNC;
-
- CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(pkg, 1, sizeof(pmpkg_t), return NULL);
return pkg;
}
@@ -382,21 +376,19 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
pmpkg_t *newpkg;
alpm_list_t *i;
- ALPM_LOG_FUNC;
-
- CALLOC(newpkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ CALLOC(newpkg, 1, sizeof(pmpkg_t), goto cleanup);
newpkg->name_hash = pkg->name_hash;
- STRDUP(newpkg->filename, pkg->filename, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->name, pkg->name, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->version, pkg->version, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->desc, pkg->desc, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->url, pkg->url, RET_ERR(PM_ERR_MEMORY, newpkg));
+ STRDUP(newpkg->filename, pkg->filename, goto cleanup);
+ STRDUP(newpkg->name, pkg->name, goto cleanup);
+ STRDUP(newpkg->version, pkg->version, goto cleanup);
+ STRDUP(newpkg->desc, pkg->desc, goto cleanup);
+ STRDUP(newpkg->url, pkg->url, goto cleanup);
newpkg->builddate = pkg->builddate;
newpkg->installdate = pkg->installdate;
- STRDUP(newpkg->packager, pkg->packager, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->md5sum, pkg->md5sum, RET_ERR(PM_ERR_MEMORY, newpkg));
- STRDUP(newpkg->arch, pkg->arch, RET_ERR(PM_ERR_MEMORY, newpkg));
+ STRDUP(newpkg->packager, pkg->packager, goto cleanup);
+ STRDUP(newpkg->md5sum, pkg->md5sum, goto cleanup);
+ STRDUP(newpkg->arch, pkg->arch, goto cleanup);
newpkg->size = pkg->size;
newpkg->isize = pkg->isize;
newpkg->scriptlet = pkg->scriptlet;
@@ -416,22 +408,25 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
newpkg->deltas = alpm_list_copy_data(pkg->deltas, sizeof(pmdelta_t));
/* internal */
+ newpkg->infolevel = pkg->infolevel;
newpkg->origin = pkg->origin;
- newpkg->ops = pkg->ops;
if(newpkg->origin == PKG_FROM_FILE) {
newpkg->origin_data.file = strdup(pkg->origin_data.file);
} else {
newpkg->origin_data.db = pkg->origin_data.db;
}
- newpkg->infolevel = pkg->infolevel;
+ newpkg->ops = pkg->ops;
+ newpkg->handle = pkg->handle;
return newpkg;
+
+cleanup:
+ _alpm_pkg_free(newpkg);
+ return NULL;
}
void _alpm_pkg_free(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
if(pkg == NULL) {
return;
}
@@ -473,8 +468,6 @@ void _alpm_pkg_free(pmpkg_t *pkg)
*/
void _alpm_pkg_free_trans(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
if(pkg == NULL) {
return;
}
@@ -491,8 +484,6 @@ void _alpm_pkg_free_trans(pmpkg_t *pkg)
/* Is spkg an upgrade for localpkg? */
int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
{
- ALPM_LOG_FUNC;
-
return alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
alpm_pkg_get_version(localpkg));
}
@@ -514,8 +505,6 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
alpm_list_t *lp;
unsigned long needle_hash;
- ALPM_LOG_FUNC;
-
if(needle == NULL || haystack == NULL) {
return NULL;
}
@@ -554,12 +543,12 @@ int _alpm_pkg_should_ignore(pmpkg_t *pkg)
alpm_list_t *groups = NULL;
/* first see if the package is ignored */
- if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
+ if(alpm_list_find_str(pkg->handle->ignorepkg, alpm_pkg_get_name(pkg))) {
return 1;
}
/* next see if the package is in a group that is ignored */
- for(groups = handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
+ for(groups = pkg->handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
char *grp = (char *)alpm_list_getdata(groups);
if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
return 1;
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index debb239c..b5d8f738 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -110,6 +110,7 @@ struct __pmpkg_t {
int scriptlet;
pmpkgreason_t reason;
+ pmdbinfrq_t infolevel;
pmpkgfrom_t origin;
/* origin == PKG_FROM_FILE, use pkg->origin_data.file
* origin == PKG_FROM_*DB, use pkg->origin_data.db */
@@ -117,7 +118,7 @@ struct __pmpkg_t {
pmdb_t *db;
char *file;
} origin_data;
- pmdbinfrq_t infolevel;
+ pmhandle_t *handle;
alpm_list_t *licenses;
alpm_list_t *replaces;
@@ -140,8 +141,10 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
void _alpm_pkg_free(pmpkg_t *pkg);
void _alpm_pkg_free_trans(pmpkg_t *pkg);
-pmpkg_t *_alpm_pkg_load_internal(const char *filename, int full,
- const char *md5sum, const char *base64_sig, pgp_verify_t check_sig);
+
+pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile,
+ int full, const char *md5sum, const char *base64_sig,
+ pgp_verify_t check_sig);
int _alpm_pkg_cmp(const void *p1, const void *p2);
int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg);
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c
index f4153300..9e98fcd8 100644
--- a/lib/libalpm/pkghash.c
+++ b/lib/libalpm/pkghash.c
@@ -17,9 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <errno.h>
+
#include "pkghash.h"
#include "util.h"
-#include "log.h"
/* List of primes for possible sizes of hash tables.
*
@@ -55,11 +56,7 @@ pmpkghash_t *_alpm_pkghash_create(size_t size)
pmpkghash_t *hash = NULL;
size_t i, loopsize;
- MALLOC(hash, sizeof(pmpkghash_t), RET_ERR(PM_ERR_MEMORY, NULL));
-
- hash->list = NULL;
- hash->entries = 0;
- hash->buckets = 0;
+ CALLOC(hash, 1, sizeof(pmpkghash_t), return NULL);
loopsize = sizeof(prime_list) / sizeof(*prime_list);
for(i = 0; i < loopsize; i++) {
@@ -70,13 +67,13 @@ pmpkghash_t *_alpm_pkghash_create(size_t size)
}
if(hash->buckets < size) {
- _alpm_log(PM_LOG_ERROR, _("database larger than maximum size\n"));
+ errno = ERANGE;
free(hash);
return NULL;
}
CALLOC(hash->hash_table, hash->buckets, sizeof(alpm_list_t *), \
- free(hash); RET_ERR(PM_ERR_MEMORY, NULL));
+ free(hash); return NULL);
return hash;
}
@@ -304,8 +301,6 @@ pmpkg_t *_alpm_pkghash_find(pmpkghash_t *hash, const char *name)
unsigned long name_hash;
size_t position;
- ALPM_LOG_FUNC;
-
if(name == NULL || hash == NULL) {
return NULL;
}
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index cf416d52..264d79ea 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -44,64 +44,62 @@
#include "deps.h"
#include "handle.h"
-int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg)
+int SYMEXPORT alpm_remove_pkg(pmhandle_t *handle, pmpkg_t *pkg)
{
- pmtrans_t *trans;
const char *pkgname;
-
- ALPM_LOG_FUNC;
+ pmtrans_t *trans;
/* Sanity checks */
- ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle == pkg->handle, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state == STATE_INITIALIZED,
- RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+ RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1));
pkgname = pkg->name;
if(_alpm_pkg_find(trans->remove, pkgname)) {
- RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
+ RET_ERR(handle, PM_ERR_TRANS_DUP_TARGET, -1);
}
- _alpm_log(PM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package %s to the transaction remove list\n",
pkgname);
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
return 0;
}
-static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
- alpm_list_t *lp)
+static void remove_prepare_cascade(pmhandle_t *handle, alpm_list_t *lp)
{
- ALPM_LOG_FUNC;
+ pmtrans_t *trans = handle->trans;
while(lp) {
alpm_list_t *i;
for(i = lp; i; i = i->next) {
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
- pmpkg_t *info = _alpm_db_get_pkgfromcache(db, miss->target);
+ pmpkg_t *info = _alpm_db_get_pkgfromcache(handle->db_local, miss->target);
if(info) {
if(!_alpm_pkg_find(trans->remove, alpm_pkg_get_name(info))) {
- _alpm_log(PM_LOG_DEBUG, "pulling %s in target list\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "pulling %s in target list\n",
alpm_pkg_get_name(info));
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
}
} else {
- _alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
miss->target);
}
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
+ trans->remove, NULL, 1);
}
}
-static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
- alpm_list_t *lp)
+static void remove_prepare_keep_needed(pmhandle_t *handle, alpm_list_t *lp)
{
- ALPM_LOG_FUNC;
+ pmtrans_t *trans = handle->trans;
/* Remove needed packages (which break dependencies) from target list */
while(lp != NULL) {
@@ -117,14 +115,15 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
&vpkg);
pkg = vpkg;
if(pkg) {
- _alpm_log(PM_LOG_WARNING, _("removing %s from target list\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("removing %s from target list\n"),
alpm_pkg_get_name(pkg));
_alpm_pkg_free(pkg);
}
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
+ trans->remove, NULL, 1);
}
}
@@ -132,37 +131,34 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
* This functions takes a pointer to a alpm_list_t which will be
* filled with a list of pmdepmissing_t* objects representing
* the packages blocking the transaction.
- * @param trans the transaction object
- * @param db the database of local packages
+ * @param handle the context handle
* @param data a pointer to an alpm_list_t* to fill
*/
-int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
+int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data)
{
alpm_list_t *lp;
-
- ALPM_LOG_FUNC;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
+ pmdb_t *db = handle->db_local;
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
- _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
- _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL);
+ _alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n");
+ _alpm_recursedeps(db, trans->remove,
+ trans->flags & PM_TRANS_FLAG_RECURSEALL);
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
+ _alpm_log(handle, PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
+ lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
- remove_prepare_cascade(trans, db, lp);
+ remove_prepare_cascade(handle, lp);
} else if(trans->flags & PM_TRANS_FLAG_UNNEEDED) {
/* Remove needed packages (which would break dependencies)
* from target list */
- remove_prepare_keep_needed(trans, db, lp);
+ remove_prepare_keep_needed(handle, lp);
} else {
if(data) {
*data = lp;
@@ -170,21 +166,21 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
}
- RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
+ RET_ERR(handle, PM_ERR_UNSATISFIED_DEPS, -1);
}
}
}
/* re-order w.r.t. dependencies */
- _alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
- lp = _alpm_sortbydeps(trans->remove, 1);
+ _alpm_log(handle, PM_LOG_DEBUG, "sorting by dependencies\n");
+ lp = _alpm_sortbydeps(handle, trans->remove, 1);
/* free the old alltargs */
alpm_list_free(trans->remove);
trans->remove = lp;
/* -Rcs == -Rc then -Rs */
if((trans->flags & PM_TRANS_FLAG_CASCADE) && (trans->flags & PM_TRANS_FLAG_RECURSE)) {
- _alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n");
_alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL);
}
@@ -195,9 +191,10 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
return 0;
}
-static int can_remove_file(const char *path, alpm_list_t *skip)
+static int can_remove_file(pmhandle_t *handle, const char *path,
+ alpm_list_t *skip)
{
- char file[PATH_MAX+1];
+ char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s%s", handle->root, path);
@@ -211,7 +208,7 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
if(errno != EACCES && errno != ETXTBSY && access(file, F_OK) == 0) {
/* only return failure if the file ACTUALLY exists and we can't write to
* it - ignore "chmod -w" simple permission failures */
- _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
file, strerror(errno));
return 0;
}
@@ -222,12 +219,11 @@ static int can_remove_file(const char *path, alpm_list_t *skip)
/* Helper function for iterating through a package's file and deleting them
* Used by _alpm_remove_commit. */
-static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, int nosave)
+static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename,
+ alpm_list_t *skip_remove, int nosave)
{
struct stat buf;
- char file[PATH_MAX+1];
-
- ALPM_LOG_FUNC;
+ char file[PATH_MAX];
snprintf(file, PATH_MAX, "%s%s", handle->root, filename);
@@ -235,7 +231,7 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove,
* see the big comment block in db_find_fileconflicts() for an
* explanation. */
if(alpm_list_find_str(skip_remove, filename)) {
- _alpm_log(PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n",
file);
return;
}
@@ -245,51 +241,51 @@ static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove,
* filesystem, we want to work with the linked directory instead of the
* actual symlink */
if(lstat(file, &buf)) {
- _alpm_log(PM_LOG_DEBUG, "file %s does not exist\n", file);
+ _alpm_log(handle, PM_LOG_DEBUG, "file %s does not exist\n", file);
return;
}
if(S_ISDIR(buf.st_mode)) {
if(rmdir(file)) {
/* this is okay, other packages are probably using it (like /usr) */
- _alpm_log(PM_LOG_DEBUG, "keeping directory %s\n", file);
+ _alpm_log(handle, PM_LOG_DEBUG, "keeping directory %s\n", file);
} else {
- _alpm_log(PM_LOG_DEBUG, "removing directory %s\n", file);
+ _alpm_log(handle, PM_LOG_DEBUG, "removing directory %s\n", file);
}
} else {
/* if the file needs backup and has been modified, back it up to .pacsave */
char *pkghash = _alpm_needbackup(filename, alpm_pkg_get_backup(info));
if(pkghash) {
if(nosave) {
- _alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
+ _alpm_log(handle, PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
FREE(pkghash);
} else {
char *filehash = alpm_compute_md5sum(file);
- int cmp = strcmp(filehash,pkghash);
+ int cmp = filehash ? strcmp(filehash, pkghash) : 0;
FREE(filehash);
FREE(pkghash);
if(cmp != 0) {
char newpath[PATH_MAX];
snprintf(newpath, PATH_MAX, "%s.pacsave", file);
rename(file, newpath);
- _alpm_log(PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
- alpm_logaction("warning: %s saved as %s\n", file, newpath);
+ _alpm_log(handle, PM_LOG_WARNING, _("%s saved as %s\n"), file, newpath);
+ alpm_logaction(handle, "warning: %s saved as %s\n", file, newpath);
return;
}
}
}
- _alpm_log(PM_LOG_DEBUG, "unlinking %s\n", file);
+ _alpm_log(handle, PM_LOG_DEBUG, "unlinking %s\n", file);
if(unlink(file) == -1) {
- _alpm_log(PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("cannot remove file '%s': %s\n"),
filename, strerror(errno));
}
}
}
-int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
- pmtrans_t *trans)
+int _alpm_upgraderemove_package(pmhandle_t *handle,
+ pmpkg_t *oldpkg, pmpkg_t *newpkg)
{
alpm_list_t *skip_remove, *b;
alpm_list_t *newfiles, *lp;
@@ -297,18 +293,16 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
alpm_list_t *files = alpm_pkg_get_files(oldpkg);
const char *pkgname = alpm_pkg_get_name(oldpkg);
- ALPM_LOG_FUNC;
-
- _alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
oldpkg->name, oldpkg->version);
- if(trans->flags & PM_TRANS_FLAG_DBONLY) {
+ if(handle->trans->flags & PM_TRANS_FLAG_DBONLY) {
goto db;
}
/* copy the remove skiplist over */
skip_remove = alpm_list_join(
- alpm_list_strdup(trans->skip_remove),
+ alpm_list_strdup(handle->trans->skip_remove),
alpm_list_strdup(handle->noupgrade));
/* Add files in the NEW backup array to the skip_remove array
* so this removal operation doesn't kill them */
@@ -321,56 +315,52 @@ int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg,
FREE(backup);
continue;
}
- _alpm_log(PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup);
+ _alpm_log(handle, PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup);
skip_remove = alpm_list_add(skip_remove, backup);
}
for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(lp->data, skip_remove)) {
- _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
+ if(!can_remove_file(handle, lp->data, skip_remove)) {
+ _alpm_log(handle, PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
pkgname);
- RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
+ RET_ERR(handle, PM_ERR_PKG_CANT_REMOVE, -1);
}
}
filenum = alpm_list_count(files);
- _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
+ _alpm_log(handle, PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
- unlink_file(oldpkg, lp->data, skip_remove, 0);
+ unlink_file(handle, oldpkg, lp->data, skip_remove, 0);
}
alpm_list_free(newfiles);
FREELIST(skip_remove);
db:
/* remove the package from the database */
- _alpm_log(PM_LOG_DEBUG, "updating database\n");
- _alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
+ _alpm_log(handle, PM_LOG_DEBUG, "updating database\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
if(_alpm_local_db_remove(handle->db_local, oldpkg) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
pkgname, alpm_pkg_get_version(oldpkg));
}
/* remove the package from the cache */
if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
pkgname);
}
return 0;
}
-int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
+int _alpm_remove_packages(pmhandle_t *handle)
{
pmpkg_t *info;
alpm_list_t *targ, *lp;
size_t pkg_count;
-
- ALPM_LOG_FUNC;
-
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
pkg_count = alpm_list_count(trans->remove);
@@ -381,23 +371,23 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
const char *pkgname = NULL;
size_t targcount = alpm_list_count(targ);
- if(handle->trans->state == STATE_INTERRUPTED) {
+ if(trans->state == STATE_INTERRUPTED) {
return 0;
}
/* get the name now so we can use it after package is removed */
pkgname = alpm_pkg_get_name(info);
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(db), pkgname, alpm_pkg_get_version(info));
+ _alpm_db_path(handle->db_local), pkgname, alpm_pkg_get_version(info));
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
- _alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "removing package %s-%s\n",
pkgname, alpm_pkg_get_version(info));
/* run the pre-remove scriptlet if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
- alpm_pkg_get_version(info), NULL, trans);
+ _alpm_runscriptlet(handle, scriptlet, "pre_remove",
+ alpm_pkg_get_version(info), NULL);
}
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
@@ -406,15 +396,15 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
size_t filenum;
for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(lp->data, NULL)) {
- _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
+ if(!can_remove_file(handle, lp->data, NULL)) {
+ _alpm_log(handle, PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
pkgname);
- RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
+ RET_ERR(handle, PM_ERR_PKG_CANT_REMOVE, -1);
}
}
filenum = alpm_list_count(files);
- _alpm_log(PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
+ _alpm_log(handle, PM_LOG_DEBUG, "removing %ld files\n", (unsigned long)filenum);
/* init progress bar */
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 0,
@@ -424,7 +414,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
int percent;
- unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
+ unlink_file(handle, info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
/* update progress bar after each file */
percent = (position * 100) / filenum;
@@ -441,20 +431,20 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* run the post-remove script if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, scriptlet, "post_remove",
- alpm_pkg_get_version(info), NULL, trans);
+ _alpm_runscriptlet(handle, scriptlet, "post_remove",
+ alpm_pkg_get_version(info), NULL);
}
/* remove the package from the database */
- _alpm_log(PM_LOG_DEBUG, "updating database\n");
- _alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
- if(_alpm_local_db_remove(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
+ _alpm_log(handle, PM_LOG_DEBUG, "updating database\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
+ if(_alpm_local_db_remove(handle->db_local, info) == -1) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
pkgname, alpm_pkg_get_version(info));
}
/* remove the package from the cache */
- if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
+ if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -1) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
pkgname);
}
@@ -462,7 +452,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
}
/* run ldconfig if it exists */
- _alpm_ldconfig(handle->root);
+ _alpm_ldconfig(handle);
return 0;
}
diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h
index a67e37a1..5cab526a 100644
--- a/lib/libalpm/remove.h
+++ b/lib/libalpm/remove.h
@@ -24,10 +24,11 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
-int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
+int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data);
+int _alpm_remove_packages(pmhandle_t *handle);
-int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
+int _alpm_upgraderemove_package(pmhandle_t *handle,
+ pmpkg_t *oldpkg, pmpkg_t *newpkg);
#endif /* _ALPM_REMOVE_H */
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 9bb9d0ad..8124e674 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -35,6 +35,7 @@
#include "util.h"
#include "log.h"
#include "alpm.h"
+#include "handle.h"
#if HAVE_LIBGPGME
#define CHECK_ERR(void) do { \
@@ -104,28 +105,26 @@ static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
return summary;
}
-static int gpgme_init(void)
+static int gpgme_init(pmhandle_t *handle)
{
static int init = 0;
const char *version;
gpgme_error_t err;
gpgme_engine_info_t enginfo;
- ALPM_LOG_FUNC;
-
if(init) {
/* we already successfully initialized the library */
return 0;
}
- if(!alpm_option_get_signaturedir()) {
- RET_ERR(PM_ERR_SIG_MISSINGDIR, 1);
+ if(!alpm_option_get_signaturedir(handle)) {
+ RET_ERR(handle, PM_ERR_SIG_MISSINGDIR, 1);
}
/* calling gpgme_check_version() returns the current version and runs
* some internal library setup code */
version = gpgme_check_version(NULL);
- _alpm_log(PM_LOG_DEBUG, "GPGME version: %s\n", version);
+ _alpm_log(handle, PM_LOG_DEBUG, "GPGME version: %s\n", version);
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
#ifdef LC_MESSAGES
gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
@@ -144,19 +143,19 @@ static int gpgme_init(void)
/* set and check engine information */
err = gpgme_set_engine_info(GPGME_PROTOCOL_OpenPGP, NULL,
- alpm_option_get_signaturedir());
+ alpm_option_get_signaturedir(handle));
CHECK_ERR();
err = gpgme_get_engine_info(&enginfo);
CHECK_ERR();
- _alpm_log(PM_LOG_DEBUG, "GPGME engine info: file=%s, home=%s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "GPGME engine info: file=%s, home=%s\n",
enginfo->file_name, enginfo->home_dir);
init = 1;
return 0;
error:
- _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
- RET_ERR(PM_ERR_GPGME, 1);
+ _alpm_log(handle, PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
+ RET_ERR(handle, PM_ERR_GPGME, 1);
}
/**
@@ -196,12 +195,14 @@ error:
/**
* Check the PGP signature for the given file.
+ * @param handle the context handle
* @param path the full path to a file
* @param base64_sig PGP signature data in base64 encoding; if NULL, expect a
* signature file next to 'path'
* @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
*/
-int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
+int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
+ const char *base64_sig)
{
int ret = 0;
gpgme_error_t err;
@@ -213,29 +214,27 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
unsigned char *decoded_sigdata = NULL;
FILE *file = NULL, *sigfile = NULL;
- ALPM_LOG_FUNC;
-
if(!path || access(path, R_OK) != 0) {
- RET_ERR(PM_ERR_NOT_A_FILE, -1);
+ RET_ERR(handle, PM_ERR_NOT_A_FILE, -1);
}
if(!base64_sig) {
size_t len = strlen(path) + 5;
- CALLOC(sigpath, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(sigpath, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, -1));
snprintf(sigpath, len, "%s.sig", path);
if(!access(sigpath, R_OK) == 0) {
FREE(sigpath);
- RET_ERR(PM_ERR_SIG_UNKNOWN, -1);
+ RET_ERR(handle, PM_ERR_SIG_UNKNOWN, -1);
}
}
- if(gpgme_init()) {
+ if(gpgme_init(handle)) {
/* pm_errno was set in gpgme_init() */
return -1;
}
- _alpm_log(PM_LOG_DEBUG, "checking signature for %s\n", path);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking signature for %s\n", path);
memset(&ctx, 0, sizeof(ctx));
memset(&sigdata, 0, sizeof(sigdata));
@@ -247,7 +246,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
/* create our necessary data objects to verify the signature */
file = fopen(path, "rb");
if(file == NULL) {
- pm_errno = PM_ERR_NOT_A_FILE;
+ handle->pm_errno = PM_ERR_NOT_A_FILE;
ret = -1;
goto error;
}
@@ -270,7 +269,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
/* file-based, it is on disk */
sigfile = fopen(sigpath, "rb");
if(sigfile == NULL) {
- pm_errno = PM_ERR_NOT_A_FILE;
+ handle->pm_errno = PM_ERR_NOT_A_FILE;
ret = -1;
goto error;
}
@@ -289,7 +288,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
count++;
gpgsig = gpgsig->next;
}
- _alpm_log(PM_LOG_ERROR, _("Unexpected number of signatures (%d)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("Unexpected number of signatures (%d)\n"),
count);
ret = -1;
goto error;
@@ -298,42 +297,42 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
{
alpm_list_t *summary_list, *summary;
- _alpm_log(PM_LOG_DEBUG, "fingerprint: %s\n", gpgsig->fpr);
+ _alpm_log(handle, PM_LOG_DEBUG, "fingerprint: %s\n", gpgsig->fpr);
summary_list = gpgme_list_sigsum(gpgsig->summary);
for(summary = summary_list; summary; summary = summary->next) {
- _alpm_log(PM_LOG_DEBUG, "summary: %s\n", (const char *)summary->data);
+ _alpm_log(handle, PM_LOG_DEBUG, "summary: %s\n", (const char *)summary->data);
}
alpm_list_free(summary_list);
- _alpm_log(PM_LOG_DEBUG, "status: %s\n", gpgme_strerror(gpgsig->status));
- _alpm_log(PM_LOG_DEBUG, "timestamp: %lu\n", gpgsig->timestamp);
- _alpm_log(PM_LOG_DEBUG, "exp_timestamp: %lu\n", gpgsig->exp_timestamp);
- _alpm_log(PM_LOG_DEBUG, "validity: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "status: %s\n", gpgme_strerror(gpgsig->status));
+ _alpm_log(handle, PM_LOG_DEBUG, "timestamp: %lu\n", gpgsig->timestamp);
+ _alpm_log(handle, PM_LOG_DEBUG, "exp_timestamp: %lu\n", gpgsig->exp_timestamp);
+ _alpm_log(handle, PM_LOG_DEBUG, "validity: %s\n",
gpgme_string_validity(gpgsig->validity));
- _alpm_log(PM_LOG_DEBUG, "validity_reason: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "validity_reason: %s\n",
gpgme_strerror(gpgsig->validity_reason));
- _alpm_log(PM_LOG_DEBUG, "pubkey algo: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "pubkey algo: %s\n",
gpgme_pubkey_algo_name(gpgsig->pubkey_algo));
- _alpm_log(PM_LOG_DEBUG, "hash algo: %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "hash algo: %s\n",
gpgme_hash_algo_name(gpgsig->hash_algo));
}
if(gpgsig->summary & GPGME_SIGSUM_VALID) {
/* good signature, continue */
- _alpm_log(PM_LOG_DEBUG, _("File %s has a valid signature.\n"),
+ _alpm_log(handle, PM_LOG_DEBUG, _("File %s has a valid signature.\n"),
path);
} else if(gpgsig->summary & GPGME_SIGSUM_GREEN) {
/* 'green' signature, not sure what to do here */
- _alpm_log(PM_LOG_WARNING, _("File %s has a green signature.\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("File %s has a green signature.\n"),
path);
} else if(gpgsig->summary & GPGME_SIGSUM_KEY_MISSING) {
- pm_errno = PM_ERR_SIG_UNKNOWN;
- _alpm_log(PM_LOG_WARNING, _("File %s has a signature from an unknown key.\n"),
+ handle->pm_errno = PM_ERR_SIG_UNKNOWN;
+ _alpm_log(handle, PM_LOG_WARNING, _("File %s has a signature from an unknown key.\n"),
path);
ret = -1;
} else {
/* we'll capture everything else here */
- pm_errno = PM_ERR_SIG_INVALID;
- _alpm_log(PM_LOG_ERROR, _("File %s has an invalid signature.\n"),
+ handle->pm_errno = PM_ERR_SIG_INVALID;
+ _alpm_log(handle, PM_LOG_ERROR, _("File %s has an invalid signature.\n"),
path);
ret = 1;
}
@@ -351,13 +350,14 @@ error:
FREE(sigpath);
FREE(decoded_sigdata);
if(err != GPG_ERR_NO_ERROR) {
- _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
- RET_ERR(PM_ERR_GPGME, -1);
+ _alpm_log(handle, PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err));
+ RET_ERR(handle, PM_ERR_GPGME, -1);
}
return ret;
}
#else
-int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
+int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
+ const char *base64_sig)
{
return -1;
}
@@ -371,13 +371,10 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
*/
pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db)
{
- ALPM_LOG_FUNC;
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, PM_PGP_VERIFY_UNKNOWN));
-
if(db->pgp_verify != PM_PGP_VERIFY_UNKNOWN) {
return db->pgp_verify;
} else {
- return alpm_option_get_default_sigverify();
+ return alpm_option_get_default_sigverify(db->handle);
}
}
@@ -388,10 +385,10 @@ pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db)
*/
int SYMEXPORT alpm_pkg_check_pgp_signature(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
ASSERT(pkg != NULL, return 0);
- return _alpm_gpgme_checksig(alpm_pkg_get_filename(pkg), pkg->base64_sig);
+ return _alpm_gpgme_checksig(pkg->handle, alpm_pkg_get_filename(pkg),
+ pkg->base64_sig);
}
/**
@@ -401,10 +398,9 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(pmpkg_t *pkg)
*/
int SYMEXPORT alpm_db_check_pgp_signature(pmdb_t *db)
{
- ALPM_LOG_FUNC;
ASSERT(db != NULL, return 0);
- return _alpm_gpgme_checksig(_alpm_db_path(db), NULL);
+ return _alpm_gpgme_checksig(db->handle, _alpm_db_path(db), NULL);
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/signing.h b/lib/libalpm/signing.h
index 8d8c1643..fdf81fcf 100644
--- a/lib/libalpm/signing.h
+++ b/lib/libalpm/signing.h
@@ -21,7 +21,8 @@
#include "alpm.h"
-int _alpm_gpgme_checksig(const char *path, const char *base64_sig);
+int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path,
+ const char *base64_sig);
pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db);
#endif /* _ALPM_SIGNING_H */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 8dd51aaa..643d65e8 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -65,14 +65,14 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
}
if(spkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db => no upgrade\n",
+ _alpm_log(pkg->handle, PM_LOG_DEBUG, "'%s' not found in sync db => no upgrade\n",
alpm_pkg_get_name(pkg));
return NULL;
}
/* compare versions and see if spkg is an upgrade */
if(_alpm_pkg_compare_versions(spkg, pkg) > 0) {
- _alpm_log(PM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
+ _alpm_log(pkg->handle, PM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
alpm_pkg_get_version(spkg));
return spkg;
@@ -82,28 +82,26 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
}
/** Search for packages to upgrade and add them to the transaction. */
-int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
+int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade)
{
alpm_list_t *i, *j, *k;
pmtrans_t *trans;
pmdb_t *db_local;
alpm_list_t *dbs_sync;
- ALPM_LOG_FUNC;
-
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
trans = handle->trans;
db_local = handle->db_local;
dbs_sync = handle->dbs_sync;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1));
- _alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "checking for package upgrades\n");
for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
pmpkg_t *lpkg = i->data;
if(_alpm_pkg_find(trans->add, lpkg->name)) {
- _alpm_log(PM_LOG_DEBUG, "%s is already in the target list -- skipping\n", lpkg->name);
+ _alpm_log(handle, PM_LOG_DEBUG, "%s is already in the target list -- skipping\n", lpkg->name);
continue;
}
@@ -117,30 +115,32 @@ int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
/* 1. literal was found in sdb */
int cmp = _alpm_pkg_compare_versions(spkg, lpkg);
if(cmp > 0) {
- _alpm_log(PM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
lpkg->name, lpkg->version, spkg->version);
/* check IgnorePkg/IgnoreGroup */
- if(_alpm_pkg_should_ignore(spkg) || _alpm_pkg_should_ignore(lpkg)) {
- _alpm_log(PM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"),
- lpkg->name, lpkg->version, spkg->version);
+ if(_alpm_pkg_should_ignore(spkg)
+ || _alpm_pkg_should_ignore(lpkg)) {
+ _alpm_log(handle, PM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"),
+ lpkg->name, lpkg->version, spkg->version);
} else {
- _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
spkg->name, spkg->version);
trans->add = alpm_list_add(trans->add, spkg);
}
} else if(cmp < 0) {
if(enable_downgrade) {
/* check IgnorePkg/IgnoreGroup */
- if(_alpm_pkg_should_ignore(spkg) || _alpm_pkg_should_ignore(lpkg)) {
- _alpm_log(PM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"),
+ if(_alpm_pkg_should_ignore(spkg)
+ || _alpm_pkg_should_ignore(lpkg)) {
+ _alpm_log(handle, PM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"),
lpkg->name, lpkg->version, spkg->version);
} else {
- _alpm_log(PM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
lpkg->name, lpkg->version, spkg->version);
trans->add = alpm_list_add(trans->add, spkg);
}
} else {
- _alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
lpkg->name, lpkg->version, sdb->treename, spkg->version);
}
}
@@ -154,8 +154,9 @@ int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
if(alpm_list_find_str(alpm_pkg_get_replaces(spkg), lpkg->name)) {
found = 1;
/* check IgnorePkg/IgnoreGroup */
- if(_alpm_pkg_should_ignore(spkg) || _alpm_pkg_should_ignore(lpkg)) {
- _alpm_log(PM_LOG_WARNING, _("ignoring package replacement (%s-%s => %s-%s)\n"),
+ if(_alpm_pkg_should_ignore(spkg)
+ || _alpm_pkg_should_ignore(lpkg)) {
+ _alpm_log(handle, PM_LOG_WARNING, _("ignoring package replacement (%s-%s => %s-%s)\n"),
lpkg->name, lpkg->version, spkg->name, spkg->version);
continue;
}
@@ -172,11 +173,11 @@ int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
if(tpkg) {
/* sanity check, multiple repos can contain spkg->name */
if(tpkg->origin_data.db != sdb) {
- _alpm_log(PM_LOG_WARNING, _("cannot replace %s by %s\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("cannot replace %s by %s\n"),
lpkg->name, spkg->name);
continue;
}
- _alpm_log(PM_LOG_DEBUG, "appending %s to the removes list of %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "appending %s to the removes list of %s\n",
lpkg->name, tpkg->name);
tpkg->removes = alpm_list_add(tpkg->removes, lpkg);
/* check the to-be-replaced package's reason field */
@@ -188,7 +189,7 @@ int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
/* copy over reason */
spkg->reason = alpm_pkg_get_reason(lpkg);
spkg->removes = alpm_list_add(NULL, lpkg);
- _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
spkg->name, spkg->version);
trans->add = alpm_list_add(trans->add, spkg);
}
@@ -232,7 +233,7 @@ alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs,
if(_alpm_pkg_should_ignore(pkg)) {
ignorelist = alpm_list_add(ignorelist, pkg);
int install = 0;
- QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
+ QUESTION(db->handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install);
if(!install)
continue;
@@ -255,6 +256,7 @@ static int compute_download_size(pmpkg_t *newpkg)
const char *fname;
char *fpath;
off_t size = 0;
+ pmhandle_t *handle = newpkg->handle;
if(newpkg->origin != PKG_FROM_SYNCDB) {
newpkg->infolevel |= INFRQ_DSIZE;
@@ -263,8 +265,8 @@ static int compute_download_size(pmpkg_t *newpkg)
}
fname = alpm_pkg_get_filename(newpkg);
- ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
- fpath = _alpm_filecache_find(fname);
+ ASSERT(fname != NULL, RET_ERR(handle, PM_ERR_PKG_INVALID_NAME, -1));
+ fpath = _alpm_filecache_find(handle, fname);
if(fpath) {
FREE(fpath);
@@ -273,16 +275,16 @@ static int compute_download_size(pmpkg_t *newpkg)
off_t dltsize;
off_t pkgsize = alpm_pkg_get_size(newpkg);
- dltsize = _alpm_shortest_delta_path(
+ dltsize = _alpm_shortest_delta_path(newpkg->handle,
alpm_pkg_get_deltas(newpkg),
alpm_pkg_get_filename(newpkg),
&newpkg->delta_path);
if(newpkg->delta_path && (dltsize < pkgsize * MAX_DELTA_RATIO)) {
- _alpm_log(PM_LOG_DEBUG, "using delta size\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "using delta size\n");
size = dltsize;
} else {
- _alpm_log(PM_LOG_DEBUG, "using package size\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "using package size\n");
size = alpm_pkg_get_size(newpkg);
alpm_list_free(newpkg->delta_path);
newpkg->delta_path = NULL;
@@ -291,7 +293,7 @@ static int compute_download_size(pmpkg_t *newpkg)
size = alpm_pkg_get_size(newpkg);
}
- _alpm_log(PM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
(intmax_t)size, alpm_pkg_get_name(newpkg));
newpkg->infolevel |= INFRQ_DSIZE;
@@ -299,18 +301,14 @@ static int compute_download_size(pmpkg_t *newpkg)
return 0;
}
-int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data)
+int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data)
{
+ alpm_list_t *i, *j;
alpm_list_t *deps = NULL;
alpm_list_t *unresolvable = NULL;
- alpm_list_t *i, *j;
alpm_list_t *remove = NULL;
int ret = 0;
-
- ALPM_LOG_FUNC;
-
- ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
if(data) {
*data = NULL;
@@ -322,7 +320,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* Build up list by repeatedly resolving each transaction package */
/* Resolve targets dependencies */
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, "resolving target's dependencies\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "resolving target's dependencies\n");
/* build remove list for resolvedeps */
for(i = trans->add; i; i = i->next) {
@@ -334,14 +332,14 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* Compute the fake local database for resolvedeps (partial fix for the
* phonon/qt issue) */
- alpm_list_t *localpkgs = alpm_list_diff(_alpm_db_get_pkgcache(db_local),
+ alpm_list_t *localpkgs = alpm_list_diff(_alpm_db_get_pkgcache(handle->db_local),
trans->add, _alpm_pkg_cmp);
/* Resolve packages in the transaction one at a time, in addition
building up a list of packages which could not be resolved. */
for(i = trans->add; i; i = i->next) {
pmpkg_t *pkg = i->data;
- if(_alpm_resolvedeps(localpkgs, dbs_sync, pkg, trans->add,
+ if(_alpm_resolvedeps(handle, localpkgs, pkg, trans->add,
&resolved, remove, data) == -1) {
unresolvable = alpm_list_add(unresolvable, pkg);
}
@@ -354,14 +352,14 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
see if they'd like to ignore them rather than failing the sync */
if(unresolvable != NULL) {
int remove_unresolvable = 0;
- QUESTION(handle->trans, PM_TRANS_CONV_REMOVE_PKGS, unresolvable,
+ QUESTION(trans, PM_TRANS_CONV_REMOVE_PKGS, unresolvable,
NULL, NULL, &remove_unresolvable);
if(remove_unresolvable) {
/* User wants to remove the unresolvable packages from the
transaction. The packages will be removed from the actual
transaction when the transaction packages are replaced with a
dependency-reordered list below */
- pm_errno = 0; /* pm_errno was set by resolvedeps */
+ handle->pm_errno = 0; /* pm_errno was set by resolvedeps */
if(data) {
alpm_list_free_inner(*data, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(*data);
@@ -389,7 +387,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* re-order w.r.t. dependencies */
alpm_list_free(trans->add);
- trans->add = _alpm_sortbydeps(resolved, 0);
+ trans->add = _alpm_sortbydeps(handle, resolved, 0);
alpm_list_free(resolved);
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
@@ -399,11 +397,11 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* check for inter-conflicts and whatnot */
EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, "looking for conflicts\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "looking for conflicts\n");
/* 1. check for conflicts in the target list */
- _alpm_log(PM_LOG_DEBUG, "check targets vs targets\n");
- deps = _alpm_innerconflicts(trans->add);
+ _alpm_log(handle, PM_LOG_DEBUG, "check targets vs targets\n");
+ deps = _alpm_innerconflicts(handle, trans->add);
for(i = deps; i; i = i->next) {
pmconflict_t *conflict = i->data;
@@ -416,7 +414,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
continue;
}
- _alpm_log(PM_LOG_DEBUG, "conflicting packages in the sync list: '%s' <-> '%s'\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "conflicting packages in the sync list: '%s' <-> '%s'\n",
conflict->package1, conflict->package2);
/* if sync1 provides sync2, we remove sync2 from the targets, and vice versa */
@@ -429,8 +427,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
rsync = sync1;
sync = sync2;
} else {
- _alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
- pm_errno = PM_ERR_CONFLICTING_DEPS;
+ _alpm_log(handle, PM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
+ handle->pm_errno = PM_ERR_CONFLICTING_DEPS;
ret = -1;
if(data) {
pmconflict_t *newconflict = _alpm_conflict_dup(conflict);
@@ -448,7 +446,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_dep_free(dep2);
/* Prints warning */
- _alpm_log(PM_LOG_WARNING,
+ _alpm_log(handle, PM_LOG_WARNING,
_("removing '%s' from target list because it conflicts with '%s'\n"),
rsync->name, sync->name);
trans->add = alpm_list_remove(trans->add, rsync, _alpm_pkg_cmp, NULL);
@@ -461,8 +459,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
deps = NULL;
/* 2. we check for target vs db conflicts (and resolve)*/
- _alpm_log(PM_LOG_DEBUG, "check targets vs db and db vs targets\n");
- deps = _alpm_outerconflicts(db_local, trans->add);
+ _alpm_log(handle, PM_LOG_DEBUG, "check targets vs db and db vs targets\n");
+ deps = _alpm_outerconflicts(handle->db_local, trans->add);
for(i = deps; i; i = i->next) {
pmconflict_t *conflict = i->data;
@@ -480,21 +478,21 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
continue;
}
- _alpm_log(PM_LOG_DEBUG, "package '%s' conflicts with '%s'\n",
+ _alpm_log(handle, PM_LOG_DEBUG, "package '%s' conflicts with '%s'\n",
conflict->package1, conflict->package2);
pmpkg_t *sync = _alpm_pkg_find(trans->add, conflict->package1);
- pmpkg_t *local = _alpm_db_get_pkgfromcache(db_local, conflict->package2);
+ pmpkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2);
int doremove = 0;
QUESTION(trans, PM_TRANS_CONV_CONFLICT_PKG, conflict->package1,
conflict->package2, conflict->reason, &doremove);
if(doremove) {
/* append to the removes list */
- _alpm_log(PM_LOG_DEBUG, "electing '%s' for removal\n", conflict->package2);
+ _alpm_log(handle, PM_LOG_DEBUG, "electing '%s' for removal\n", conflict->package2);
sync->removes = alpm_list_add(sync->removes, local);
} else { /* abort */
- _alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
- pm_errno = PM_ERR_CONFLICTING_DEPS;
+ _alpm_log(handle, PM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
+ handle->pm_errno = PM_ERR_CONFLICTING_DEPS;
ret = -1;
if(data) {
pmconflict_t *newconflict = _alpm_conflict_dup(conflict);
@@ -518,17 +516,18 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
for(j = spkg->removes; j; j = j->next) {
pmpkg_t *rpkg = j->data;
if(!_alpm_pkg_find(trans->remove, rpkg->name)) {
- _alpm_log(PM_LOG_DEBUG, "adding '%s' to remove list\n", rpkg->name);
+ _alpm_log(handle, PM_LOG_DEBUG, "adding '%s' to remove list\n", rpkg->name);
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(rpkg));
}
}
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
- _alpm_log(PM_LOG_DEBUG, "checking dependencies\n");
- deps = alpm_checkdeps(_alpm_db_get_pkgcache(db_local), 1, trans->remove, trans->add);
+ _alpm_log(handle, PM_LOG_DEBUG, "checking dependencies\n");
+ deps = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
+ trans->remove, trans->add, 1);
if(deps) {
- pm_errno = PM_ERR_UNSATISFIED_DEPS;
+ handle->pm_errno = PM_ERR_UNSATISFIED_DEPS;
ret = -1;
if(data) {
*data = deps;
@@ -579,15 +578,16 @@ static int endswith(const char *filename, const char *extension)
* All intermediate files are deleted, leaving only the starting and
* ending package files.
*
- * @param trans the transaction
+ * @param handle the context handle
*
* @return 0 if all delta files were able to be applied, 1 otherwise.
*/
-static int apply_deltas(pmtrans_t *trans)
+static int apply_deltas(pmhandle_t *handle)
{
alpm_list_t *i;
int ret = 0;
- const char *cachedir = _alpm_filecache_setup();
+ const char *cachedir = _alpm_filecache_setup(handle);
+ pmtrans_t *trans = handle->trans;
for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
@@ -604,18 +604,18 @@ static int apply_deltas(pmtrans_t *trans)
char command[PATH_MAX];
size_t len = 0;
- delta = _alpm_filecache_find(d->delta);
+ delta = _alpm_filecache_find(handle, d->delta);
/* the initial package might be in a different cachedir */
if(dlts == delta_path) {
- from = _alpm_filecache_find(d->from);
+ from = _alpm_filecache_find(handle, d->from);
} else {
/* len = cachedir len + from len + '/' + null */
len = strlen(cachedir) + strlen(d->from) + 2;
- CALLOC(from, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, 1));
+ CALLOC(from, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, 1));
snprintf(from, len, "%s/%s", cachedir, d->from);
}
len = strlen(cachedir) + strlen(d->to) + 2;
- CALLOC(to, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, 1));
+ CALLOC(to, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, 1));
snprintf(to, len, "%s/%s", cachedir, d->to);
/* build the patch command */
@@ -626,7 +626,7 @@ static int apply_deltas(pmtrans_t *trans)
snprintf(command, PATH_MAX, "xdelta3 -d -q -s %s %s %s", from, delta, to);
}
- _alpm_log(PM_LOG_DEBUG, "command: %s\n", command);
+ _alpm_log(handle, PM_LOG_DEBUG, "command: %s\n", command);
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, d->to, d->delta);
@@ -651,7 +651,7 @@ static int apply_deltas(pmtrans_t *trans)
if(retval != 0) {
/* one delta failed for this package, cancel the remaining ones */
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_FAILED, NULL, NULL);
- pm_errno = PM_ERR_DLT_PATCHFAILED;
+ handle->pm_errno = PM_ERR_DLT_PATCHFAILED;
ret = 1;
break;
}
@@ -688,11 +688,12 @@ static int test_md5sum(pmtrans_t *trans, const char *filepath,
return ret;
}
-static int validate_deltas(pmtrans_t *trans, alpm_list_t *deltas,
+static int validate_deltas(pmhandle_t *handle, alpm_list_t *deltas,
alpm_list_t **data)
{
int errors = 0, ret = 0;
alpm_list_t *i;
+ pmtrans_t *trans = handle->trans;
if(!deltas) {
return 0;
@@ -704,7 +705,7 @@ static int validate_deltas(pmtrans_t *trans, alpm_list_t *deltas,
for(i = deltas; i; i = i->next) {
pmdelta_t *d = alpm_list_getdata(i);
const char *filename = alpm_delta_get_filename(d);
- char *filepath = _alpm_filecache_find(filename);
+ char *filepath = _alpm_filecache_find(handle, filename);
const char *md5sum = alpm_delta_get_md5sum(d);
if(test_md5sum(trans, filepath, md5sum) != 0) {
@@ -714,27 +715,27 @@ static int validate_deltas(pmtrans_t *trans, alpm_list_t *deltas,
FREE(filepath);
}
if(errors) {
- pm_errno = PM_ERR_DLT_INVALID;
+ handle->pm_errno = PM_ERR_DLT_INVALID;
return -1;
}
EVENT(trans, PM_TRANS_EVT_DELTA_INTEGRITY_DONE, NULL, NULL);
/* Use the deltas to generate the packages */
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_START, NULL, NULL);
- ret = apply_deltas(trans);
+ ret = apply_deltas(handle);
EVENT(trans, PM_TRANS_EVT_DELTA_PATCHES_DONE, NULL, NULL);
return ret;
}
-static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
+static int download_files(pmhandle_t *handle, alpm_list_t **deltas)
{
const char *cachedir;
alpm_list_t *i, *j;
alpm_list_t *files = NULL;
int errors = 0;
- cachedir = _alpm_filecache_setup();
- trans->state = STATE_DOWNLOADING;
+ cachedir = _alpm_filecache_setup(handle);
+ handle->trans->state = STATE_DOWNLOADING;
/* Total progress - figure out the total download size if required to
* pass to the callback. This function is called once, and it is up to the
@@ -742,7 +743,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
if(handle->totaldlcb) {
off_t total_size = (off_t)0;
/* sum up the download size for each package and store total */
- for(i = trans->add; i; i = i->next) {
+ for(i = handle->trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
total_size += spkg->download_size;
}
@@ -753,14 +754,14 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
for(i = handle->dbs_sync; i; i = i->next) {
pmdb_t *current = i->data;
- for(j = trans->add; j; j = j->next) {
+ for(j = handle->trans->add; j; j = j->next) {
pmpkg_t *spkg = j->data;
if(spkg->origin != PKG_FROM_FILE && current == spkg->origin_data.db) {
const char *fname = NULL;
fname = alpm_pkg_get_filename(spkg);
- ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
+ ASSERT(fname != NULL, RET_ERR(handle, PM_ERR_PKG_INVALID_NAME, -1));
alpm_list_t *delta_path = spkg->delta_path;
if(delta_path) {
/* using deltas */
@@ -782,7 +783,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
}
if(files) {
- EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
+ EVENT(handle->trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
for(j = files; j; j = j->next) {
const char *filename = j->data;
alpm_list_t *server;
@@ -794,10 +795,10 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
/* print server + filename into a buffer */
len = strlen(server_url) + strlen(filename) + 2;
- CALLOC(fileurl, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(fileurl, len, sizeof(char), RET_ERR(handle, PM_ERR_MEMORY, -1));
snprintf(fileurl, len, "%s/%s", server_url, filename);
- ret = _alpm_download(fileurl, cachedir, 0, 1, 0);
+ ret = _alpm_download(handle, fileurl, cachedir, 0, 1, 0);
FREE(fileurl);
if(ret != -1) {
break;
@@ -810,17 +811,17 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
FREELIST(files);
if(errors) {
- _alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
current->treename);
- if(pm_errno == 0) {
- pm_errno = PM_ERR_RETRIEVE;
+ if(handle->pm_errno == 0) {
+ handle->pm_errno = PM_ERR_RETRIEVE;
}
return -1;
}
}
}
- for(j = trans->add; j; j = j->next) {
+ for(j = handle->trans->add; j; j = j->next) {
pmpkg_t *pkg = j->data;
pkg->infolevel &= ~INFRQ_DSIZE;
pkg->download_size = 0;
@@ -833,23 +834,20 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
return 0;
}
-int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
+int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data)
{
alpm_list_t *i;
alpm_list_t *deltas = NULL;
size_t numtargs, current = 0, replaces = 0;
int errors;
+ pmtrans_t *trans = handle->trans;
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
- if(download_files(trans, &deltas)) {
+ if(download_files(handle, &deltas)) {
alpm_list_free(deltas);
return -1;
}
- if(validate_deltas(trans, deltas, data)) {
+ if(validate_deltas(handle, deltas, data)) {
alpm_list_free(deltas);
return -1;
}
@@ -875,14 +873,16 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
}
filename = alpm_pkg_get_filename(spkg);
- filepath = _alpm_filecache_find(filename);
+ filepath = _alpm_filecache_find(handle, filename);
pmdb_t *sdb = alpm_pkg_get_db(spkg);
check_sig = _alpm_db_get_sigverify_level(sdb);
/* load the package file and replace pkgcache entry with it in the target list */
/* TODO: alpm_pkg_get_db() will not work on this target anymore */
- _alpm_log(PM_LOG_DEBUG, "replacing pkgcache entry with package file for target %s\n", spkg->name);
- pmpkg_t *pkgfile =_alpm_pkg_load_internal(filepath, 1, spkg->md5sum,
+ _alpm_log(handle, PM_LOG_DEBUG,
+ "replacing pkgcache entry with package file for target %s\n",
+ spkg->name);
+ pmpkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1, spkg->md5sum,
spkg->base64_sig, check_sig);
if(!pkgfile) {
errors++;
@@ -902,7 +902,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(errors) {
- RET_ERR(PM_ERR_PKG_INVALID, -1);
+ RET_ERR(handle, PM_ERR_PKG_INVALID, -1);
}
if(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY) {
@@ -917,9 +917,9 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(!(trans->flags & PM_TRANS_FLAG_FORCE)) {
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, "looking for file conflicts\n");
- alpm_list_t *conflict = _alpm_db_find_fileconflicts(db_local, trans,
- trans->add, trans->remove);
+ _alpm_log(handle, PM_LOG_DEBUG, "looking for file conflicts\n");
+ alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle,
+ trans->add, trans->remove);
if(conflict) {
if(data) {
*data = conflict;
@@ -927,7 +927,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
alpm_list_free_inner(conflict, (alpm_list_fn_free)_alpm_fileconflict_free);
alpm_list_free(conflict);
}
- RET_ERR(PM_ERR_FILE_CONFLICTS, -1);
+ RET_ERR(handle, PM_ERR_FILE_CONFLICTS, -1);
}
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
@@ -937,9 +937,9 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(handle->checkspace) {
EVENT(trans, PM_TRANS_EVT_DISKSPACE_START, NULL, NULL);
- _alpm_log(PM_LOG_DEBUG, "checking available disk space\n");
- if(_alpm_check_diskspace(trans, handle->db_local) == -1) {
- _alpm_log(PM_LOG_ERROR, "%s\n", _("not enough free disk space"));
+ _alpm_log(handle, PM_LOG_DEBUG, "checking available disk space\n");
+ if(_alpm_check_diskspace(handle) == -1) {
+ _alpm_log(handle, PM_LOG_ERROR, "%s\n", _("not enough free disk space"));
return -1;
}
@@ -948,18 +948,18 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
/* remove conflicting and to-be-replaced packages */
if(replaces) {
- _alpm_log(PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
/* we want the frontend to be aware of commit details */
- if(_alpm_remove_packages(trans, handle->db_local) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n"));
+ if(_alpm_remove_packages(handle) == -1) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not commit removal transaction\n"));
return -1;
}
}
/* install targets */
- _alpm_log(PM_LOG_DEBUG, "installing packages\n");
- if(_alpm_upgrade_packages(trans, handle->db_local) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not commit transaction\n"));
+ _alpm_log(handle, PM_LOG_DEBUG, "installing packages\n");
+ if(_alpm_upgrade_packages(handle) == -1) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not commit transaction\n"));
return -1;
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 90a2d40d..3049dd21 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -24,8 +24,8 @@
#include "alpm.h"
-int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data);
-int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
+int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data);
+int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data);
#endif /* _ALPM_SYNC_H */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 4e88668b..a95280c7 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -54,6 +54,8 @@ static int make_lock(pmhandle_t *handle)
int fd;
char *dir, *ptr;
+ ASSERT(handle->lockfile != NULL, return -1);
+
/* create the dir of the lockfile first */
dir = strdup(handle->lockfile);
ptr = strrchr(dir, '/');
@@ -94,7 +96,7 @@ static int remove_lock(pmhandle_t *handle)
}
/** Initialize the transaction. */
-int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
+int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{
@@ -102,51 +104,45 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
const int required_db_version = 2;
int db_version;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
-
- ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(handle->trans == NULL, RET_ERR(handle, PM_ERR_TRANS_NOT_NULL, -1));
/* lock db */
if(!(flags & PM_TRANS_FLAG_NOLOCK)) {
if(make_lock(handle)) {
- RET_ERR(PM_ERR_HANDLE_LOCK, -1);
+ RET_ERR(handle, PM_ERR_HANDLE_LOCK, -1);
}
}
+ CALLOC(trans, 1, sizeof(pmtrans_t), RET_ERR(handle, PM_ERR_MEMORY, -1));
+ trans->flags = flags;
+ trans->cb_event = event;
+ trans->cb_conv = conv;
+ trans->cb_progress = progress;
+ trans->state = STATE_INITIALIZED;
+
/* check database version */
db_version = _alpm_db_version(handle->db_local);
if(db_version < required_db_version) {
- _alpm_log(PM_LOG_ERROR,
+ _alpm_log(handle, PM_LOG_ERROR,
_("%s database version is too old\n"), handle->db_local->treename);
remove_lock(handle);
- RET_ERR(PM_ERR_DB_VERSION, -1);
- }
-
- trans = _alpm_trans_new();
- if(trans == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ _alpm_trans_free(trans);
+ RET_ERR(handle, PM_ERR_DB_VERSION, -1);
}
- trans->flags = flags;
- trans->cb_event = event;
- trans->cb_conv = conv;
- trans->cb_progress = progress;
- trans->state = STATE_INITIALIZED;
-
handle->trans = trans;
return 0;
}
-static alpm_list_t *check_arch(alpm_list_t *pkgs)
+static alpm_list_t *check_arch(pmhandle_t *handle, alpm_list_t *pkgs)
{
alpm_list_t *i;
alpm_list_t *invalid = NULL;
- const char *arch = alpm_option_get_arch();
+ const char *arch = alpm_option_get_arch(handle);
if(!arch) {
return NULL;
}
@@ -158,7 +154,7 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs)
const char *pkgname = alpm_pkg_get_name(pkg);
const char *pkgver = alpm_pkg_get_version(pkg);
size_t len = strlen(pkgname) + strlen(pkgver) + strlen(pkgarch) + 3;
- MALLOC(string, len, RET_ERR(PM_ERR_MEMORY, invalid));
+ MALLOC(string, len, RET_ERR(handle, PM_ERR_MEMORY, invalid));
sprintf(string, "%s-%s-%s", pkgname, pkgver, pkgarch);
invalid = alpm_list_add(invalid, string);
}
@@ -167,41 +163,39 @@ static alpm_list_t *check_arch(alpm_list_t *pkgs)
}
/** Prepare a transaction. */
-int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
+int SYMEXPORT alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data)
{
pmtrans_t *trans;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(data != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1));
/* If there's nothing to do, return without complaining */
if(trans->add == NULL && trans->remove == NULL) {
return 0;
}
- alpm_list_t *invalid = check_arch(trans->add);
+ alpm_list_t *invalid = check_arch(handle, trans->add);
if(invalid) {
if(data) {
*data = invalid;
}
- RET_ERR(PM_ERR_PKG_INVALID_ARCH, -1);
+ RET_ERR(handle, PM_ERR_PKG_INVALID_ARCH, -1);
}
if(trans->add == NULL) {
- if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
+ if(_alpm_remove_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_remove_prepare() */
return -1;
}
} else {
- if(_alpm_sync_prepare(trans, handle->db_local, handle->dbs_sync, data) == -1) {
+ if(_alpm_sync_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_sync_prepare() */
return -1;
}
@@ -213,21 +207,19 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
}
/** Commit a transaction. */
-int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
+int SYMEXPORT alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data)
{
pmtrans_t *trans;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_PREPARED, RET_ERR(PM_ERR_TRANS_NOT_PREPARED, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_PREPARED, RET_ERR(handle, PM_ERR_TRANS_NOT_PREPARED, -1));
- ASSERT(!(trans->flags & PM_TRANS_FLAG_NOLOCK), RET_ERR(PM_ERR_TRANS_NOT_LOCKED, -1));
+ ASSERT(!(trans->flags & PM_TRANS_FLAG_NOLOCK), RET_ERR(handle, PM_ERR_TRANS_NOT_LOCKED, -1));
/* If there's nothing to do, return without complaining */
if(trans->add == NULL && trans->remove == NULL) {
@@ -237,12 +229,12 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
trans->state = STATE_COMMITING;
if(trans->add == NULL) {
- if(_alpm_remove_packages(trans, handle->db_local) == -1) {
+ if(_alpm_remove_packages(handle) == -1) {
/* pm_errno is set by _alpm_remove_commit() */
return -1;
}
} else {
- if(_alpm_sync_commit(trans, handle->db_local, data) == -1) {
+ if(_alpm_sync_commit(handle, data) == -1) {
/* pm_errno is set by _alpm_sync_commit() */
return -1;
}
@@ -254,19 +246,17 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
}
/** Interrupt a transaction. */
-int SYMEXPORT alpm_trans_interrupt(void)
+int SYMEXPORT alpm_trans_interrupt(pmhandle_t *handle)
{
pmtrans_t *trans;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state == STATE_COMMITING || trans->state == STATE_INTERRUPTED,
- RET_ERR(PM_ERR_TRANS_TYPE, -1));
+ RET_ERR(handle, PM_ERR_TRANS_TYPE, -1));
trans->state = STATE_INTERRUPTED;
@@ -274,18 +264,16 @@ int SYMEXPORT alpm_trans_interrupt(void)
}
/** Release a transaction. */
-int SYMEXPORT alpm_trans_release(void)
+int SYMEXPORT alpm_trans_release(pmhandle_t *handle)
{
pmtrans_t *trans;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ ASSERT(handle != NULL, return -1);
trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state != STATE_IDLE, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state != STATE_IDLE, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
int nolock_flag = trans->flags & PM_TRANS_FLAG_NOLOCK;
@@ -295,10 +283,10 @@ int SYMEXPORT alpm_trans_release(void)
/* unlock db */
if(!nolock_flag) {
if(remove_lock(handle)) {
- _alpm_log(PM_LOG_WARNING, _("could not remove lock file %s\n"),
- alpm_option_get_lockfile());
- alpm_logaction("warning: could not remove lock file %s\n",
- alpm_option_get_lockfile());
+ _alpm_log(handle, PM_LOG_WARNING, _("could not remove lock file %s\n"),
+ alpm_option_get_lockfile(handle));
+ alpm_logaction(handle, "warning: could not remove lock file %s\n",
+ alpm_option_get_lockfile(handle));
}
}
@@ -307,22 +295,8 @@ int SYMEXPORT alpm_trans_release(void)
/** @} */
-pmtrans_t *_alpm_trans_new(void)
-{
- pmtrans_t *trans;
-
- ALPM_LOG_FUNC;
-
- CALLOC(trans, 1, sizeof(pmtrans_t), RET_ERR(PM_ERR_MEMORY, NULL));
- trans->state = STATE_IDLE;
-
- return trans;
-}
-
void _alpm_trans_free(pmtrans_t *trans)
{
- ALPM_LOG_FUNC;
-
if(trans == NULL) {
return;
}
@@ -363,9 +337,8 @@ static int grep(const char *fn, const char *needle)
return 0;
}
-int _alpm_runscriptlet(const char *root, const char *installfn,
- const char *script, const char *ver,
- const char *oldver, pmtrans_t UNUSED *trans)
+int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn,
+ const char *script, const char *ver, const char *oldver)
{
char scriptfn[PATH_MAX];
char cmdline[PATH_MAX];
@@ -375,22 +348,20 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
int clean_tmpdir = 0;
int retval = 0;
- ALPM_LOG_FUNC;
-
if(access(installfn, R_OK)) {
/* not found */
- _alpm_log(PM_LOG_DEBUG, "scriptlet '%s' not found\n", installfn);
+ _alpm_log(handle, PM_LOG_DEBUG, "scriptlet '%s' not found\n", installfn);
return 0;
}
/* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
- snprintf(tmpdir, PATH_MAX, "%stmp/", root);
+ snprintf(tmpdir, PATH_MAX, "%stmp/", handle->root);
if(access(tmpdir, F_OK) != 0) {
_alpm_makepath_mode(tmpdir, 01777);
}
- snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root);
+ snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", handle->root);
if(mkdtemp(tmpdir) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not create temp directory\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not create temp directory\n"));
return 1;
} else {
clean_tmpdir = 1;
@@ -399,12 +370,12 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* either extract or copy the scriptlet */
snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir);
if(strcmp(script, "pre_upgrade") == 0 || strcmp(script, "pre_install") == 0) {
- if(_alpm_unpack_single(installfn, tmpdir, ".INSTALL")) {
+ if(_alpm_unpack_single(handle, installfn, tmpdir, ".INSTALL")) {
retval = 1;
}
} else {
if(_alpm_copyfile(installfn, scriptfn)) {
- _alpm_log(PM_LOG_ERROR, _("could not copy tempfile to %s (%s)\n"), scriptfn, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not copy tempfile to %s (%s)\n"), scriptfn, strerror(errno));
retval = 1;
}
}
@@ -413,7 +384,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
}
/* chop off the root so we can find the tmpdir in the chroot */
- scriptpath = scriptfn + strlen(root) - 1;
+ scriptpath = scriptfn + strlen(handle->root) - 1;
if(!grep(scriptfn, script)) {
/* script not found in scriptlet file */
@@ -428,41 +399,41 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
scriptpath, script, ver);
}
- _alpm_log(PM_LOG_DEBUG, "executing \"%s\"\n", cmdline);
+ _alpm_log(handle, PM_LOG_DEBUG, "executing \"%s\"\n", cmdline);
- retval = _alpm_run_chroot(root, "/bin/sh", argv);
+ retval = _alpm_run_chroot(handle, "/bin/sh", argv);
cleanup:
if(clean_tmpdir && _alpm_rmrf(tmpdir)) {
- _alpm_log(PM_LOG_WARNING, _("could not remove tmpdir %s\n"), tmpdir);
+ _alpm_log(handle, PM_LOG_WARNING, _("could not remove tmpdir %s\n"), tmpdir);
}
return retval;
}
-int SYMEXPORT alpm_trans_get_flags()
+pmtransflag_t SYMEXPORT alpm_trans_get_flags(pmhandle_t *handle)
{
/* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(handle != NULL, return -1);
+ ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1));
return handle->trans->flags;
}
-alpm_list_t SYMEXPORT * alpm_trans_get_add()
+alpm_list_t SYMEXPORT *alpm_trans_get_add(pmhandle_t *handle)
{
/* Sanity checks */
ASSERT(handle != NULL, return NULL);
- ASSERT(handle->trans != NULL, return NULL);
+ ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, NULL));
return handle->trans->add;
}
-alpm_list_t SYMEXPORT * alpm_trans_get_remove()
+alpm_list_t SYMEXPORT *alpm_trans_get_remove(pmhandle_t *handle)
{
/* Sanity checks */
ASSERT(handle != NULL, return NULL);
- ASSERT(handle->trans != NULL, return NULL);
+ ASSERT(handle->trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, NULL));
return handle->trans->remove;
}
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 6702881b..e8587156 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -66,14 +66,12 @@ do { \
} \
} while(0)
-pmtrans_t *_alpm_trans_new(void);
void _alpm_trans_free(pmtrans_t *trans);
int _alpm_trans_init(pmtrans_t *trans, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress);
-int _alpm_runscriptlet(const char *root, const char *installfn,
- const char *script, const char *ver,
- const char *oldver, pmtrans_t *trans);
+int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn,
+ const char *script, const char *ver, const char *oldver);
#endif /* _ALPM_TRANS_H */
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 99dd3bea..357ce506 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -56,6 +56,7 @@
#include "alpm.h"
#include "alpm_list.h"
#include "handle.h"
+#include "trans.h"
#ifndef HAVE_STRSEP
/* This is a replacement for strsep which is not portable (missing on Solaris).
@@ -151,9 +152,6 @@ int _alpm_copyfile(const char *src, const char *dest)
size_t nwritten = 0;
nwritten = fwrite(buf, 1, len, out);
if((nwritten != len) || ferror(out)) {
- pm_errno = PM_ERR_WRITE;
- _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
- dest, strerror(errno));
ret = -1;
goto cleanup;
}
@@ -214,20 +212,22 @@ char *_alpm_strtrim(char *str)
/**
* @brief Unpack a specific file in an archive.
*
- * @param archive the archive to unpack
- * @param prefix where to extract the files
- * @param fn a file within the archive to unpack
+ * @param handle the context handle
+ * @param archive the archive to unpack
+ * @param prefix where to extract the files
+ * @param filename a file within the archive to unpack
* @return 0 on success, 1 on failure
*/
-int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn)
+int _alpm_unpack_single(pmhandle_t *handle, const char *archive,
+ const char *prefix, const char *filename)
{
alpm_list_t *list = NULL;
int ret = 0;
- if(fn == NULL) {
+ if(filename == NULL) {
return 1;
}
- list = alpm_list_add(list, (void *)fn);
- ret = _alpm_unpack(archive, prefix, list, 1);
+ list = alpm_list_add(list, (void *)filename);
+ ret = _alpm_unpack(handle, archive, prefix, list, 1);
alpm_list_free(list);
return ret;
}
@@ -235,15 +235,16 @@ int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn)
/**
* @brief Unpack a list of files in an archive.
*
- * @param archive the archive to unpack
- * @param prefix where to extract the files
- * @param list a list of files within the archive to unpack or
- * NULL for all
+ * @param handle the context handle
+ * @param archive the archive to unpack
+ * @param prefix where to extract the files
+ * @param list a list of files within the archive to unpack or NULL for all
* @param breakfirst break after the first entry found
*
* @return 0 on success, 1 on failure
*/
-int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst)
+int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix,
+ alpm_list_t *list, int breakfirst)
{
int ret = 0;
mode_t oldmask;
@@ -252,33 +253,33 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int
char cwd[PATH_MAX];
int restore_cwd = 0;
- ALPM_LOG_FUNC;
-
- if((_archive = archive_read_new()) == NULL)
- RET_ERR(PM_ERR_LIBARCHIVE, 1);
+ if((_archive = archive_read_new()) == NULL) {
+ RET_ERR(handle, PM_ERR_LIBARCHIVE, 1);
+ }
archive_read_support_compression_all(_archive);
archive_read_support_format_all(_archive);
if(archive_read_open_filename(_archive, archive,
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), archive,
+ _alpm_log(handle, PM_LOG_ERROR, _("could not open file %s: %s\n"), archive,
archive_error_string(_archive));
- RET_ERR(PM_ERR_PKG_OPEN, 1);
+ RET_ERR(handle, PM_ERR_PKG_OPEN, 1);
}
oldmask = umask(0022);
/* save the cwd so we can restore it later */
if(getcwd(cwd, PATH_MAX) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not get current working directory\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not get current working directory\n"));
} else {
restore_cwd = 1;
}
/* just in case our cwd was removed in the upgrade operation */
if(chdir(prefix) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), prefix, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
+ prefix, strerror(errno));
ret = 1;
goto cleanup;
}
@@ -312,7 +313,7 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int
}
continue;
} else {
- _alpm_log(PM_LOG_DEBUG, "extracting: %s\n", entryname);
+ _alpm_log(handle, PM_LOG_DEBUG, "extracting: %s\n", entryname);
}
}
@@ -320,10 +321,10 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int
int readret = archive_read_extract(_archive, entry, 0);
if(readret == ARCHIVE_WARN) {
/* operation succeeded but a non-critical error was encountered */
- _alpm_log(PM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
entryname, archive_error_string(_archive));
} else if(readret != ARCHIVE_OK) {
- _alpm_log(PM_LOG_ERROR, _("could not extract %s (%s)\n"),
+ _alpm_log(handle, PM_LOG_ERROR, _("could not extract %s (%s)\n"),
entryname, archive_error_string(_archive));
ret = 1;
goto cleanup;
@@ -338,7 +339,8 @@ cleanup:
umask(oldmask);
archive_read_finish(_archive);
if(restore_cwd && chdir(cwd) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
+ cwd, strerror(errno));
}
return ret;
}
@@ -386,11 +388,11 @@ int _alpm_rmrf(const char *path)
return 0;
}
-int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
+int _alpm_logaction(pmhandle_t *handle, const char *fmt, va_list args)
{
int ret = 0;
- if(usesyslog) {
+ if(handle->usesyslog) {
/* we can't use a va_list more than once, so we need to copy it
* so we can use the original when calling vfprintf below. */
va_list args_syslog;
@@ -399,7 +401,7 @@ int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
va_end(args_syslog);
}
- if(f) {
+ if(handle->logstream) {
time_t t;
struct tm *tm;
@@ -407,17 +409,17 @@ int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
tm = localtime(&t);
/* Use ISO-8601 date format */
- fprintf(f, "[%04d-%02d-%02d %02d:%02d] ",
+ fprintf(handle->logstream, "[%04d-%02d-%02d %02d:%02d] ",
tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
tm->tm_hour, tm->tm_min);
- ret = vfprintf(f, fmt, args);
- fflush(f);
+ ret = vfprintf(handle->logstream, fmt, args);
+ fflush(handle->logstream);
}
return ret;
}
-int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
+int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[])
{
char cwd[PATH_MAX];
pid_t pid;
@@ -425,28 +427,28 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
int restore_cwd = 0;
int retval = 0;
- ALPM_LOG_FUNC;
-
/* save the cwd so we can restore it later */
if(getcwd(cwd, PATH_MAX) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not get current working directory\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not get current working directory\n"));
} else {
restore_cwd = 1;
}
/* just in case our cwd was removed in the upgrade operation */
- if(chdir(root) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), root, strerror(errno));
+ if(chdir(handle->root) != 0) {
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
+ handle->root, strerror(errno));
goto cleanup;
}
- _alpm_log(PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n", path, root);
+ _alpm_log(handle, PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n",
+ path, handle->root);
/* Flush open fds before fork() to avoid cloning buffers */
fflush(NULL);
if(pipe(pipefd) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not create pipe (%s)\n"), strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not create pipe (%s)\n"), strerror(errno));
retval = 1;
goto cleanup;
}
@@ -454,7 +456,7 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
/* fork- parent and child each have seperate code blocks below */
pid = fork();
if(pid == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not fork a new process (%s)\n"), strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not fork a new process (%s)\n"), strerror(errno));
retval = 1;
goto cleanup;
}
@@ -469,7 +471,7 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
close(pipefd[1]);
/* use fprintf instead of _alpm_log to send output through the parent */
- if(chroot(root) != 0) {
+ if(chroot(handle->root) != 0) {
fprintf(stderr, _("could not change the root directory (%s)\n"), strerror(errno));
exit(1);
}
@@ -497,7 +499,7 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
char line[PATH_MAX];
if(fgets(line, PATH_MAX, pipe) == NULL)
break;
- alpm_logaction("%s", line);
+ alpm_logaction(handle, "%s", line);
EVENT(handle->trans, PM_TRANS_EVT_SCRIPTLET_INFO, line, NULL);
}
fclose(pipe);
@@ -505,7 +507,7 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
while(waitpid(pid, &status, 0) == -1) {
if(errno != EINTR) {
- _alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"), strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("call to waitpid failed (%s)\n"), strerror(errno));
retval = 1;
goto cleanup;
}
@@ -513,14 +515,14 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
/* report error from above after the child has exited */
if(retval != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not open pipe (%s)\n"), strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not open pipe (%s)\n"), strerror(errno));
goto cleanup;
}
/* check the return status, make sure it is 0 (success) */
if(WIFEXITED(status)) {
- _alpm_log(PM_LOG_DEBUG, "call to waitpid succeeded\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "call to waitpid succeeded\n");
if(WEXITSTATUS(status) != 0) {
- _alpm_log(PM_LOG_ERROR, _("command failed to execute correctly\n"));
+ _alpm_log(handle, PM_LOG_ERROR, _("command failed to execute correctly\n"));
retval = 1;
}
}
@@ -528,24 +530,24 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
cleanup:
if(restore_cwd && chdir(cwd) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
+ _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
}
return retval;
}
-int _alpm_ldconfig(const char *root)
+int _alpm_ldconfig(pmhandle_t *handle)
{
char line[PATH_MAX];
- _alpm_log(PM_LOG_DEBUG, "running ldconfig\n");
+ _alpm_log(handle, PM_LOG_DEBUG, "running ldconfig\n");
- snprintf(line, PATH_MAX, "%setc/ld.so.conf", root);
+ snprintf(line, PATH_MAX, "%setc/ld.so.conf", handle->root);
if(access(line, F_OK) == 0) {
- snprintf(line, PATH_MAX, "%ssbin/ldconfig", root);
+ snprintf(line, PATH_MAX, "%ssbin/ldconfig", handle->root);
if(access(line, X_OK) == 0) {
char *argv[] = { "ldconfig", NULL };
- _alpm_run_chroot(root, "/sbin/ldconfig", argv);
+ _alpm_run_chroot(handle, "/sbin/ldconfig", argv);
}
}
@@ -560,10 +562,11 @@ int _alpm_str_cmp(const void *s1, const void *s2)
}
/** Find a filename in a registered alpm cachedir.
+ * @param handle the context handle
* @param filename name of file to find
* @return malloced path of file, NULL if not found
*/
-char *_alpm_filecache_find(const char* filename)
+char *_alpm_filecache_find(pmhandle_t *handle, const char *filename)
{
char path[PATH_MAX];
char *retpath;
@@ -571,52 +574,56 @@ char *_alpm_filecache_find(const char* filename)
struct stat buf;
/* Loop through the cache dirs until we find a matching file */
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = alpm_option_get_cachedirs(handle); i; i = alpm_list_next(i)) {
snprintf(path, PATH_MAX, "%s%s", (char *)alpm_list_getdata(i),
filename);
if(stat(path, &buf) == 0 && S_ISREG(buf.st_mode)) {
retpath = strdup(path);
- _alpm_log(PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
+ _alpm_log(handle, PM_LOG_DEBUG, "found cached pkg: %s\n", retpath);
return retpath;
}
}
/* package wasn't found in any cachedir */
- RET_ERR(PM_ERR_PKG_NOT_FOUND, NULL);
+ return NULL;
}
/** Check the alpm cachedirs for existance and find a writable one.
* If no valid cache directory can be found, use /tmp.
+ * @param handle the context handle
* @return pointer to a writable cache directory.
*/
-const char *_alpm_filecache_setup(void)
+const char *_alpm_filecache_setup(pmhandle_t *handle)
{
struct stat buf;
alpm_list_t *i, *tmp;
char *cachedir;
/* Loop through the cache dirs until we find a writeable dir */
- for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
+ for(i = alpm_option_get_cachedirs(handle); i; i = alpm_list_next(i)) {
cachedir = alpm_list_getdata(i);
if(stat(cachedir, &buf) != 0) {
/* cache directory does not exist.... try creating it */
- _alpm_log(PM_LOG_WARNING, _("no %s cache exists, creating...\n"),
+ _alpm_log(handle, PM_LOG_WARNING, _("no %s cache exists, creating...\n"),
cachedir);
if(_alpm_makepath(cachedir) == 0) {
- _alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
+ _alpm_log(handle, PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
return cachedir;
}
} else if(S_ISDIR(buf.st_mode) && (buf.st_mode & S_IWUSR)) {
- _alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
+ _alpm_log(handle, PM_LOG_DEBUG, "using cachedir: %s\n", cachedir);
return cachedir;
+ } else {
+ _alpm_log(handle, PM_LOG_DEBUG, "skipping cachedir: %s\n", cachedir);
}
}
/* we didn't find a valid cache directory. use /tmp. */
- tmp = alpm_list_add(NULL, strdup("/tmp/"));
- alpm_option_set_cachedirs(tmp);
- _alpm_log(PM_LOG_DEBUG, "using cachedir: %s", "/tmp/\n");
- _alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
- return alpm_list_getdata(tmp);
+ tmp = alpm_list_add(NULL, "/tmp/");
+ alpm_option_set_cachedirs(handle, tmp);
+ alpm_list_free(tmp);
+ _alpm_log(handle, PM_LOG_DEBUG, "using cachedir: %s\n", "/tmp/");
+ _alpm_log(handle, PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
+ return "/tmp/";
}
/** lstat wrapper that treats /path/dirsymlink/ the same as /path/dirsymlink.
@@ -629,17 +636,18 @@ const char *_alpm_filecache_setup(void)
int _alpm_lstat(const char *path, struct stat *buf)
{
int ret;
- char *newpath = strdup(path);
- size_t len = strlen(newpath);
+ size_t len = strlen(path);
/* strip the trailing slash if one exists */
- if(len != 0 && newpath[len - 1] == '/') {
- newpath[len - 1] = '\0';
+ if(len != 0 && path[len - 1] == '/') {
+ char *newpath = strdup(path);
+ newpath[len - 1] = '\0';
+ ret = lstat(newpath, buf);
+ free(newpath);
+ } else {
+ ret = lstat(path, buf);
}
- ret = lstat(newpath, buf);
-
- FREE(newpath);
return ret;
}
@@ -651,7 +659,7 @@ static int md5_file(const char *path, unsigned char output[16])
MD5_CTX ctx;
unsigned char *buf;
- CALLOC(buf, 8192, sizeof(unsigned char), RET_ERR(PM_ERR_MEMORY, 1));
+ CALLOC(buf, 8192, sizeof(unsigned char), return 1);
if((f = fopen(path, "rb")) == NULL) {
free(buf);
@@ -690,8 +698,6 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
char *md5sum;
int ret, i;
- ALPM_LOG_FUNC;
-
ASSERT(filename != NULL, return NULL);
/* allocate 32 chars plus 1 for null */
@@ -700,7 +706,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
ret = md5_file(filename, output);
if(ret > 0) {
- RET_ERR(PM_ERR_NOT_A_FILE, NULL);
+ return NULL;
}
/* Convert the result to something readable */
@@ -710,7 +716,6 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
}
md5sum[32] = '\0';
- _alpm_log(PM_LOG_DEBUG, "md5(%s) = %s\n", filename, md5sum);
return md5sum;
}
@@ -775,20 +780,19 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
/* allocate our buffer, or ensure our existing one is big enough */
if(!b->line) {
/* set the initial buffer to the read block_size */
- CALLOC(b->line, b->block_size + 1, sizeof(char),
- RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(b->line, b->block_size + 1, sizeof(char), return ENOMEM);
b->line_size = b->block_size + 1;
b->line_offset = b->line;
} else {
size_t needed = (size_t)((b->line_offset - b->line)
+ (i - b->block_offset) + 1);
if(needed > b->max_line_size) {
- RET_ERR(PM_ERR_MEMORY, -1);
+ return ERANGE;
}
if(needed > b->line_size) {
/* need to realloc + copy data to fit total length */
char *new;
- CALLOC(new, needed, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
+ CALLOC(new, needed, sizeof(char), return ENOMEM);
memcpy(new, b->line, b->line_size);
b->line_size = needed;
b->line_offset = new + (b->line_offset - b->line);
@@ -855,13 +859,12 @@ int _alpm_splitname(const char *target, pmpkg_t *pkg)
}
/* version actually points to the dash, so need to increment 1 and account
* for potential end character */
- STRNDUP(pkg->version, version + 1, end - version - 1,
- RET_ERR(PM_ERR_MEMORY, -1));
+ STRNDUP(pkg->version, version + 1, end - version - 1, return -1);
if(pkg->name) {
FREE(pkg->name);
}
- STRNDUP(pkg->name, target, version - target, RET_ERR(PM_ERR_MEMORY, -1));
+ STRNDUP(pkg->name, target, version - target, return -1);
pkg->name_hash = _alpm_hash_sdbm(pkg->name);
return 0;
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 776cee4d..e5fefe9e 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -27,7 +27,9 @@
#include "config.h"
#include "alpm_list.h"
+#include "alpm.h"
#include "package.h" /* pmpkg_t */
+#include "handle.h" /* pmhandle_t */
#include <stdio.h>
#include <string.h>
@@ -47,7 +49,7 @@
#define _(s) s
#endif
-#define ALLOC_FAIL(s) do { _alpm_log(PM_LOG_ERROR, _("alloc failure: could not allocate %zd bytes\n"), s); } while(0)
+#define ALLOC_FAIL(s) do { fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", s); } while(0)
#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
@@ -59,12 +61,12 @@
#define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)
-#define RET_ERR_VOID(err) do { pm_errno = (err); \
- _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
+#define RET_ERR_VOID(handle, err) do { (handle)->pm_errno = (err); \
+ _alpm_log(handle, PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(err)); \
return; } while(0)
-#define RET_ERR(err, ret) do { pm_errno = (err); \
- _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
+#define RET_ERR(handle, err, ret) do { (handle)->pm_errno = (err); \
+ _alpm_log(handle, PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(err)); \
return (ret); } while(0)
#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
@@ -89,15 +91,17 @@ int _alpm_makepath(const char *path);
int _alpm_makepath_mode(const char *path, mode_t mode);
int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtrim(char *str);
-int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn);
-int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst);
+int _alpm_unpack_single(pmhandle_t *handle, const char *archive,
+ const char *prefix, const char *filename);
+int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix,
+ alpm_list_t *list, int breakfirst);
int _alpm_rmrf(const char *path);
-int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
-int _alpm_run_chroot(const char *root, const char *path, char *const argv[]);
-int _alpm_ldconfig(const char *root);
+int _alpm_logaction(pmhandle_t *handle, const char *fmt, va_list args);
+int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[]);
+int _alpm_ldconfig(pmhandle_t *handle);
int _alpm_str_cmp(const void *s1, const void *s2);
-char *_alpm_filecache_find(const char *filename);
-const char *_alpm_filecache_setup(void);
+char *_alpm_filecache_find(pmhandle_t *handle, const char *filename);
+const char *_alpm_filecache_setup(pmhandle_t *handle);
int _alpm_lstat(const char *path, struct stat *buf);
int _alpm_test_md5sum(const char *filepath, const char *md5sum);
int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b);