[pacman-dev] [PATCH 00/13] global handle removal patch series
This is a bitch of a diffstat, unfortunately, and the patches aren't all that fun to look through. I have it pushed to my repo as alpm-cleanups if you'd rather grab it there. The bright side is it should successfully build and test after each patch as long as they are applied in the order sent here (or in my repo). Comments/suggestion/feedback welcome. Once these are applied, I think our API makes a lot more sense from a consumer standpoint as we have a single object, tracked by the "client", tracking all state in the library rather than the state being held in a global variable in the backend library. This patch series (and the previous one sent and now applied) makes it *much* easier for the next few patches, which will ensure DBs are signature-checked and verified at the right time, and at a time all clients expect them to be checked so error codes can be checked. Look at the bright side- the overall line differential is at least negative! -Dan Dan McGee (13): Require handle argument to alpm_logaction() Require handle argument to all alpm_option_(get|set)_*() methods Require handle argument to all alpm_trans_*() methods Require handle for alpm_db_register_sync() Require handle for alpm_sync_sysupgrade() Require handle for alpm_pkg_load() Require handle for alpm_checkconflicts() Add handle argument to two more alpm methods Require handle for alpm_find_grp_pkgs() Move pm_errno onto the handle Switch all logging to use handle directly Remove global handle variable Always pass data to trans_commit() lib/libalpm/add.c | 173 +++++++++++++++--------------- lib/libalpm/alpm.c | 14 +-- lib/libalpm/alpm.h | 159 +++++++++++++++------------- lib/libalpm/be_local.c | 77 ++++++------- lib/libalpm/be_package.c | 92 ++++++++-------- lib/libalpm/be_sync.c | 88 ++++++++-------- lib/libalpm/conflict.c | 151 ++++++++++++++------------ lib/libalpm/conflict.h | 3 +- lib/libalpm/db.c | 124 ++++++++++----------- lib/libalpm/delta.c | 31 +++--- lib/libalpm/delta.h | 2 +- lib/libalpm/deps.c | 117 +++++++++----------- lib/libalpm/deps.h | 4 +- lib/libalpm/diskspace.c | 38 ++++---- lib/libalpm/dload.c | 61 +++++------ lib/libalpm/dload.h | 3 +- lib/libalpm/error.c | 16 +--- lib/libalpm/graph.c | 2 +- lib/libalpm/group.c | 9 +- lib/libalpm/handle.c | 269 ++++++++++++++++++---------------------------- lib/libalpm/handle.h | 3 + lib/libalpm/log.c | 23 ++--- lib/libalpm/log.h | 3 +- lib/libalpm/package.c | 38 ++++--- lib/libalpm/package.h | 8 +- lib/libalpm/pkghash.c | 13 +-- lib/libalpm/remove.c | 118 +++++++++++---------- lib/libalpm/signing.c | 83 ++++++++------- lib/libalpm/signing.h | 3 +- lib/libalpm/sync.c | 192 +++++++++++++++++---------------- lib/libalpm/trans.c | 115 +++++++++----------- lib/libalpm/trans.h | 1 - lib/libalpm/util.c | 127 +++++++++++----------- lib/libalpm/util.h | 23 +++-- src/pacman/callback.c | 6 +- src/pacman/conf.c | 54 +++++----- src/pacman/database.c | 4 +- src/pacman/deptest.c | 3 +- src/pacman/package.c | 5 +- src/pacman/pacman.c | 18 ++-- src/pacman/query.c | 21 ++-- src/pacman/remove.c | 27 +++-- src/pacman/sync.c | 78 +++++++------ src/pacman/upgrade.c | 34 +++--- src/pacman/util.c | 22 ++-- src/util/cleanupdelta.c | 6 +- src/util/pactree.c | 34 ++---- src/util/testdb.c | 19 ++-- src/util/testpkg.c | 9 +- 49 files changed, 1227 insertions(+), 1296 deletions(-) -- 1.7.5.2
This is the first in a series of patches to update the API to remove the implicit global handle variable. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/add.c | 34 +++++++++++++++++----------------- lib/libalpm/alpm.h | 2 +- lib/libalpm/log.c | 4 ++-- lib/libalpm/remove.c | 2 +- lib/libalpm/trans.c | 2 +- lib/libalpm/util.c | 14 +++++++------- lib/libalpm/util.h | 2 +- src/pacman/callback.c | 6 +++--- src/pacman/pacman.c | 2 +- src/pacman/sync.c | 4 ++-- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 59d539c..da2ecdc 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -103,7 +103,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *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; @@ -121,7 +121,7 @@ static int perform_extraction(struct archive *archive, } else if(ret != ARCHIVE_OK) { _alpm_log(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; } @@ -169,7 +169,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, if(alpm_list_find_str(handle->noextract, entryname)) { _alpm_log(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; @@ -209,7 +209,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, _alpm_log(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); } @@ -284,7 +284,7 @@ static int extract_single_file(pmhandle_t *handle, 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); @@ -331,7 +331,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, if(rename(filename, newpath)) { _alpm_log(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 { @@ -339,12 +339,12 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, if(rename(checkfile, filename)) { _alpm_log(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_logaction(handle, "warning: %s saved as %s\n", filename, newpath); } } } else { @@ -363,7 +363,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, if(rename(checkfile, filename)) { _alpm_log(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++; } @@ -393,12 +393,12 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, if(rename(checkfile, newpath)) { _alpm_log(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"), filename, newpath); - alpm_logaction("warning: %s installed as %s\n", + alpm_logaction(handle, "warning: %s installed as %s\n", filename, newpath); } } @@ -415,7 +415,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, /* 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_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); @@ -428,7 +428,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, 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); @@ -532,7 +532,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, /* 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; ret = -1; @@ -632,12 +632,12 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, if(is_upgrade) { _alpm_log(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"), newpkg->name); - alpm_logaction("error: problem occurred while installing %s\n", + alpm_logaction(handle, "error: problem occurred while installing %s\n", newpkg->name); } } @@ -652,7 +652,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, if(_alpm_local_db_write(db, newpkg, INFRQ_ALL)) { _alpm_log(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; ret = -1; diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index ee55d0b..f46c154 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -100,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 diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 20d1ec3..30d1d6f 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -42,7 +42,7 @@ extern pmhandle_t *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; @@ -67,7 +67,7 @@ int SYMEXPORT alpm_logaction(const char *fmt, ...) } 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. diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 27305ae..0682a35 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -261,7 +261,7 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename, 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_logaction(handle, "warning: %s saved as %s\n", file, newpath); return; } } diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 58bcc38..a7d762e 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -292,7 +292,7 @@ int SYMEXPORT alpm_trans_release(void) 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_logaction(handle, "warning: could not remove lock file %s\n", alpm_option_get_lockfile()); } } diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 6f0763d..c6dba5d 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -385,11 +385,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; @@ -398,7 +398,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; @@ -406,11 +406,11 @@ 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; @@ -496,7 +496,7 @@ int _alpm_run_chroot(pmhandle_t *handle, 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); diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index c1a92a0..86968ae 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -93,7 +93,7 @@ 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_rmrf(const char *path); -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 _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); diff --git a/src/pacman/callback.c b/src/pacman/callback.c index f1c314f..a96f858 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -176,7 +176,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_ADD_DONE: - alpm_logaction("installed %s (%s)\n", + alpm_logaction(config->handle, "installed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); display_optdepends(data1); @@ -187,7 +187,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_REMOVE_DONE: - alpm_logaction("removed %s (%s)\n", + alpm_logaction(config->handle, "removed %s (%s)\n", alpm_pkg_get_name(data1), alpm_pkg_get_version(data1)); break; @@ -197,7 +197,7 @@ void cb_trans_evt(pmtransevt_t event, void *data1, void *data2) } break; case PM_TRANS_EVT_UPGRADE_DONE: - alpm_logaction("upgraded %s (%s -> %s)\n", + alpm_logaction(config->handle, "upgraded %s (%s -> %s)\n", (char *)alpm_pkg_get_name(data1), (char *)alpm_pkg_get_version(data2), (char *)alpm_pkg_get_version(data1)); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 4b54eb3..544a26f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -735,7 +735,7 @@ static void cl_to_log(int argc, char* argv[]) *p++ = ' '; } strcpy(p, argv[i]); - alpm_logaction("Running '%s'\n", cl_text); + alpm_logaction(config->handle, "Running '%s'\n", cl_text); free(cl_text); } diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 884504f..ffc30ce 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -757,7 +757,7 @@ static int sync_trans(alpm_list_t *targets) if(config->op_s_upgrade) { printf(_(":: Starting full system upgrade...\n")); - alpm_logaction("starting full system upgrade\n"); + alpm_logaction(config->handle, "starting full system upgrade\n"); if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); retval = 1; @@ -919,7 +919,7 @@ int pacman_sync(alpm_list_t *targets) if(config->op_s_sync) { /* grab a fresh package list */ printf(_(":: Synchronizing package databases...\n")); - alpm_logaction("synchronizing package lists\n"); + alpm_logaction(config->handle, "synchronizing package lists\n"); if(!sync_synctree(config->op_s_sync, sync_dbs)) { return 1; } -- 1.7.5.2
This requires a lot of line changes, but not many functional changes as more often than not our handle variable is already available in some fashion. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 97 +++++++++--------- lib/libalpm/be_local.c | 2 +- lib/libalpm/be_package.c | 2 +- lib/libalpm/be_sync.c | 2 +- lib/libalpm/db.c | 2 +- lib/libalpm/delta.c | 11 +- lib/libalpm/delta.h | 2 +- lib/libalpm/diskspace.c | 2 +- lib/libalpm/dload.c | 6 +- lib/libalpm/handle.c | 249 ++++++++++++++++++---------------------------- lib/libalpm/log.c | 2 +- lib/libalpm/package.c | 4 +- lib/libalpm/signing.c | 19 ++-- lib/libalpm/signing.h | 3 +- lib/libalpm/sync.c | 28 +++--- lib/libalpm/trans.c | 6 +- lib/libalpm/util.c | 12 ++- lib/libalpm/util.h | 4 +- src/pacman/conf.c | 42 ++++---- src/pacman/database.c | 2 +- src/pacman/deptest.c | 3 +- src/pacman/package.c | 5 +- src/pacman/pacman.c | 12 +- src/pacman/query.c | 19 ++-- src/pacman/remove.c | 2 +- src/pacman/sync.c | 28 +++--- src/pacman/upgrade.c | 4 +- src/pacman/util.c | 7 +- src/util/cleanupdelta.c | 2 +- src/util/pactree.c | 6 +- src/util/testdb.c | 11 +-- src/util/testpkg.c | 2 +- 32 files changed, 274 insertions(+), 324 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index f46c154..26ed1e5 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -127,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 @@ -138,67 +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(void); +const char *alpm_option_get_root(pmhandle_t *handle); /** Returns the path to the database directory. Read-only. */ -const char *alpm_option_get_dbpath(void); +const char *alpm_option_get_dbpath(pmhandle_t *handle); /** Get the name of the database lock file. Read-only. */ -const char *alpm_option_get_lockfile(void); +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); +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. @@ -207,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. @@ -218,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. @@ -229,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); /** @} */ @@ -262,14 +263,14 @@ 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. * @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 treename the name of the sync repository diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 3a0887d..42ddaf5 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -205,7 +205,7 @@ static void *_cache_changelog_open(pmpkg_t *pkg) { 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)); diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index c89365a..0545167 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -270,7 +270,7 @@ pmpkg_t *_alpm_pkg_load_internal(const char *pkgfile, int full, _alpm_log(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); + 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); diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index aeba86f..c8d3758 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -91,7 +91,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) ASSERT(db != NULL && db != 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(); + dbpath = alpm_option_get_dbpath(db->handle); len = strlen(dbpath) + 6; MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1)); sprintf(syncpath, "%s%s", dbpath, "sync/"); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index fda8428..6114334 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -360,7 +360,7 @@ 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); diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index cd23487..645c7ba 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -111,7 +111,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 +121,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 +130,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 +211,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,7 +219,7 @@ 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; @@ -233,7 +234,7 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas, _alpm_log(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); diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h index bd196ba..d7725f5 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/diskspace.c b/lib/libalpm/diskspace.c index c6c0b98..7be5464 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -226,7 +226,7 @@ static int calculate_installed_size(pmhandle_t *handle, /* 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); diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 8591c9d..0ba3bc1 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -332,7 +332,7 @@ int _alpm_download(const char *url, const char *localpath, } /** 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; @@ -341,7 +341,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *url) 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); @@ -374,7 +374,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *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/handle.c b/lib/libalpm/handle.c index 80ad560..0e50cbd 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -90,210 +90,150 @@ void _alpm_handle_free(pmhandle_t *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; } @@ -344,11 +284,11 @@ enum _pmerrno_t _alpm_set_directory_option(const char *value, 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; - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + ASSERT(handle != NULL, return -1); if(!cachedir) { pm_errno = PM_ERR_WRONG_ARGS; return -1; @@ -362,15 +302,15 @@ int SYMEXPORT alpm_option_add_cachedir(const char *cachedir) 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) { alpm_list_t *i; - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + ASSERT(handle != NULL, return -1); if(handle->cachedirs) { FREELIST(handle->cachedirs); } for(i = cachedirs; i; i = i->next) { - int ret = alpm_option_add_cachedir(i->data); + int ret = alpm_option_add_cachedir(handle, i->data); if(ret) { return ret; } @@ -378,12 +318,12 @@ int SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs) 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] != '/') { @@ -401,11 +341,11 @@ 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; - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + ASSERT(handle != NULL, return -1); if(!logfile) { pm_errno = PM_ERR_WRONG_ARGS; return -1; @@ -426,8 +366,9 @@ int SYMEXPORT alpm_option_set_logfile(const char *logfile) return 0; } -int SYMEXPORT alpm_option_set_signaturedir(const char *signaturedir) +int SYMEXPORT alpm_option_set_signaturedir(pmhandle_t *handle, const char *signaturedir) { + ASSERT(handle != NULL, return -1); if(!signaturedir) { pm_errno = PM_ERR_WRONG_ARGS; return -1; @@ -442,32 +383,32 @@ int SYMEXPORT alpm_option_set_signaturedir(const char *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 = 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); @@ -476,25 +417,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 = 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); @@ -503,25 +444,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 = 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); @@ -530,25 +471,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 = 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); @@ -557,9 +498,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); @@ -569,31 +510,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(handle != NULL, return -1); ASSERT(level != PM_PGP_VERIFY_UNKNOWN, RET_ERR(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/log.c b/lib/libalpm/log.c index 30d1d6f..023bfc9 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -89,7 +89,7 @@ int SYMEXPORT alpm_logaction(pmhandle_t *handle, const char *fmt, ...) void _alpm_log(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/package.c b/lib/libalpm/package.c index d6edca1..67d31c3 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -65,7 +65,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg) /* We only inspect packages from sync repositories */ ASSERT(pkg->origin == PKG_FROM_SYNCDB, RET_ERR(PM_ERR_PKG_INVALID, -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)); @@ -341,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 diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index f6a5a1a..6ce56e5 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -104,7 +104,7 @@ 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; @@ -116,7 +116,7 @@ static int gpgme_init(void) return 0; } - if(!alpm_option_get_signaturedir()) { + if(!alpm_option_get_signaturedir(handle)) { RET_ERR(PM_ERR_SIG_MISSINGDIR, 1); } @@ -142,7 +142,7 @@ 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(); @@ -194,12 +194,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; @@ -226,7 +228,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig) } } - if(gpgme_init()) { + if(gpgme_init(handle)) { /* pm_errno was set in gpgme_init() */ return -1; } @@ -372,7 +374,7 @@ pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db) 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); } } @@ -385,7 +387,8 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(pmpkg_t *pkg) { 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); } /** @@ -397,7 +400,7 @@ int SYMEXPORT alpm_db_check_pgp_signature(pmdb_t *db) { 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 8d8c164..fdf81fc 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 7a33bc9..41f9f99 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -265,7 +265,7 @@ 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); + fpath = _alpm_filecache_find(newpkg->handle, fname); if(fpath) { FREE(fpath); @@ -274,7 +274,7 @@ 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); @@ -577,15 +577,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; @@ -602,10 +603,10 @@ 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; @@ -686,11 +687,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; @@ -702,7 +704,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) { @@ -719,7 +721,7 @@ static int validate_deltas(pmtrans_t *trans, alpm_list_t *deltas, /* 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; } @@ -731,7 +733,7 @@ static int download_files(pmhandle_t *handle, alpm_list_t **deltas) alpm_list_t *files = NULL; int errors = 0; - cachedir = _alpm_filecache_setup(); + cachedir = _alpm_filecache_setup(handle); handle->trans->state = STATE_DOWNLOADING; /* Total progress - figure out the total download size if required to @@ -844,7 +846,7 @@ int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data) return -1; } - if(validate_deltas(trans, deltas, data)) { + if(validate_deltas(handle, deltas, data)) { alpm_list_free(deltas); return -1; } @@ -870,7 +872,7 @@ int _alpm_sync_commit(pmhandle_t *handle, 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); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index a7d762e..59f6aec 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -149,7 +149,7 @@ static alpm_list_t *check_arch(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; } @@ -291,9 +291,9 @@ int SYMEXPORT alpm_trans_release(void) if(!nolock_flag) { if(remove_lock(handle)) { _alpm_log(PM_LOG_WARNING, _("could not remove lock file %s\n"), - alpm_option_get_lockfile()); + alpm_option_get_lockfile(handle)); alpm_logaction(handle, "warning: could not remove lock file %s\n", - alpm_option_get_lockfile()); + alpm_option_get_lockfile(handle)); } } diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index c6dba5d..174af8c 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -559,10 +559,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; @@ -570,7 +571,7 @@ 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)) { @@ -585,16 +586,17 @@ char *_alpm_filecache_find(const char* filename) /** 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 */ @@ -614,7 +616,7 @@ const char *_alpm_filecache_setup(void) /* we didn't find a valid cache directory. use /tmp. */ tmp = alpm_list_add(NULL, "/tmp/"); - alpm_option_set_cachedirs(tmp); + alpm_option_set_cachedirs(handle, tmp); alpm_list_free(tmp); _alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", "/tmp/"); _alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n")); diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 86968ae..839b802 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -97,8 +97,8 @@ 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); diff --git a/src/pacman/conf.c b/src/pacman/conf.c index b16be04..a9ff14c 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -421,6 +421,7 @@ static int setup_libalpm(void) { int ret = 0; enum _pmerrno_t err; + pmhandle_t *handle; pm_printf(PM_LOG_DEBUG, "setup_libalpm called\n"); @@ -444,18 +445,19 @@ static int setup_libalpm(void) } /* initialize library */ - config->handle = alpm_initialize(config->rootdir, config->dbpath, &err); - if(!config->handle) { + handle = alpm_initialize(config->rootdir, config->dbpath, &err); + if(!handle) { pm_printf(PM_LOG_ERROR, _("failed to initialize alpm library (%s)\n"), alpm_strerror(err)); return -1; } + config->handle = handle; - alpm_option_set_logcb(cb_log); - alpm_option_set_dlcb(cb_dl_progress); + alpm_option_set_logcb(handle, cb_log); + alpm_option_set_dlcb(handle, cb_dl_progress); config->logfile = config->logfile ? config->logfile : strdup(LOGFILE); - ret = alpm_option_set_logfile(config->logfile); + ret = alpm_option_set_logfile(handle, config->logfile); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), config->logfile, alpm_strerrorlast()); @@ -465,7 +467,7 @@ static int setup_libalpm(void) /* Set GnuPG's home directory. This is not relative to rootdir, even if * rootdir is defined. Reasoning: gpgdir contains configuration data. */ config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR); - ret = alpm_option_set_signaturedir(config->gpgdir); + ret = alpm_option_set_signaturedir(handle, config->gpgdir); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), config->gpgdir, alpm_strerrorlast()); @@ -474,33 +476,33 @@ static int setup_libalpm(void) /* add a default cachedir if one wasn't specified */ if(config->cachedirs == NULL) { - alpm_option_add_cachedir(CACHEDIR); + alpm_option_add_cachedir(handle, CACHEDIR); } else { - alpm_option_set_cachedirs(config->cachedirs); + alpm_option_set_cachedirs(handle, config->cachedirs); } if(config->sigverify != PM_PGP_VERIFY_UNKNOWN) { - alpm_option_set_default_sigverify(config->sigverify); + alpm_option_set_default_sigverify(handle, config->sigverify); } if(config->xfercommand) { - alpm_option_set_fetchcb(download_with_xfercommand); + alpm_option_set_fetchcb(handle, download_with_xfercommand); } if(config->totaldownload) { - alpm_option_set_totaldlcb(cb_dl_total); + alpm_option_set_totaldlcb(handle, cb_dl_total); } - alpm_option_set_arch(config->arch); - alpm_option_set_checkspace(config->checkspace); - alpm_option_set_usesyslog(config->usesyslog); - alpm_option_set_usedelta(config->usedelta); - alpm_option_set_default_sigverify(config->sigverify); + alpm_option_set_arch(handle, config->arch); + alpm_option_set_checkspace(handle, config->checkspace); + alpm_option_set_usesyslog(handle, config->usesyslog); + alpm_option_set_usedelta(handle, config->usedelta); + alpm_option_set_default_sigverify(handle, config->sigverify); - alpm_option_set_ignorepkgs(config->ignorepkg); - alpm_option_set_ignoregrps(config->ignoregrp); - alpm_option_set_noupgrades(config->noupgrade); - alpm_option_set_noextracts(config->noextract); + alpm_option_set_ignorepkgs(handle, config->ignorepkg); + alpm_option_set_ignoregrps(handle, config->ignoregrp); + alpm_option_set_noupgrades(handle, config->noupgrade); + alpm_option_set_noextracts(handle, config->noextract); return 0; } diff --git a/src/pacman/database.c b/src/pacman/database.c index 123f72d..33cd49e 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -63,7 +63,7 @@ int pacman_database(alpm_list_t *targets) return 1; } - db_local = alpm_option_get_localdb(); + db_local = alpm_option_get_localdb(config->handle); for(i = targets; i; i = alpm_list_next(i)) { char *pkgname = i->data; if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) { diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 19e4da4..99abd72 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -27,12 +27,13 @@ /* pacman */ #include "pacman.h" +#include "conf.h" int pacman_deptest(alpm_list_t *targets) { alpm_list_t *i; alpm_list_t *deps = NULL; - pmdb_t *localdb = alpm_option_get_localdb(); + pmdb_t *localdb = alpm_option_get_localdb(config->handle); for(i = targets; i; i = alpm_list_next(i)) { char *target = alpm_list_getdata(i); diff --git a/src/pacman/package.c b/src/pacman/package.c index e256dda..9cdb487 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -33,6 +33,7 @@ /* pacman */ #include "package.h" #include "util.h" +#include "conf.h" #define CLBUF_SIZE 4096 @@ -194,7 +195,7 @@ static const char *get_backup_file_status(const char *root, void dump_pkg_backups(pmpkg_t *pkg) { alpm_list_t *i; - const char *root = alpm_option_get_root(); + const char *root = alpm_option_get_root(config->handle); printf(_("Backup Files:\n")); if(alpm_pkg_get_backup(pkg)) { /* package has backup files, so print them */ @@ -227,7 +228,7 @@ void dump_pkg_files(pmpkg_t *pkg, int quiet) pkgname = alpm_pkg_get_name(pkg); pkgfiles = alpm_pkg_get_files(pkg); - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); for(i = pkgfiles; i; i = alpm_list_next(i)) { filestr = alpm_list_getdata(i); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 544a26f..9e283b5 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -875,17 +875,17 @@ int main(int argc, char *argv[]) if(config->verbose > 0) { alpm_list_t *i; - printf("Root : %s\n", alpm_option_get_root()); + printf("Root : %s\n", alpm_option_get_root(config->handle)); printf("Conf File : %s\n", config->configfile); - printf("DB Path : %s\n", alpm_option_get_dbpath()); + printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle)); printf("Cache Dirs: "); - for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) { + for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) { printf("%s ", (char *)alpm_list_getdata(i)); } printf("\n"); - printf("Lock File : %s\n", alpm_option_get_lockfile()); - printf("Log File : %s\n", alpm_option_get_logfile()); - printf("GPG Dir : %s\n", alpm_option_get_signaturedir()); + printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle)); + printf("Log File : %s\n", alpm_option_get_logfile(config->handle)); + printf("GPG Dir : %s\n", alpm_option_get_signaturedir(config->handle)); list_display("Targets :", pm_targets); } diff --git a/src/pacman/query.c b/src/pacman/query.c index d1105b4..d446534 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -124,12 +124,12 @@ static int query_fileowner(alpm_list_t *targets) /* Set up our root path buffer. We only need to copy the location of root in * once, then we can just overwrite whatever file was there on the previous * iteration. */ - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); strncpy(path, root, PATH_MAX - 1); append = path + strlen(path); max_length = PATH_MAX - (append - path) - 1; - db_local = alpm_option_get_localdb(); + db_local = alpm_option_get_localdb(config->handle); for(t = targets; t; t = alpm_list_next(t)) { char *filename, *dname, *rpath; @@ -240,7 +240,7 @@ static int query_search(alpm_list_t *targets) { alpm_list_t *i, *searchlist; int freelist; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); /* if we have a targets list, search for packages matching it */ if(targets) { @@ -299,7 +299,7 @@ static int query_group(alpm_list_t *targets) alpm_list_t *i, *j; char *grpname = NULL; int ret = 0; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); if(targets == NULL) { for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) { @@ -342,7 +342,7 @@ static int is_foreign(pmpkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); alpm_list_t *j; - alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); int match = 0; for(j = sync_dbs; j; j = alpm_list_next(j)) { @@ -390,7 +390,8 @@ static int filter(pmpkg_t *pkg) return 0; } /* check if this pkg is outdated */ - if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) { + if(config->op_q_upgrade && (alpm_sync_newversion(pkg, + alpm_option_get_syncdbs(config->handle)) == NULL)) { return 0; } return 1; @@ -406,7 +407,7 @@ static int check(pmpkg_t *pkg) size_t rootlen; char f[PATH_MAX]; - root = alpm_option_get_root(); + root = alpm_option_get_root(config->handle); rootlen = strlen(root); if(rootlen + 1 > PATH_MAX) { /* we are in trouble here */ @@ -503,14 +504,14 @@ int pacman_query(alpm_list_t *targets) if(config->op_q_foreign) { /* ensure we have at least one valid sync db set up */ - alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) { pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n")); return 1; } } - db_local = alpm_option_get_localdb(); + db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 094a43b..46c595f 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -34,7 +34,7 @@ static int remove_target(const char *target) { pmpkg_t *info; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); alpm_list_t *p; if((info = alpm_db_get_pkg(db_local, target)) != NULL) { diff --git a/src/pacman/sync.c b/src/pacman/sync.c index ffc30ce..3876d92 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -51,7 +51,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) return 1; } - syncdbs = alpm_option_get_syncdbs(); + syncdbs = alpm_option_get_syncdbs(config->handle); rewinddir(dir); /* step through the directory one file at a time */ @@ -125,7 +125,7 @@ static int sync_cleandb_all(void) char newdbpath[PATH_MAX]; int ret = 0; - dbpath = alpm_option_get_dbpath(); + dbpath = alpm_option_get_dbpath(config->handle); printf(_("Database directory: %s\n"), dbpath); if(!yesno(_("Do you want to remove unused repositories?"))) { return 0; @@ -145,11 +145,12 @@ static int sync_cleandb_all(void) static int sync_cleancache(int level) { alpm_list_t *i; - alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); - pmdb_t *db_local = alpm_option_get_localdb(); + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); + alpm_list_t *cachedirs = alpm_option_get_cachedirs(config->handle); int ret = 0; - for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) { + for(i = cachedirs; i; i = alpm_list_next(i)) { printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i)); } @@ -177,7 +178,7 @@ static int sync_cleancache(int level) printf(_("removing all files from cache...\n")); } - for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) { + for(i = cachedirs; i; i = alpm_list_next(i)) { const char *cachedir = alpm_list_getdata(i); DIR *dir = opendir(cachedir); struct dirent *ent; @@ -335,7 +336,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) alpm_list_t *i, *j, *ret; int freelist; int found = 0; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); for(i = syncs; i; i = alpm_list_next(i)) { pmdb_t *db = alpm_list_getdata(i); @@ -532,7 +533,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) { alpm_list_t *i, *j, *ls = NULL; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); if(targets) { for(i = targets; i; i = alpm_list_next(i)) { @@ -587,7 +588,8 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) static alpm_list_t *syncfirst(void) { alpm_list_t *i, *res = NULL; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); + alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle); for(i = config->syncfirst; i; i = alpm_list_next(i)) { char *pkgname = alpm_list_getdata(i); @@ -596,7 +598,7 @@ static alpm_list_t *syncfirst(void) { continue; } - if(alpm_sync_newversion(pkg, alpm_option_get_syncdbs())) { + if(alpm_sync_newversion(pkg, syncdbs)) { res = alpm_list_add(res, strdup(pkgname)); } } @@ -607,7 +609,7 @@ static alpm_list_t *syncfirst(void) { static pmdb_t *get_db(const char *dbname) { alpm_list_t *i; - for(i = alpm_option_get_syncdbs(); i; i = i->next) { + for(i = alpm_option_get_syncdbs(config->handle); i; i = i->next) { pmdb_t *db = i->data; if(strcmp(alpm_db_get_name(db), dbname) == 0) { return db; @@ -726,7 +728,7 @@ static int process_target(char *target) alpm_list_free(dblist); } else { targname = targstring; - dblist = alpm_option_get_syncdbs(); + dblist = alpm_option_get_syncdbs(config->handle); ret = process_targname(dblist, targname); } cleanup: @@ -910,7 +912,7 @@ int pacman_sync(alpm_list_t *targets) } /* ensure we have at least one valid sync db set up */ - sync_dbs = alpm_option_get_syncdbs(); + sync_dbs = alpm_option_get_syncdbs(config->handle); if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) { pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n")); return 1; diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 0ffc94c..21d9411 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -42,7 +42,7 @@ int pacman_upgrade(alpm_list_t *targets) { alpm_list_t *i, *data = NULL; - pgp_verify_t check_sig = alpm_option_get_default_sigverify(); + pgp_verify_t check_sig = alpm_option_get_default_sigverify(config->handle); int retval = 0; if(targets == NULL) { @@ -54,7 +54,7 @@ int pacman_upgrade(alpm_list_t *targets) */ for(i = targets; i; i = alpm_list_next(i)) { if(strstr(i->data, "://")) { - char *str = alpm_fetch_pkgurl(i->data); + char *str = alpm_fetch_pkgurl(config->handle, i->data); if(str == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", (char *)i->data, alpm_strerrorlast()); diff --git a/src/pacman/util.c b/src/pacman/util.c index 3233f5f..8d174e9 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -64,7 +64,8 @@ int trans_init(pmtransflag_t flags) alpm_strerrorlast()); if(pm_errno == PM_ERR_HANDLE_LOCK) { fprintf(stderr, _(" if you're sure a package manager is not already\n" - " running, you can remove %s\n"), alpm_option_get_lockfile()); + " running, you can remove %s\n"), + alpm_option_get_lockfile(config->handle)); } else if(pm_errno == PM_ERR_DB_VERSION) { fprintf(stderr, _(" try running pacman-db-upgrade\n")); @@ -654,7 +655,7 @@ static alpm_list_t *create_verbose_row(pmpkg_t *pkg, int install) double size; const char *label; alpm_list_t *ret = NULL; - pmdb_t *ldb = alpm_option_get_localdb(); + pmdb_t *ldb = alpm_option_get_localdb(config->handle); /* a row consists of the package name, */ pm_asprintf(&str, "%s", alpm_pkg_get_name(pkg)); @@ -688,7 +689,7 @@ void display_targets(const alpm_list_t *pkgs, int install) const alpm_list_t *i; off_t isize = 0, rsize = 0, dlsize = 0; alpm_list_t *j, *lp, *header = NULL, *targets = NULL; - pmdb_t *db_local = alpm_option_get_localdb(); + pmdb_t *db_local = alpm_option_get_localdb(config->handle); if(!pkgs) { return; diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 9247c2c..83659cd 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(output_cb); + alpm_option_set_logcb(handle, output_cb); checkdbs(dbpath,dbnames); alpm_list_free(dbnames); diff --git a/src/util/pactree.c b/src/util/pactree.c index e2210ea..6c86942 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -97,11 +97,7 @@ static int alpm_local_init(void) return -1; } - db_local = alpm_option_get_localdb(); - if(!db_local) { - return 1; - } - + db_local = alpm_option_get_localdb(handle); return 0; } diff --git a/src/util/testdb.c b/src/util/testdb.c index 06c01f8..c7640d9 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -61,7 +61,7 @@ static int check_localdb_files(void) int ret = 0; DIR *dir; - dbpath = alpm_option_get_dbpath(); + dbpath = alpm_option_get_dbpath(handle); snprintf(path, sizeof(path), "%slocal", dbpath); if(!(dir = opendir(path))) { fprintf(stderr, "error : %s : %s\n", path, strerror(errno)); @@ -138,12 +138,7 @@ static int check_localdb(void) { return ret; } - db = alpm_option_get_localdb(); - if(db == NULL) { - fprintf(stderr, "error: could not register 'local' database (%s)\n", - alpm_strerrorlast()); - cleanup(EXIT_FAILURE); - } + db = alpm_option_get_localdb(handle); pkglist = alpm_db_get_pkgcache(db); ret += checkdeps(pkglist); ret += checkconflicts(pkglist); @@ -214,7 +209,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(output_cb); + alpm_option_set_logcb(handle, output_cb); if(!dbnames) { ret = check_localdb(); diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 20920ff..32011d4 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) } /* let us get log messages from libalpm */ - alpm_option_set_logcb(output_cb); + alpm_option_set_logcb(handle, output_cb); if(alpm_pkg_load(argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 || pkg == NULL) { -- 1.7.5.2
Begin enforcing the need to pass a handle. This allows us to remove one more extern handle declaration from the backend. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 26 +++++++++++++++++--------- lib/libalpm/deps.c | 6 +++--- lib/libalpm/trans.c | 23 ++++++++++------------- src/pacman/pacman.c | 4 ++-- src/pacman/remove.c | 8 ++++---- src/pacman/sync.c | 10 +++++----- src/pacman/upgrade.c | 12 ++++++------ src/pacman/util.c | 6 +++--- 8 files changed, 50 insertions(+), 45 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 26ed1e5..d63b987 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -794,54 +794,62 @@ 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 */ diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 62e8702..3292289 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -204,9 +204,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); } @@ -282,7 +282,7 @@ 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) { diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 59f6aec..f7fbd2b 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -43,9 +43,6 @@ #include "sync.h" #include "alpm.h" -/* global handle variable */ -extern pmhandle_t *handle; - /** \addtogroup alpm_trans Transaction Functions * @brief Functions to manipulate libalpm transactions * @{ @@ -99,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) { @@ -144,7 +141,7 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags, 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; @@ -170,7 +167,7 @@ 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; @@ -188,7 +185,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data) 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; @@ -214,7 +211,7 @@ 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; @@ -253,7 +250,7 @@ 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; @@ -271,7 +268,7 @@ 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; @@ -428,7 +425,7 @@ cleanup: 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)); @@ -437,7 +434,7 @@ int SYMEXPORT alpm_trans_get_flags() 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); @@ -446,7 +443,7 @@ alpm_list_t SYMEXPORT * alpm_trans_get_add() 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); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 9e283b5..db6b687 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -307,12 +307,12 @@ static void handler(int signum) } else if(signum == SIGINT) { const char *msg = "\nInterrupt signal received\n"; xwrite(err, msg, strlen(msg)); - if(alpm_trans_interrupt() == 0) { + if(alpm_trans_interrupt(config->handle) == 0) { /* a transaction is being interrupted, don't exit pacman yet. */ return; } /* no commiting transaction, we can release it now and then exit pacman */ - alpm_trans_release(); + alpm_trans_release(config->handle); /* output a newline to be sure we clear any line we may be on */ xwrite(out, "\n", 1); } diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 46c595f..b96687a 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -99,7 +99,7 @@ int pacman_remove(alpm_list_t *targets) } /* Step 2: prepare the transaction based on its type, targets and flags */ - if(alpm_trans_prepare(&data) == -1) { + if(alpm_trans_prepare(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), alpm_strerrorlast()); switch(pm_errno) { @@ -129,7 +129,7 @@ int pacman_remove(alpm_list_t *targets) /* Search for holdpkg in target list */ int holdpkg = 0; - for(i = alpm_trans_get_remove(); i; i = alpm_list_next(i)) { + for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) { pmpkg_t *pkg = alpm_list_getdata(i); if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) { pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"), @@ -143,7 +143,7 @@ int pacman_remove(alpm_list_t *targets) } /* Step 3: actually perform the removal */ - alpm_list_t *pkglist = alpm_trans_get_remove(); + alpm_list_t *pkglist = alpm_trans_get_remove(config->handle); if(pkglist == NULL) { printf(_(" there is nothing to do\n")); goto cleanup; /* we are done */ @@ -162,7 +162,7 @@ int pacman_remove(alpm_list_t *targets) goto cleanup; } - if(alpm_trans_commit(NULL) == -1) { + if(alpm_trans_commit(config->handle, NULL) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), alpm_strerrorlast()); retval = 1; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 3876d92..6f8508e 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -768,7 +768,7 @@ static int sync_trans(alpm_list_t *targets) } /* Step 2: "compute" the transaction based on targets and flags */ - if(alpm_trans_prepare(&data) == -1) { + if(alpm_trans_prepare(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), alpm_strerrorlast()); switch(pm_errno) { @@ -810,7 +810,7 @@ static int sync_trans(alpm_list_t *targets) goto cleanup; } - packages = alpm_trans_get_add(); + packages = alpm_trans_get_add(config->handle); if(packages == NULL) { /* nothing to do: just exit without complaining */ printf(_(" there is nothing to do\n")); @@ -823,8 +823,8 @@ static int sync_trans(alpm_list_t *targets) goto cleanup; } - display_targets(alpm_trans_get_remove(), 0); - display_targets(alpm_trans_get_add(), 1); + display_targets(alpm_trans_get_remove(config->handle), 0); + display_targets(alpm_trans_get_add(config->handle), 1); printf("\n"); int confirm; @@ -837,7 +837,7 @@ static int sync_trans(alpm_list_t *targets) goto cleanup; } - if(alpm_trans_commit(&data) == -1) { + if(alpm_trans_commit(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), alpm_strerrorlast()); switch(pm_errno) { diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 21d9411..ddb8a2e 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -93,7 +93,7 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 2: "compute" the transaction based on targets and flags */ /* TODO: No, compute nothing. This is stupid. */ - if(alpm_trans_prepare(&data) == -1) { + if(alpm_trans_prepare(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), alpm_strerrorlast()); switch(pm_errno) { @@ -142,20 +142,20 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 3: perform the installation */ if(config->print) { - print_packages(alpm_trans_get_add()); + print_packages(alpm_trans_get_add(config->handle)); trans_release(); return 0; } /* print targets and ask user confirmation */ - alpm_list_t *packages = alpm_trans_get_add(); + alpm_list_t *packages = alpm_trans_get_add(config->handle); if(packages == NULL) { /* we are done */ printf(_(" there is nothing to do\n")); trans_release(); return retval; } - display_targets(alpm_trans_get_remove(), 0); - display_targets(alpm_trans_get_add(), 1); + display_targets(alpm_trans_get_remove(config->handle), 0); + display_targets(alpm_trans_get_add(config->handle), 1); printf("\n"); int confirm = yesno(_("Proceed with installation?")); if(!confirm) { @@ -163,7 +163,7 @@ int pacman_upgrade(alpm_list_t *targets) return retval; } - if(alpm_trans_commit(&data) == -1) { + if(alpm_trans_commit(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), alpm_strerrorlast()); switch(pm_errno) { diff --git a/src/pacman/util.c b/src/pacman/util.c index 8d174e9..043b9d6 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -53,9 +53,9 @@ int trans_init(pmtransflag_t flags) { int ret; if(config->print) { - ret = alpm_trans_init(flags, NULL, NULL, NULL); + ret = alpm_trans_init(config->handle, flags, NULL, NULL, NULL); } else { - ret = alpm_trans_init(flags, cb_trans_evt, cb_trans_conv, + ret = alpm_trans_init(config->handle, flags, cb_trans_evt, cb_trans_conv, cb_trans_progress); } @@ -78,7 +78,7 @@ int trans_init(pmtransflag_t flags) int trans_release(void) { - if(alpm_trans_release() == -1) { + if(alpm_trans_release(config->handle) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), alpm_strerrorlast()); return -1; -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 4 +++- lib/libalpm/db.c | 5 +---- src/pacman/conf.c | 2 +- src/util/cleanupdelta.c | 2 +- src/util/testdb.c | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index d63b987..50ab06e 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -268,15 +268,17 @@ 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(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 diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 6114334..8156f2a 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -39,16 +39,13 @@ #include "package.h" #include "group.h" -/* global handle variable */ -extern pmhandle_t *handle; - /** \addtogroup alpm_databases Database Functions * @brief Functions to query and manipulate the database of libalpm * @{ */ /** 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) { /* Sanity checks */ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL)); diff --git a/src/pacman/conf.c b/src/pacman/conf.c index a9ff14c..6686f73 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -564,7 +564,7 @@ static int _parseconfig(const char *file, int parse_options, pm_printf(PM_LOG_DEBUG, "config: new section '%s'\n", name); /* if we are not looking at the options section, register a db */ if(!parse_options && strcmp(name, "options") != 0) { - db = alpm_db_register_sync(name); + db = alpm_db_register_sync(config->handle, name); if(db == NULL) { pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"), name, alpm_strerrorlast()); diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 83659cd..5112b1a 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -75,7 +75,7 @@ static void checkdbs(const char *dbpath, alpm_list_t *dbnames) { for(i = dbnames; i; i = alpm_list_next(i)) { char *dbname = alpm_list_getdata(i); snprintf(syncdbpath, PATH_MAX, "%s/sync/%s", dbpath, dbname); - db = alpm_db_register_sync(dbname); + db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", alpm_strerrorlast()); diff --git a/src/util/testdb.c b/src/util/testdb.c index c7640d9..620328e 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -152,7 +152,7 @@ static int check_syncdbs(alpm_list_t *dbnames) { for(i = dbnames; i; i = alpm_list_next(i)) { char *dbname = alpm_list_getdata(i); - db = alpm_db_register_sync(dbname); + db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", alpm_strerrorlast()); -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 3 ++- lib/libalpm/sync.c | 5 +---- src/pacman/sync.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 50ab06e..2144401 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -858,10 +858,11 @@ int alpm_trans_release(pmhandle_t *handle); /** @{ */ /** 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 diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 41f9f99..16be6d9 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -50,9 +50,6 @@ #include "diskspace.h" #include "signing.h" -/* global handle variable */ -extern pmhandle_t *handle; - /** Check for new version of pkg in sync repos * (only the first occurrence is considered in sync) */ @@ -85,7 +82,7 @@ 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; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 6f8508e..4cd8d21 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -760,7 +760,7 @@ static int sync_trans(alpm_list_t *targets) if(config->op_s_upgrade) { printf(_(":: Starting full system upgrade...\n")); alpm_logaction(config->handle, "starting full system upgrade\n"); - if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) { + if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); retval = 1; goto cleanup; -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 5 +++-- lib/libalpm/be_package.c | 16 ++++++++-------- lib/libalpm/package.h | 6 ++++-- lib/libalpm/sync.c | 2 +- src/pacman/query.c | 2 +- src/pacman/sync.c | 2 +- src/pacman/upgrade.c | 2 +- src/util/testpkg.c | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 2144401..44f2ba1 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -368,6 +368,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 @@ -376,8 +377,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 diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 0545167..5b8cd81 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -30,15 +30,13 @@ /* 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 */ -/* global handle variable */ -extern pmhandle_t *handle; - /** * Open a package changelog for reading. Similar to fopen in functionality, * except that the returned 'file stream' is from an archive. @@ -225,13 +223,15 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg) /** * 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; @@ -383,13 +383,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) { - /* Sanity checks */ + ASSERT(handle != NULL, return -1); ASSERT(pkg != NULL, RET_ERR(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/package.h b/lib/libalpm/package.h index 4e2dcf3..b5d8f73 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -141,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/sync.c b/lib/libalpm/sync.c index 16be6d9..1882888 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -876,7 +876,7 @@ int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data) /* 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, + pmpkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1, spkg->md5sum, spkg->base64_sig, check_sig); if(!pkgfile) { errors++; diff --git a/src/pacman/query.c b/src/pacman/query.c index d446534..76d9d73 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -552,7 +552,7 @@ int pacman_query(alpm_list_t *targets) char *strname = alpm_list_getdata(i); if(config->op_q_isfile) { - alpm_pkg_load(strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg); + alpm_pkg_load(config->handle, strname, 1, PM_PGP_VERIFY_OPTIONAL, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 4cd8d21..8405002 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -220,7 +220,7 @@ static int sync_cleancache(int level) /* attempt to load the package, prompt removal on failures as we may have * files here that aren't valid packages. we also don't need a full * load of the package, just the metadata. */ - if(alpm_pkg_load(path, 0, PM_PGP_VERIFY_NEVER, &localpkg) != 0 + if(alpm_pkg_load(config->handle, path, 0, PM_PGP_VERIFY_NEVER, &localpkg) != 0 || localpkg == NULL) { if(yesno(_("File %s does not seem to be a valid package, remove it?"), path)) { diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index ddb8a2e..deea1ee 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -76,7 +76,7 @@ int pacman_upgrade(alpm_list_t *targets) char *targ = alpm_list_getdata(i); pmpkg_t *pkg; - if(alpm_pkg_load(targ, 1, check_sig, &pkg) != 0) { + if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 0) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast()); trans_release(); diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 32011d4..5b8831d 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) /* let us get log messages from libalpm */ alpm_option_set_logcb(handle, output_cb); - if(alpm_pkg_load(argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 + if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 || pkg == NULL) { switch(pm_errno) { case PM_ERR_PKG_OPEN: -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 2 +- lib/libalpm/conflict.c | 20 ++++++++++++-------- lib/libalpm/conflict.h | 2 +- lib/libalpm/sync.c | 2 +- src/util/testdb.c | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 44f2ba1..270418e 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -912,7 +912,7 @@ 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); diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 8921470..28f8cc6 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -160,7 +160,7 @@ 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; @@ -197,11 +197,13 @@ 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; @@ -297,7 +299,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; @@ -305,7 +308,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg) char abspath[PATH_MAX]; DIR *dir; - snprintf(abspath, PATH_MAX, "%s%s", pkg->handle->root, dirpath); + snprintf(abspath, PATH_MAX, "%s%s", root, dirpath); dir = opendir(abspath); if(dir == NULL) { return 1; @@ -317,12 +320,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", pkg->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); @@ -474,7 +477,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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", dir, dbpkg->name); - resolved_conflict = dir_belongsto_pkg(filestr, dbpkg); + resolved_conflict = dir_belongsto_pkg(handle->root, filestr, dbpkg); } free(dir); } @@ -561,4 +564,5 @@ const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict) return conflict->ctarget; } + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index d00314d..2101170 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -40,7 +40,7 @@ struct __pmfileconflict_t { 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(pmhandle_t *handle, alpm_list_t *upgrade, alpm_list_t *remove); diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 1882888..518e853 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -398,7 +398,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 1. check for conflicts in the target list */ _alpm_log(PM_LOG_DEBUG, "check targets vs targets\n"); - deps = _alpm_innerconflicts(trans->add); + deps = _alpm_innerconflicts(handle, trans->add); for(i = deps; i; i = i->next) { pmconflict_t *conflict = i->data; diff --git a/src/util/testdb.c b/src/util/testdb.c index 620328e..839a9cf 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -117,7 +117,7 @@ static int checkconflicts(alpm_list_t *pkglist) alpm_list_t *data, *i; int ret = 0; /* check conflicts */ - data = alpm_checkconflicts(pkglist); + data = alpm_checkconflicts(handle, pkglist); for(i = data; i; i = i->next) { pmconflict_t *conflict = alpm_list_getdata(i); printf("%s conflicts with %s\n", alpm_conflict_get_package1(conflict), -- 1.7.5.2
This takes care of alpm_checkdeps() and alpm_find_dbs_satisfier(). Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 7 ++++--- lib/libalpm/deps.c | 29 +++++++++++++++-------------- lib/libalpm/deps.h | 2 +- lib/libalpm/remove.c | 27 ++++++++++++++++----------- lib/libalpm/sync.c | 5 +++-- src/pacman/sync.c | 2 +- src/util/testdb.c | 2 +- 7 files changed, 41 insertions(+), 33 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 270418e..821f2fa 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -903,10 +903,11 @@ 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); diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 3292289..1ebf45a 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -37,9 +37,6 @@ #include "handle.h" #include "trans.h" -/* global handle variable */ -extern pmhandle_t *handle; - void _alpm_dep_free(pmdepend_t *dep) { FREE(dep->name); @@ -257,14 +254,15 @@ 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; @@ -541,6 +539,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 @@ -550,8 +549,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; @@ -644,11 +643,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; @@ -657,7 +658,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; } @@ -666,8 +667,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 @@ -682,7 +683,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) { @@ -707,7 +708,7 @@ int _alpm_resolvedeps(alpm_list_t *localpkgs, alpm_list_t *dbs_sync, pmpkg_t *pk 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) { @@ -724,7 +725,7 @@ 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; diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index f728cad..2d61653 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -47,7 +47,7 @@ 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); 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/remove.c b/lib/libalpm/remove.c index 0682a35..5f09930 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -68,14 +68,15 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *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) { + 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", @@ -89,13 +90,15 @@ static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db, } 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) { + pmtrans_t *trans = handle->trans; + /* Remove needed packages (which break dependencies) from target list */ while(lp != NULL) { alpm_list_t *i; @@ -117,7 +120,8 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db, } 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); } } @@ -136,22 +140,23 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) 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_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); + 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; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 518e853..b4ac077 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -336,7 +336,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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, handle->dbs_sync, pkg, trans->add, + if(_alpm_resolvedeps(handle, localpkgs, pkg, trans->add, &resolved, remove, data) == -1) { unresolvable = alpm_list_add(unresolvable, pkg); } @@ -521,7 +521,8 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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); + deps = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local), + trans->remove, trans->add, 1); if(deps) { pm_errno = PM_ERR_UNSATISFIED_DEPS; ret = -1; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 8405002..cf350d7 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -685,7 +685,7 @@ cleanup: static int process_targname(alpm_list_t *dblist, char *targname) { - pmpkg_t *pkg = alpm_find_dbs_satisfier(dblist, targname); + pmpkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname); /* #FS23342 - skip ignored packages when user says no */ if(pm_errno == PM_ERR_PKG_IGNORED) { diff --git a/src/util/testdb.c b/src/util/testdb.c index 839a9cf..bda67d5 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -98,7 +98,7 @@ static int checkdeps(alpm_list_t *pkglist) alpm_list_t *data, *i; int ret = 0; /* check dependencies */ - data = alpm_checkdeps(pkglist, 0, NULL, pkglist); + data = alpm_checkdeps(handle, pkglist, NULL, pkglist, 0); for(i = data; i; i = alpm_list_next(i)) { pmdepmissing_t *miss = alpm_list_getdata(i); pmdepend_t *dep = alpm_miss_get_dep(miss); -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.h | 3 ++- lib/libalpm/sync.c | 5 +++-- src/pacman/sync.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 821f2fa..c493245 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -634,7 +634,8 @@ off_t alpm_delta_get_size(pmdelta_t *delta); */ const char *alpm_grp_get_name(const pmgrp_t *grp); alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp); -alpm_list_t *alpm_find_grp_pkgs(alpm_list_t *dbs, const char *name); +alpm_list_t *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, + const char *name); /* * Sync diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index b4ac077..b525efa 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -205,11 +205,12 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) /** Find group members across a list of databases. * If a member exists in several databases, only the first database is used. * IgnorePkg is also handled. + * @param handle the context handle * @param dbs the list of pmdb_t * - * @pram name the name of the group + * @param name the name of the group * @return the list of pmpkg_t * (caller is responsible for alpm_list_free) */ -alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL; diff --git a/src/pacman/sync.c b/src/pacman/sync.c index cf350d7..87b321f 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -641,7 +641,7 @@ static int process_group(alpm_list_t *dbs, char *group) { int ret = 0; alpm_list_t *i; - alpm_list_t *pkgs = alpm_find_grp_pkgs(dbs, group); + alpm_list_t *pkgs = alpm_find_grp_pkgs(config->handle, dbs, group); int count = alpm_list_count(pkgs); if(!count) { -- 1.7.5.2
On 2011/6/7 Dan McGee <dan@archlinux.org> wrote:
-alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;
I don't see where the handle is needed in this function. Rémy.
On Tue, Jun 7, 2011 at 5:19 PM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On 2011/6/7 Dan McGee <dan@archlinux.org> wrote:
-alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;
I don't see where the handle is needed in this function.
It's needed in the subsequent patches that move pm_errno to the handle; I tried anything to make that one smaller and this was one bit that could be split out. Barely worth it, I know, but trying every little bit... -Dan
On 08/06/11 08:29, Dan McGee wrote:
On Tue, Jun 7, 2011 at 5:19 PM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On 2011/6/7 Dan McGee<dan@archlinux.org> wrote:
-alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;
I don't see where the handle is needed in this function.
It's needed in the subsequent patches that move pm_errno to the handle; I tried anything to make that one smaller and this was one bit that could be split out. Barely worth it, I know, but trying every little bit...
It that for subsequent patches in this patchset or future patches? At the end of the current patchset, I find these two functions that do not use the handle argument: diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 7071e89..ceae3f8 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -538,7 +538,7 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *n * * @return 1 if the package should be ignored, 0 otherwise */ -int _alpm_pkg_should_ignore(pmhandle_t *handle, pmpkg_t *pkg) +int _alpm_pkg_should_ignore(pmhandle_t UNUSED *handle, pmpkg_t *pkg) { alpm_list_t *groups = NULL; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 81d4de2..2652424 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -213,7 +213,7 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int e * @param name the name of the group * @return the list of pmpkg_t * (caller is responsible for alpm_list_free) */ -alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t UNUSED *handle, alpm_list_
On Tue, Jun 7, 2011 at 6:38 PM, Allan McRae <allan@archlinux.org> wrote:
On 08/06/11 08:29, Dan McGee wrote:
On Tue, Jun 7, 2011 at 5:19 PM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On 2011/6/7 Dan McGee<dan@archlinux.org> wrote:
-alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs, +alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;
I don't see where the handle is needed in this function.
It's needed in the subsequent patches that move pm_errno to the handle; I tried anything to make that one smaller and this was one bit that could be split out. Barely worth it, I know, but trying every little bit...
It that for subsequent patches in this patchset or future patches? At the end of the current patchset, I find these two functions that do not use the handle argument:
Bagh, looks like I'm eating my words here. * alpm_find_grp_pkgs() needed the handle for the QUESTION() call, but as it is in a loop, we can get that off of the db (or the pkg) for that matter. So no need for the handle. * alpm_pkg_should_ignore() looks like one I missed from my original rough draft; as above the handle can be grabbed from the pkg object. I'll fix both of these up to their old signatures. -Dan
This involves some serious changes and a very messy diff, unfortunately. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/add.c | 31 ++++++++++-------- lib/libalpm/alpm.c | 6 ++-- lib/libalpm/alpm.h | 10 ++---- lib/libalpm/be_local.c | 28 +++++----------- lib/libalpm/be_package.c | 40 ++++++++++++------------ lib/libalpm/be_sync.c | 54 +++++++++++++++------------------ lib/libalpm/conflict.c | 65 ++++++++++++++++++++------------------- lib/libalpm/conflict.h | 1 - lib/libalpm/db.c | 75 ++++++++++++++++++++++----------------------- lib/libalpm/delta.c | 14 +++++--- lib/libalpm/deps.c | 34 +++++++++++---------- lib/libalpm/diskspace.c | 14 ++++---- lib/libalpm/dload.c | 36 +++++++++++----------- lib/libalpm/dload.h | 3 +- lib/libalpm/error.c | 16 ++-------- lib/libalpm/graph.c | 2 +- lib/libalpm/group.c | 4 +- lib/libalpm/handle.c | 10 +++--- lib/libalpm/handle.h | 3 ++ lib/libalpm/log.c | 12 ++++---- lib/libalpm/package.c | 34 +++++++++++--------- lib/libalpm/package.h | 2 +- lib/libalpm/pkghash.c | 8 +---- lib/libalpm/remove.c | 23 +++++++------- lib/libalpm/signing.c | 25 ++++++++------- lib/libalpm/sync.c | 60 +++++++++++++++++++------------------ lib/libalpm/trans.c | 70 +++++++++++++++++------------------------- lib/libalpm/trans.h | 1 - lib/libalpm/util.c | 54 +++++++++++++++++---------------- lib/libalpm/util.h | 15 +++++---- src/pacman/conf.c | 10 +++--- src/pacman/database.c | 2 +- src/pacman/remove.c | 13 +++++--- src/pacman/sync.c | 28 ++++++++++------- src/pacman/upgrade.c | 20 +++++++----- src/pacman/util.c | 9 +++-- src/util/cleanupdelta.c | 2 +- src/util/pactree.c | 30 +++++++----------- src/util/testdb.c | 2 +- src/util/testpkg.c | 5 ++- 40 files changed, 426 insertions(+), 445 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index da2ecdc..20d6745 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" @@ -56,10 +58,11 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg) pmpkg_t *local; /* Sanity checks */ - ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(pkg != NULL, return -1); trans = pkg->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(pkg->handle, PM_ERR_TRANS_NULL, -1)); + ASSERT(trans->state == STATE_INITIALIZED, + RET_ERR(pkg->handle, PM_ERR_TRANS_NOT_INITIALIZED, -1)); db_local = pkg->handle->db_local; pkgname = pkg->name; @@ -68,7 +71,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg) _alpm_log(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(pkg->handle, PM_ERR_TRANS_DUP_TARGET, -1); } local = _alpm_db_get_pkgfromcache(db_local, pkgname); @@ -265,7 +268,7 @@ static int extract_single_file(pmhandle_t *handle, 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)); } } } @@ -275,7 +278,7 @@ static int extract_single_file(pmhandle_t *handle, 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]; @@ -307,7 +310,7 @@ static int extract_single_file(pmhandle_t *handle, 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'; @@ -449,7 +452,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, _alpm_log(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'; @@ -523,7 +526,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, if(oldpkg) { /* set up fake remove transaction */ if(_alpm_upgraderemove_package(newpkg->handle, oldpkg, newpkg) == -1) { - pm_errno = PM_ERR_TRANS_ABORT; + handle->pm_errno = PM_ERR_TRANS_ABORT; ret = -1; goto cleanup; } @@ -534,7 +537,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, if(_alpm_local_db_prepare(db, newpkg)) { 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; } @@ -548,7 +551,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, _alpm_log(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; } @@ -559,7 +562,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, _alpm_log(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; } @@ -654,7 +657,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg)); 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; } @@ -720,7 +723,7 @@ int _alpm_upgrade_packages(pmhandle_t *handle) 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; diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index d516870..86b1619 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -35,7 +35,6 @@ #include "util.h" /* Globals */ -enum _pmerrno_t pm_errno SYMEXPORT; extern pmhandle_t *handle; /** \addtogroup alpm_interface Interface Functions @@ -107,6 +106,7 @@ cleanup: */ int SYMEXPORT alpm_release(pmhandle_t *myhandle) { + int ret = 0; pmdb_t *db; ASSERT(myhandle != NULL, return -1); @@ -119,7 +119,7 @@ int SYMEXPORT alpm_release(pmhandle_t *myhandle) } if(alpm_db_unregister_all(myhandle) == -1) { - return -1; + ret = -1; } _alpm_handle_free(myhandle); @@ -131,7 +131,7 @@ int SYMEXPORT alpm_release(pmhandle_t *myhandle) curl_global_cleanup(); #endif - return 0; + return ret; } /** @} */ diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index c493245..742a343 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1031,7 +1031,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, @@ -1040,14 +1039,11 @@ 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 */ /** @} */ diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 42ddaf5..d7d1812 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -282,12 +282,12 @@ static int checkdbdir(pmdb_t *db) _alpm_log(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); if(unlink(path) != 0 || _alpm_makepath(path) != 0) { - RET_ERR(PM_ERR_SYSTEM, -1); + RET_ERR(db->handle, PM_ERR_SYSTEM, -1); } } return 0; @@ -323,8 +323,6 @@ static int local_db_populate(pmdb_t *db) const char *dbpath; DIR *dbdir; - 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() */ @@ -336,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; @@ -363,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) { @@ -381,7 +379,7 @@ 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) { @@ -436,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; } @@ -449,10 +447,6 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) char line[1024]; char *pkgpath = NULL; - 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"); return -1; @@ -856,10 +850,6 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info) int ret = 0; char *pkgpath = NULL; - if(db == NULL || info == NULL) { - RET_ERR(PM_ERR_DB_NULL, -1); - } - pkgpath = get_pkgpath(db, info); ret = _alpm_rmrf(pkgpath); @@ -879,7 +869,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) { @@ -888,7 +878,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); } } diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 5b8cd81..20b9f52 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -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; @@ -166,26 +166,26 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg) 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); @@ -241,20 +241,20 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, struct stat st; 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 */ @@ -263,7 +263,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, _alpm_log(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); } } @@ -273,14 +273,14 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *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); + 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); @@ -289,7 +289,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, 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); @@ -330,7 +330,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, if(archive_read_data_skip(archive)) { _alpm_log(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; } @@ -343,7 +343,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occured */ _alpm_log(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; } @@ -375,7 +375,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, 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); @@ -387,7 +387,7 @@ int SYMEXPORT alpm_pkg_load(pmhandle_t *handle, const char *filename, int full, pgp_verify_t check_sig, pmpkg_t **pkg) { ASSERT(handle != NULL, return -1); - ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(pkg != NULL, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1)); *pkg = _alpm_pkg_load_internal(handle, filename, full, NULL, NULL, check_sig); if(*pkg == NULL) { diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index c8d3758..ecef7a5 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -85,15 +85,18 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) size_t len; int ret = -1; mode_t oldmask; + pmhandle_t *handle; pgp_verify_t check_sig; /* Sanity checks */ - ASSERT(db != NULL && db != db->handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - ASSERT(db->servers != NULL, RET_ERR(PM_ERR_SERVER_NONE, -1)); + 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)); - dbpath = alpm_option_get_dbpath(db->handle); + dbpath = alpm_option_get_dbpath(handle); len = strlen(dbpath) + 6; - MALLOC(syncpath, len, RET_ERR(PM_ERR_MEMORY, -1)); + MALLOC(syncpath, len, RET_ERR(handle, PM_ERR_MEMORY, -1)); sprintf(syncpath, "%s%s", dbpath, "sync/"); /* make sure we have a sane umask */ @@ -104,13 +107,13 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) syncpath); if(_alpm_makepath(syncpath) != 0) { free(syncpath); - RET_ERR(PM_ERR_SYSTEM, -1); + RET_ERR(handle, 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); + RET_ERR(handle, PM_ERR_SYSTEM, -1); } } @@ -124,10 +127,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)) { @@ -135,7 +138,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; } @@ -148,11 +151,11 @@ 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(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerror(handle->pm_errno)); goto cleanup; } @@ -239,10 +242,8 @@ static int sync_db_populate(pmdb_t *db) struct archive_entry *entry; pmpkg_t *pkg = NULL; - 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); @@ -261,17 +262,17 @@ static int sync_db_populate(pmdb_t *db) _alpm_log(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) { @@ -285,7 +286,7 @@ 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); @@ -360,18 +361,12 @@ 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; - 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"); return -1; @@ -385,7 +380,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; @@ -398,7 +393,7 @@ 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); } @@ -501,6 +496,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, return 0; error: + _alpm_log(PM_LOG_DEBUG, "error parsing database file: %s\n", filename); FREE(pkgname); return -1; } @@ -524,7 +520,7 @@ pmdb_t *_alpm_db_register_sync(pmhandle_t *handle, const char *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; diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 28f8cc6..1d3f0e7 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -40,16 +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; - MALLOC(conflict, sizeof(pmconflict_t), RET_ERR(PM_ERR_MEMORY, NULL)); + MALLOC(conflict, sizeof(pmconflict_t), return 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; } @@ -65,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; } @@ -98,17 +98,21 @@ static int conflict_isin(pmconflict_t *needle, alpm_list_t *haystack) * @param pkg1 first package * @param pkg2 package causing conflict */ -static void add_conflict(alpm_list_t **baddeps, const char *pkg1, +static int add_conflict(alpm_list_t **baddeps, const char *pkg1, const char *pkg2, const char *reason) { - pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason); + pmconflict_t *conflict = conflict_new(pkg1, pkg2, reason); + if(!conflict) { + return -1; + } _alpm_log(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. @@ -273,15 +277,15 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts, 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); @@ -392,6 +396,11 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, snprintf(path, PATH_MAX, "%s%s", handle->root, (char *)k->data); conflicts = add_fileconflict(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); } @@ -464,7 +473,8 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, /* 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)); + handle->trans->skip_remove = + alpm_list_add(handle->trans->skip_remove, strdup(filestr)); _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr); resolved_conflict = 1; } @@ -499,6 +509,11 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, _alpm_log(PM_LOG_DEBUG, "file found in conflict: %s\n", path); conflicts = add_fileconflict(conflicts, PM_FILECONFLICT_FILESYSTEM, path, p1->name, NULL); + if(!conflicts) { + FREELIST(conflicts); + FREELIST(tmpfiles); + RET_ERR(handle, PM_ERR_MEMORY, NULL); + } } } FREELIST(tmpfiles); @@ -511,57 +526,43 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, const char SYMEXPORT *alpm_conflict_get_package1(pmconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->package1; } const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->package2; } const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->reason; } const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->target; } pmfileconflicttype_t SYMEXPORT alpm_fileconflict_get_type(pmfileconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return -1); - return conflict->type; } const char SYMEXPORT *alpm_fileconflict_get_file(pmfileconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->file; } const char SYMEXPORT *alpm_fileconflict_get_ctarget(pmfileconflict_t *conflict) { - /* Sanity checks */ ASSERT(conflict != NULL, return NULL); - return conflict->ctarget; } diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index 2101170..7a3784a 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -37,7 +37,6 @@ 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(pmhandle_t *handle, alpm_list_t *packages); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 8156f2a..17dde95 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -48,10 +48,11 @@ pmdb_t SYMEXPORT *alpm_db_register_sync(pmhandle_t *handle, const char *treename) { /* 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(handle, treename); } @@ -74,9 +75,9 @@ int SYMEXPORT alpm_db_unregister_all(pmhandle_t *handle) pmdb_t *db; /* 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) { @@ -92,14 +93,16 @@ int SYMEXPORT alpm_db_unregister_all(pmhandle_t *handle) int SYMEXPORT alpm_db_unregister(pmdb_t *db) { int found = 0; + pmhandle_t *handle; /* Sanity checks */ - 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(db->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 == db->handle->db_local) { - db->handle->db_local = NULL; + if(db == handle->db_local) { + handle->db_local = NULL; found = 1; } else { /* Warning : this function shouldn't be used to unregister all sync @@ -107,7 +110,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db) * alpm_option_get_syncdbs, because the db is removed from that list here. */ void *data; - db->handle->dbs_sync = alpm_list_remove(db->handle->dbs_sync, + handle->dbs_sync = alpm_list_remove(handle->dbs_sync, db, _alpm_db_cmp, &data); if(data) { found = 1; @@ -115,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); @@ -126,7 +129,7 @@ int SYMEXPORT alpm_db_unregister(pmdb_t *db) alpm_list_t SYMEXPORT *alpm_db_get_servers(const pmdb_t *db) { /* Sanity checks */ - ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, NULL)); + ASSERT(db != NULL, return NULL); return(db->servers); } @@ -135,7 +138,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_servers(const pmdb_t *db) int SYMEXPORT alpm_db_set_servers(pmdb_t *db, alpm_list_t *servers) { /* 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; @@ -147,7 +150,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'; @@ -165,8 +168,8 @@ int SYMEXPORT alpm_db_add_server(pmdb_t *db, const char *url) char *newurl; /* 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) { @@ -190,8 +193,8 @@ int SYMEXPORT alpm_db_remove_server(pmdb_t *db, const char *url) char *newurl, *vdata = NULL; /* 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) { @@ -216,7 +219,7 @@ 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) { /* 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", @@ -228,9 +231,7 @@ int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify) /** Get the name of a package database. */ const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db) { - /* Sanity checks */ ASSERT(db != NULL, return NULL); - return db->treename; } @@ -239,7 +240,6 @@ const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db) { char *url; - /* Sanity checks */ ASSERT(db != NULL, return NULL); ASSERT(db->servers != NULL, return NULL); @@ -252,7 +252,6 @@ const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db) /** Get a package entry from a package database. */ pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name) { - /* Sanity checks */ ASSERT(db != NULL, return NULL); ASSERT(name != NULL && strlen(name) != 0, return NULL); @@ -262,16 +261,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) { - /* Sanity checks */ 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) { - /* Sanity checks */ ASSERT(db != NULL, return NULL); ASSERT(name != NULL && strlen(name) != 0, return NULL); @@ -281,7 +277,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) { - /* Sanity checks */ ASSERT(db != NULL, return NULL); return _alpm_db_get_grpcache(db); @@ -290,7 +285,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) { - /* Sanity checks */ ASSERT(db != NULL, return NULL); return _alpm_db_search(db, needles); @@ -299,12 +293,13 @@ 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) { - /* Sanity checks */ - 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); @@ -316,7 +311,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; @@ -328,8 +323,8 @@ pmdb_t *_alpm_db_new(const char *treename, int is_local) { pmdb_t *db; - 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; return db; @@ -360,16 +355,16 @@ const char *_alpm_db_path(pmdb_t *db) 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); + 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); } @@ -413,7 +408,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles) _alpm_log(PM_LOG_DEBUG, "searching for target '%s'\n", targ); if(regcomp(®, 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) { @@ -640,6 +635,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); } diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index 645c7ba..ad2be77 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; @@ -311,17 +315,17 @@ pmdelta_t *_alpm_delta_parse(char *line) } regfree(®); - 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, ' '); @@ -331,10 +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)); + STRDUP(delta->to, tmp2, return NULL); _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%jd'\n", delta->from, delta->to, (intmax_t)delta->delta_size); diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1ebf45a..bcec8c7 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -49,11 +49,11 @@ static pmdepmissing_t *depmiss_new(const char *target, pmdepend_t *dep, { pmdepmissing_t *miss; - MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL)); + MALLOC(miss, sizeof(pmdepmissing_t), return 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; } @@ -247,6 +247,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; @@ -414,7 +417,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. */ @@ -440,11 +443,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; @@ -453,11 +455,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; @@ -562,7 +564,7 @@ static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep, for(i = dbs; i; i = i->next) { pmpkg_t *pkg = _alpm_db_get_pkgfromcache(i->data, dep->name); if(pkg && _alpm_depcmp(pkg, dep) && !_alpm_pkg_find(excluding, pkg->name)) { - if(_alpm_pkg_should_ignore(pkg)) { + if(_alpm_pkg_should_ignore(handle, pkg)) { int install = 0; if(prompt) { QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, @@ -584,7 +586,7 @@ static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep, pmpkg_t *pkg = j->data; if(_alpm_depcmp(pkg, dep) && strcmp(pkg->name, dep->name) != 0 && !_alpm_pkg_find(excluding, pkg->name)) { - if(_alpm_pkg_should_ignore(pkg)) { + if(_alpm_pkg_should_ignore(handle, pkg)) { int install = 0; if(prompt) { QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, @@ -632,9 +634,9 @@ static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep, } 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; } @@ -728,7 +730,7 @@ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, 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, _("cannot resolve \"%s\", a dependency of \"%s\"\n"), @@ -860,7 +862,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/diskspace.c b/lib/libalpm/diskspace.c index 7be5464..c24b65d 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; @@ -87,7 +87,7 @@ static alpm_list_t *mount_point_list(void) 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)); @@ -193,7 +193,7 @@ static int calculate_installed_size(pmhandle_t *handle, 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(pmhandle_t *handle, 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; } @@ -246,7 +246,7 @@ static int calculate_installed_size(pmhandle_t *handle, if(archive_read_data_skip(archive)) { _alpm_log(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; } } @@ -267,7 +267,7 @@ int _alpm_check_diskspace(pmhandle_t *handle) 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")); return -1; @@ -350,7 +350,7 @@ int _alpm_check_diskspace(pmhandle_t *handle) 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/dload.c b/lib/libalpm/dload.c index 0ba3bc1..fee5a98 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -42,9 +42,6 @@ #include "util.h" #include "handle.h" -/* global handle variable */ -extern pmhandle_t *handle; - #ifdef HAVE_LIBCURL static double prevprogress; /* last download amount */ #endif @@ -65,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; @@ -92,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; } @@ -106,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; @@ -153,7 +150,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; @@ -170,11 +168,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); + RET_ERR(handle, PM_ERR_SERVER_BAD_URL, -1); } destfile = get_fullpath(localpath, dlfile.filename, ""); @@ -250,7 +249,7 @@ 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; + handle->pm_errno = PM_ERR_LIBCURL; _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"), dlfile.filename, hostname, error_buffer); } else { @@ -280,7 +279,7 @@ 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; + handle->pm_errno = PM_ERR_RETRIEVE; _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), dlfile.filename, (intmax_t)bytes_dl, (intmax_t)remote_size); goto cleanup; @@ -313,19 +312,20 @@ 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; } @@ -344,7 +344,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(pmhandle_t *handle, const char *url) 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); return NULL; @@ -359,10 +359,10 @@ char SYMEXPORT *alpm_fetch_pkgurl(pmhandle_t *handle, 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); /* Warn now, but don't return NULL. We will fail later during package diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index f4fd14c..e409c32 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 294ec21..d893f86 100644 --- a/lib/libalpm/error.c +++ b/lib/libalpm/error.c @@ -29,15 +29,12 @@ #include "alpm.h" #include "handle.h" -/* global handle variable */ -extern pmhandle_t *handle; - -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 */ @@ -140,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 */ @@ -151,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 2e2ba23..29bf86a 100644 --- a/lib/libalpm/graph.c +++ b/lib/libalpm/graph.c @@ -27,7 +27,7 @@ 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; } diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c index 383d016..1d77382 100644 --- a/lib/libalpm/group.c +++ b/lib/libalpm/group.c @@ -34,8 +34,8 @@ pmgrp_t *_alpm_grp_new(const char *name) { pmgrp_t* grp; - 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; } diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 0e50cbd..888eae8 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -44,7 +44,7 @@ pmhandle_t *_alpm_handle_new() { pmhandle_t *handle; - 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; @@ -290,7 +290,7 @@ int SYMEXPORT alpm_option_add_cachedir(pmhandle_t *handle, const char *cachedir) 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 @@ -347,7 +347,7 @@ int SYMEXPORT alpm_option_set_logfile(pmhandle_t *handle, const char *logfile) ASSERT(handle != NULL, return -1); if(!logfile) { - pm_errno = PM_ERR_WRONG_ARGS; + handle->pm_errno = PM_ERR_WRONG_ARGS; return -1; } @@ -370,7 +370,7 @@ int SYMEXPORT alpm_option_set_signaturedir(pmhandle_t *handle, const char *signa { ASSERT(handle != NULL, return -1); if(!signaturedir) { - pm_errno = PM_ERR_WRONG_ARGS; + handle->pm_errno = PM_ERR_WRONG_ARGS; return -1; } @@ -527,7 +527,7 @@ int SYMEXPORT alpm_option_set_checkspace(pmhandle_t *handle, int checkspace) int SYMEXPORT alpm_option_set_default_sigverify(pmhandle_t *handle, pgp_verify_t level) { ASSERT(handle != NULL, return -1); - ASSERT(level != PM_PGP_VERIFY_UNKNOWN, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(level != PM_PGP_VERIFY_UNKNOWN, RET_ERR(handle, PM_ERR_WRONG_ARGS, -1)); handle->sigverify = level; return 0; } diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index ecfefcc..bace805 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -70,6 +70,9 @@ struct __pmhandle_t { int usedelta; /* Download deltas if possible */ int checkspace; /* Check disk space before installing */ pgp_verify_t sigverify; /* Default signature verification level */ + + /* error code */ + enum _pmerrno_t pm_errno; }; pmhandle_t *_alpm_handle_new(void); diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 023bfc9..2b6385b 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -39,6 +39,7 @@ extern pmhandle_t *handle; */ /** 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) */ @@ -47,8 +48,7 @@ int SYMEXPORT alpm_logaction(pmhandle_t *handle, const char *fmt, ...) int ret; va_list args; - /* 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) { @@ -56,13 +56,13 @@ int SYMEXPORT alpm_logaction(pmhandle_t *handle, 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; } } diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 67d31c3..7071e89 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -45,7 +45,7 @@ /** Free a package. */ int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg) { - 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) { @@ -61,9 +61,9 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg) char *fpath; int retval; - 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(pkg->handle, alpm_pkg_get_filename(pkg)); @@ -72,7 +72,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *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; } @@ -366,7 +366,7 @@ pmpkg_t *_alpm_pkg_new(void) { pmpkg_t* pkg; - CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL)); + CALLOC(pkg, 1, sizeof(pmpkg_t), return NULL); return pkg; } @@ -376,19 +376,19 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) pmpkg_t *newpkg; alpm_list_t *i; - 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; @@ -419,6 +419,10 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) newpkg->handle = pkg->handle; return newpkg; + +cleanup: + _alpm_pkg_free(newpkg); + return NULL; } void _alpm_pkg_free(pmpkg_t *pkg) @@ -534,7 +538,7 @@ pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle) * * @return 1 if the package should be ignored, 0 otherwise */ -int _alpm_pkg_should_ignore(pmpkg_t *pkg) +int _alpm_pkg_should_ignore(pmhandle_t *handle, pmpkg_t *pkg) { alpm_list_t *groups = NULL; diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index b5d8f73..bc5b267 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -149,7 +149,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, int _alpm_pkg_cmp(const void *p1, const void *p2); int _alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg); pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle); -int _alpm_pkg_should_ignore(pmpkg_t *pkg); +int _alpm_pkg_should_ignore(pmhandle_t *handle, pmpkg_t *pkg); #endif /* _ALPM_PACKAGE_H */ diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c index 7e5e1fc..a22e6b5 100644 --- a/lib/libalpm/pkghash.c +++ b/lib/libalpm/pkghash.c @@ -55,11 +55,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++) { @@ -76,7 +72,7 @@ pmpkghash_t *_alpm_pkghash_create(size_t size) } CALLOC(hash->hash_table, hash->buckets, sizeof(alpm_list_t *), \ - free(hash); RET_ERR(PM_ERR_MEMORY, NULL)); + free(hash); return NULL); return hash; } diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 5f09930..e1c78c4 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -50,16 +50,16 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg) const char *pkgname; /* Sanity checks */ - ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(pkg != NULL, return -1); trans = pkg->handle->trans; - ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); + ASSERT(trans != NULL, RET_ERR(pkg->handle, PM_ERR_TRANS_NULL, -1)); ASSERT(trans->state == STATE_INITIALIZED, - RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1)); + RET_ERR(pkg->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(pkg->handle, PM_ERR_TRANS_DUP_TARGET, -1); } _alpm_log(PM_LOG_DEBUG, "adding package %s to the transaction remove list\n", @@ -164,7 +164,7 @@ int _alpm_remove_prepare(pmhandle_t *handle, 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); } } } @@ -189,11 +189,12 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) return 0; } -static int can_remove_file(pmhandle_t *handle, const char *path, alpm_list_t *skip) +static int can_remove_file(const char *root, const char *path, + alpm_list_t *skip) { char file[PATH_MAX+1]; - snprintf(file, PATH_MAX, "%s%s", handle->root, path); + snprintf(file, PATH_MAX, "%s%s", root, path); if(alpm_list_find_str(skip, file)) { /* return success because we will never actually remove this file */ @@ -317,10 +318,10 @@ int _alpm_upgraderemove_package(pmhandle_t *handle, } for(lp = files; lp; lp = lp->next) { - if(!can_remove_file(handle, lp->data, skip_remove)) { + if(!can_remove_file(handle->root, lp->data, skip_remove)) { _alpm_log(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); } } @@ -393,10 +394,10 @@ int _alpm_remove_packages(pmhandle_t *handle) size_t filenum; for(lp = files; lp; lp = lp->next) { - if(!can_remove_file(handle, lp->data, NULL)) { + if(!can_remove_file(handle->root, lp->data, NULL)) { _alpm_log(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); } } diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 6ce56e5..ec465e7 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 { \ @@ -117,7 +118,7 @@ static int gpgme_init(pmhandle_t *handle) } if(!alpm_option_get_signaturedir(handle)) { - RET_ERR(PM_ERR_SIG_MISSINGDIR, 1); + RET_ERR(handle, PM_ERR_SIG_MISSINGDIR, 1); } /* calling gpgme_check_version() returns the current version and runs @@ -154,7 +155,7 @@ static int gpgme_init(pmhandle_t *handle) error: _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err)); - RET_ERR(PM_ERR_GPGME, 1); + RET_ERR(handle, PM_ERR_GPGME, 1); } /** @@ -214,17 +215,17 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, FILE *file = NULL, *sigfile = NULL; 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); } } @@ -245,7 +246,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, /* 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; } @@ -268,7 +269,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, /* 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; } @@ -324,13 +325,13 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, _alpm_log(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; + handle->pm_errno = PM_ERR_SIG_UNKNOWN; _alpm_log(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; + handle->pm_errno = PM_ERR_SIG_INVALID; _alpm_log(PM_LOG_ERROR, _("File %s has an invalid signature.\n"), path); ret = 1; @@ -350,12 +351,13 @@ error: 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); + 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; } @@ -369,7 +371,6 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig) */ pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db) { - 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; diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index b525efa..f8b93f1 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -89,12 +89,12 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) pmdb_t *db_local; alpm_list_t *dbs_sync; - 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"); for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { @@ -118,7 +118,8 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) _alpm_log(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)) { + if(_alpm_pkg_should_ignore(spkg->handle, spkg) + || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { _alpm_log(PM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"), lpkg->name, lpkg->version, spkg->version); } else { @@ -129,7 +130,8 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) } else if(cmp < 0) { if(enable_downgrade) { /* check IgnorePkg/IgnoreGroup */ - if(_alpm_pkg_should_ignore(spkg) || _alpm_pkg_should_ignore(lpkg)) { + if(_alpm_pkg_should_ignore(spkg->handle, spkg) + || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { _alpm_log(PM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"), lpkg->name, lpkg->version, spkg->version); } else { @@ -152,7 +154,8 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, 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)) { + if(_alpm_pkg_should_ignore(spkg->handle, spkg) + || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { _alpm_log(PM_LOG_WARNING, _("ignoring package replacement (%s-%s => %s-%s)\n"), lpkg->name, lpkg->version, spkg->name, spkg->version); continue; @@ -228,7 +231,7 @@ alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(pmhandle_t *handle, alpm_list_t *dbs, if(_alpm_pkg_find(ignorelist, alpm_pkg_get_name(pkg))) { continue; } - if(_alpm_pkg_should_ignore(pkg)) { + if(_alpm_pkg_should_ignore(pkg->handle, pkg)) { ignorelist = alpm_list_add(ignorelist, pkg); int install = 0; QUESTION(db->handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, @@ -262,7 +265,7 @@ 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)); + ASSERT(fname != NULL, RET_ERR(newpkg->handle, PM_ERR_PKG_INVALID_NAME, -1)); fpath = _alpm_filecache_find(newpkg->handle, fname); if(fpath) { @@ -300,13 +303,12 @@ static int compute_download_size(pmpkg_t *newpkg) 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; pmtrans_t *trans = handle->trans; - pmdb_t *db_local = handle->db_local; if(data) { *data = NULL; @@ -330,7 +332,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 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 @@ -350,14 +352,14 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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); @@ -426,7 +428,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) sync = sync2; } else { _alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected\n")); - pm_errno = PM_ERR_CONFLICTING_DEPS; + handle->pm_errno = PM_ERR_CONFLICTING_DEPS; ret = -1; if(data) { pmconflict_t *newconflict = _alpm_conflict_dup(conflict); @@ -458,7 +460,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 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); + deps = _alpm_outerconflicts(handle->db_local, trans->add); for(i = deps; i; i = i->next) { pmconflict_t *conflict = i->data; @@ -480,7 +482,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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); @@ -490,7 +492,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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; + handle->pm_errno = PM_ERR_CONFLICTING_DEPS; ret = -1; if(data) { pmconflict_t *newconflict = _alpm_conflict_dup(conflict); @@ -525,7 +527,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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; @@ -609,11 +611,11 @@ static int apply_deltas(pmhandle_t *handle) } 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 */ @@ -649,7 +651,7 @@ static int apply_deltas(pmhandle_t *handle) 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; } @@ -713,7 +715,7 @@ static int validate_deltas(pmhandle_t *handle, 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); @@ -759,7 +761,7 @@ static int download_files(pmhandle_t *handle, alpm_list_t **deltas) 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 */ @@ -793,10 +795,10 @@ static int download_files(pmhandle_t *handle, 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; @@ -811,8 +813,8 @@ static int download_files(pmhandle_t *handle, alpm_list_t **deltas) if(errors) { _alpm_log(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; } @@ -898,7 +900,7 @@ int _alpm_sync_commit(pmhandle_t *handle, 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) { @@ -923,7 +925,7 @@ int _alpm_sync_commit(pmhandle_t *handle, 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); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index f7fbd2b..564b06e 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -105,29 +105,23 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags, int db_version; /* 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); } } - trans = _alpm_trans_new(); - if(trans == NULL) { - RET_ERR(PM_ERR_MEMORY, -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; - handle->trans = trans; - /* check database version */ db_version = _alpm_db_version(handle->db_local); if(db_version < required_db_version) { @@ -135,9 +129,11 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags, _("%s database version is too old\n"), handle->db_local->treename); remove_lock(handle); _alpm_trans_free(trans); - RET_ERR(PM_ERR_DB_VERSION, -1); + RET_ERR(handle, PM_ERR_DB_VERSION, -1); } + handle->trans = trans; + return 0; } @@ -158,7 +154,7 @@ static alpm_list_t *check_arch(pmhandle_t *handle, 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); } @@ -172,13 +168,13 @@ int SYMEXPORT alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data) pmtrans_t *trans; /* 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) { @@ -190,7 +186,7 @@ int SYMEXPORT alpm_trans_prepare(pmhandle_t *handle, alpm_list_t **data) 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) { @@ -216,14 +212,14 @@ int SYMEXPORT alpm_trans_commit(pmhandle_t *handle, alpm_list_t **data) pmtrans_t *trans; /* 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) { @@ -255,12 +251,12 @@ int SYMEXPORT alpm_trans_interrupt(pmhandle_t *handle) pmtrans_t *trans; /* 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; @@ -273,11 +269,11 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle) pmtrans_t *trans; /* 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; @@ -299,16 +295,6 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle) /** @} */ -pmtrans_t *_alpm_trans_new(void) -{ - pmtrans_t *trans; - - 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) { if(trans == NULL) { @@ -384,7 +370,7 @@ int _alpm_runscriptlet(pmhandle_t *handle, 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 { @@ -428,8 +414,8 @@ cleanup: 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; } @@ -438,7 +424,7 @@ 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; } @@ -447,7 +433,7 @@ 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 8c9e7fa..e858715 100644 --- a/lib/libalpm/trans.h +++ b/lib/libalpm/trans.h @@ -66,7 +66,6 @@ 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, diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 174af8c..2ad0833 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -152,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; } @@ -215,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; } @@ -236,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; @@ -253,8 +253,9 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int char cwd[PATH_MAX]; int restore_cwd = 0; - 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); @@ -263,7 +264,7 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { _alpm_log(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); @@ -277,7 +278,8 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int /* 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(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), + prefix, strerror(errno)); ret = 1; goto cleanup; } @@ -337,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(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), + cwd, strerror(errno)); } return ret; } @@ -581,7 +584,7 @@ char *_alpm_filecache_find(pmhandle_t *handle, const char *filename) } } /* 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. @@ -655,7 +658,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); @@ -702,7 +705,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 */ @@ -856,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 839b802..b289531 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -29,6 +29,7 @@ #include "alpm_list.h" #include "alpm.h" #include "package.h" /* pmpkg_t */ +#include "handle.h" /* pmhandle_t */ #include <stdio.h> #include <string.h> @@ -60,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(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(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) @@ -90,8 +91,10 @@ 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(pmhandle_t *handle, const char *fmt, va_list args); int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[]); diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 6686f73..97e6497 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -402,7 +402,7 @@ static int _add_mirror(pmdb_t *db, char *value) if(alpm_db_add_server(db, server) != 0) { /* pm_errno is set by alpm_db_setserver */ pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"), - dbname, server, alpm_strerrorlast()); + dbname, server, alpm_strerror(alpm_errno(config->handle))); free(server); return 1; } @@ -460,7 +460,7 @@ static int setup_libalpm(void) ret = alpm_option_set_logfile(handle, config->logfile); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting logfile '%s' (%s)\n"), - config->logfile, alpm_strerrorlast()); + config->logfile, alpm_strerror(alpm_errno(config->handle))); return ret; } @@ -470,7 +470,7 @@ static int setup_libalpm(void) ret = alpm_option_set_signaturedir(handle, config->gpgdir); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("problem setting gpgdir '%s' (%s)\n"), - config->gpgdir, alpm_strerrorlast()); + config->gpgdir, alpm_strerror(alpm_errno(config->handle))); return ret; } @@ -567,7 +567,7 @@ static int _parseconfig(const char *file, int parse_options, db = alpm_db_register_sync(config->handle, name); if(db == NULL) { pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"), - name, alpm_strerrorlast()); + name, alpm_strerror(alpm_errno(config->handle))); ret = 1; goto cleanup; } @@ -665,7 +665,7 @@ static int _parseconfig(const char *file, int parse_options, ret = alpm_db_set_pgp_verify(db, level); if(ret != 0) { pm_printf(PM_LOG_ERROR, _("could not add set verify option for database '%s': %s (%s)\n"), - alpm_db_get_name(db), value, alpm_strerrorlast()); + alpm_db_get_name(db), value, alpm_strerror(alpm_errno(config->handle))); goto cleanup; } } else { diff --git a/src/pacman/database.c b/src/pacman/database.c index 33cd49e..292fa54 100644 --- a/src/pacman/database.c +++ b/src/pacman/database.c @@ -68,7 +68,7 @@ int pacman_database(alpm_list_t *targets) char *pkgname = i->data; if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) { pm_printf(PM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"), - pkgname, alpm_strerrorlast()); + pkgname, alpm_strerror(alpm_errno(config->handle))); retval = 1; } else { if(reason == PM_PKG_REASON_DEPEND) { diff --git a/src/pacman/remove.c b/src/pacman/remove.c index b96687a..5993ab3 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -39,7 +39,8 @@ static int remove_target(const char *target) if((info = alpm_db_get_pkg(db_local, target)) != NULL) { if(alpm_remove_pkg(info) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, + alpm_strerror(alpm_errno(config->handle))); return -1; } return 0; @@ -54,7 +55,8 @@ static int remove_target(const char *target) for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) { pmpkg_t *pkg = alpm_list_getdata(p); if(alpm_remove_pkg(pkg) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target, + alpm_strerror(alpm_errno(config->handle))); return -1; } } @@ -100,9 +102,10 @@ int pacman_remove(alpm_list_t *targets) /* Step 2: prepare the transaction based on its type, targets and flags */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { char *pkg = alpm_list_getdata(i); @@ -164,7 +167,7 @@ int pacman_remove(alpm_list_t *targets) if(alpm_trans_commit(config->handle, NULL) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); + alpm_strerror(alpm_errno(config->handle))); retval = 1; } diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 87b321f..dae828d 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -293,7 +293,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) ret = alpm_db_update((level < 2 ? 0 : 1), db); if(ret < 0) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to update %s (%s)\n"), - alpm_db_get_name(db), alpm_strerrorlast()); + alpm_db_get_name(db), alpm_strerror(alpm_errno(config->handle))); } else if(ret == 1) { printf(_(" %s is up to date\n"), alpm_db_get_name(db)); success++; @@ -623,14 +623,15 @@ static int process_pkg(pmpkg_t *pkg) int ret = alpm_add_pkg(pkg); if(ret == -1) { - if(pm_errno == PM_ERR_TRANS_DUP_TARGET - || pm_errno == PM_ERR_PKG_IGNORED) { + enum _pmerrno_t err = alpm_errno(config->handle); + if(err == PM_ERR_TRANS_DUP_TARGET + || err == PM_ERR_PKG_IGNORED) { /* just skip duplicate or ignored targets */ pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), alpm_pkg_get_name(pkg)); return 0; } else { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", alpm_pkg_get_name(pkg), - alpm_strerrorlast()); + alpm_strerror(err)); return 1; } } @@ -687,10 +688,11 @@ static int process_targname(alpm_list_t *dblist, char *targname) { pmpkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname); - /* #FS23342 - skip ignored packages when user says no */ - if(pm_errno == PM_ERR_PKG_IGNORED) { + /* #FS#23342 - skip ignored packages when user says no */ + if(alpm_errno(config->handle) == PM_ERR_PKG_IGNORED) { pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targname); - pm_errno = 0; + /* TODO how to do this, we shouldn't be fucking with it from the frontend */ + /* pm_errno = 0; */ return 0; } @@ -761,7 +763,7 @@ static int sync_trans(alpm_list_t *targets) printf(_(":: Starting full system upgrade...\n")); alpm_logaction(config->handle, "starting full system upgrade\n"); if(alpm_sync_sysupgrade(config->handle, config->op_s_upgrade >= 2) == -1) { - pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast()); + pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerror(alpm_errno(config->handle))); retval = 1; goto cleanup; } @@ -769,9 +771,10 @@ static int sync_trans(alpm_list_t *targets) /* Step 2: "compute" the transaction based on targets and flags */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { @@ -838,9 +841,10 @@ static int sync_trans(alpm_list_t *targets) } if(alpm_trans_commit(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_FILE_CONFLICTS: for(i = data; i; i = alpm_list_next(i)) { diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index deea1ee..cdbbffe 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -57,7 +57,7 @@ int pacman_upgrade(alpm_list_t *targets) char *str = alpm_fetch_pkgurl(config->handle, i->data); if(str == NULL) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - (char *)i->data, alpm_strerrorlast()); + (char *)i->data, alpm_strerror(alpm_errno(config->handle))); return 1; } else { free(i->data); @@ -78,13 +78,13 @@ int pacman_upgrade(alpm_list_t *targets) if(alpm_pkg_load(config->handle, targ, 1, check_sig, &pkg) != 0) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - targ, alpm_strerrorlast()); + targ, alpm_strerror(alpm_errno(config->handle))); trans_release(); return 1; } if(alpm_add_pkg(pkg) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", - targ, alpm_strerrorlast()); + targ, alpm_strerror(alpm_errno(config->handle))); alpm_pkg_free(pkg); trans_release(); return 1; @@ -94,9 +94,10 @@ int pacman_upgrade(alpm_list_t *targets) /* Step 2: "compute" the transaction based on targets and flags */ /* TODO: No, compute nothing. This is stupid. */ if(alpm_trans_prepare(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { case PM_ERR_PKG_INVALID_ARCH: for(i = data; i; i = alpm_list_next(i)) { char *pkg = alpm_list_getdata(i); @@ -140,15 +141,15 @@ int pacman_upgrade(alpm_list_t *targets) } /* Step 3: perform the installation */ + alpm_list_t *packages = alpm_trans_get_add(config->handle); if(config->print) { - print_packages(alpm_trans_get_add(config->handle)); + print_packages(packages); trans_release(); return 0; } /* print targets and ask user confirmation */ - alpm_list_t *packages = alpm_trans_get_add(config->handle); if(packages == NULL) { /* we are done */ printf(_(" there is nothing to do\n")); trans_release(); @@ -164,9 +165,10 @@ int pacman_upgrade(alpm_list_t *targets) } if(alpm_trans_commit(config->handle, &data) == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), - alpm_strerrorlast()); - switch(pm_errno) { + alpm_strerror(err)); + switch(err) { alpm_list_t *i; case PM_ERR_FILE_CONFLICTS: for(i = data; i; i = alpm_list_next(i)) { diff --git a/src/pacman/util.c b/src/pacman/util.c index 043b9d6..71acd6f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -60,14 +60,15 @@ int trans_init(pmtransflag_t flags) } if(ret == -1) { + enum _pmerrno_t err = alpm_errno(config->handle); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to init transaction (%s)\n"), - alpm_strerrorlast()); - if(pm_errno == PM_ERR_HANDLE_LOCK) { + alpm_strerror(err)); + if(err == PM_ERR_HANDLE_LOCK) { fprintf(stderr, _(" if you're sure a package manager is not already\n" " running, you can remove %s\n"), alpm_option_get_lockfile(config->handle)); } - else if(pm_errno == PM_ERR_DB_VERSION) { + else if(err == PM_ERR_DB_VERSION) { fprintf(stderr, _(" try running pacman-db-upgrade\n")); } @@ -80,7 +81,7 @@ int trans_release(void) { if(alpm_trans_release(config->handle) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"), - alpm_strerrorlast()); + alpm_strerror(alpm_errno(config->handle))); return -1; } return 0; diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c index 5112b1a..9829170 100644 --- a/src/util/cleanupdelta.c +++ b/src/util/cleanupdelta.c @@ -78,7 +78,7 @@ static void checkdbs(const char *dbpath, alpm_list_t *dbnames) { db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); return; } checkpkgs(alpm_db_get_pkgcache(db)); diff --git a/src/util/pactree.c b/src/util/pactree.c index 6c86942..1dee61b 100644 --- a/src/util/pactree.c +++ b/src/util/pactree.c @@ -88,19 +88,6 @@ int reverse = 0; int unique = 0; const char *dbpath = DBPATH; -static int alpm_local_init(void) -{ - enum _pmerrno_t err; - - handle = alpm_initialize(ROOTDIR, dbpath, &err); - if(!handle) { - return -1; - } - - db_local = alpm_option_get_localdb(handle); - return 0; -} - static int parse_options(int argc, char *argv[]) { int opt, option_index = 0; @@ -327,22 +314,27 @@ static void walk_deps(pmpkg_t *pkg, int depth) int main(int argc, char *argv[]) { - int ret; + int ret = 0; + enum _pmerrno_t err; const char *target_name; pmpkg_t *pkg; - ret = parse_options(argc, argv); - if(ret != 0) { + if(parse_options(argc, argv) != 0) { usage(); + ret = 1; goto finish; } - ret = alpm_local_init(); - if(ret != 0) { - fprintf(stderr, "error: cannot initialize alpm: %s\n", alpm_strerrorlast()); + handle = alpm_initialize(ROOTDIR, dbpath, &err); + if(!handle) { + fprintf(stderr, "error: cannot initialize alpm: %s\n", + alpm_strerror(err)); + ret = 1; goto finish; } + db_local = alpm_option_get_localdb(handle); + /* we only care about the first non option arg for walking */ target_name = argv[optind]; diff --git a/src/util/testdb.c b/src/util/testdb.c index bda67d5..0bd7820 100644 --- a/src/util/testdb.c +++ b/src/util/testdb.c @@ -155,7 +155,7 @@ static int check_syncdbs(alpm_list_t *dbnames) { db = alpm_db_register_sync(handle, dbname); if(db == NULL) { fprintf(stderr, "error: could not register sync database (%s)\n", - alpm_strerrorlast()); + alpm_strerror(alpm_errno(handle))); ret = 1; goto cleanup; } diff --git a/src/util/testpkg.c b/src/util/testpkg.c index 5b8831d..c6f02e3 100644 --- a/src/util/testpkg.c +++ b/src/util/testpkg.c @@ -60,7 +60,8 @@ int main(int argc, char *argv[]) if(alpm_pkg_load(handle, argv[1], 1, PM_PGP_VERIFY_OPTIONAL, &pkg) == -1 || pkg == NULL) { - switch(pm_errno) { + enum _pmerrno_t err = alpm_errno(handle); + switch(err) { case PM_ERR_PKG_OPEN: printf("Cannot open the given file.\n"); break; @@ -69,7 +70,7 @@ int main(int argc, char *argv[]) printf("Package is invalid.\n"); break; default: - printf("libalpm error: %s\n", alpm_strerrorlast()); + printf("libalpm error: %s\n", alpm_strerror(err)); break; } retval = 1; -- 1.7.5.2
This is the last user of our global handle object. Once again the diff is large but the functional changes are not. Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/add.c | 114 +++++++++++++++++++++++----------------------- lib/libalpm/be_local.c | 47 ++++++++++--------- lib/libalpm/be_package.c | 34 +++++++------- lib/libalpm/be_sync.c | 38 ++++++++------- lib/libalpm/conflict.c | 70 +++++++++++++++------------- lib/libalpm/db.c | 42 ++++++++--------- lib/libalpm/delta.c | 6 +-- lib/libalpm/deps.c | 48 +++++++------------ lib/libalpm/deps.h | 2 +- lib/libalpm/diskspace.c | 22 ++++---- lib/libalpm/dload.c | 19 ++++---- lib/libalpm/group.c | 5 +-- lib/libalpm/handle.c | 6 +- lib/libalpm/log.c | 2 +- lib/libalpm/log.h | 3 +- lib/libalpm/pkghash.c | 5 +- lib/libalpm/remove.c | 84 +++++++++++++++++---------------- lib/libalpm/signing.c | 39 ++++++++-------- lib/libalpm/sync.c | 89 ++++++++++++++++++----------------- lib/libalpm/trans.c | 14 +++--- lib/libalpm/util.c | 51 ++++++++++---------- lib/libalpm/util.h | 6 +- 22 files changed, 370 insertions(+), 376 deletions(-) diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 20d6745..4ea6c34 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -53,28 +53,28 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg) { const char *pkgname, *pkgver; + pmhandle_t *handle; pmtrans_t *trans; - pmdb_t *db_local; pmpkg_t *local; /* Sanity checks */ ASSERT(pkg != NULL, return -1); - trans = pkg->handle->trans; - ASSERT(trans != NULL, RET_ERR(pkg->handle, PM_ERR_TRANS_NULL, -1)); + handle = pkg->handle; + trans = handle->trans; + ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1)); ASSERT(trans->state == STATE_INITIALIZED, - RET_ERR(pkg->handle, PM_ERR_TRANS_NOT_INITIALIZED, -1)); - db_local = pkg->handle->db_local; + 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(pkg->handle, 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,23 +83,23 @@ 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 if(!(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY)) { - _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"), + _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); @@ -119,10 +119,10 @@ static int perform_extraction(pmhandle_t *handle, 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(handle, "error: could not extract %s (%s)\n", origname, archive_error_string(archive)); @@ -160,7 +160,7 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, } 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 { @@ -170,7 +170,7 @@ static int extract_single_file(pmhandle_t *handle, 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(handle, "note: %s is in NoExtract, skipping extraction\n", entryname); @@ -209,20 +209,20 @@ static int extract_single_file(pmhandle_t *handle, 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(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; @@ -231,20 +231,20 @@ static int extract_single_file(pmhandle_t *handle, 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: */ @@ -318,10 +318,10 @@ static int extract_single_file(pmhandle_t *handle, 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) { @@ -332,7 +332,7 @@ static int extract_single_file(pmhandle_t *handle, 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(handle, "error: could not rename %s to %s (%s)\n", filename, newpath, strerror(errno)); @@ -340,13 +340,13 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, } 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(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_log(handle, PM_LOG_WARNING, _("%s saved as %s\n"), filename, newpath); alpm_logaction(handle, "warning: %s saved as %s\n", filename, newpath); } } @@ -360,11 +360,11 @@ static int extract_single_file(pmhandle_t *handle, 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(handle, "error: could not rename %s to %s (%s)\n", checkfile, filename, strerror(errno)); @@ -373,33 +373,33 @@ static int extract_single_file(pmhandle_t *handle, struct archive *archive, } 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(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(handle, "warning: %s installed as %s\n", filename, newpath); @@ -416,12 +416,12 @@ static int extract_single_file(pmhandle_t *handle, 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_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(handle->trans->flags & PM_TRANS_FLAG_FORCE) { @@ -449,7 +449,7 @@ static int extract_single_file(pmhandle_t *handle, 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(handle, PM_ERR_MEMORY, -1)); @@ -491,7 +491,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, _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 */ @@ -506,7 +506,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, 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 */ @@ -548,7 +548,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, 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) { handle->pm_errno = PM_ERR_LIBARCHIVE; @@ -559,7 +559,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, 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) { handle->pm_errno = PM_ERR_PKG_OPEN; @@ -569,15 +569,15 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, /* 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(newpkg->handle->root) != 0) { - _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), - newpkg->handle->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)); ret = -1; goto cleanup; } @@ -600,7 +600,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, * (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) { @@ -627,18 +627,18 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, /* 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(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(handle, "error: problem occurred while installing %s\n", newpkg->name); @@ -649,11 +649,11 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, /* 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(handle, "error: could not update database entry %s-%s\n", alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg)); @@ -663,7 +663,7 @@ static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg, } 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)); } diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index d7d1812..d9a76cc 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -279,13 +279,13 @@ 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(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(db->handle, PM_ERR_SYSTEM, -1); } @@ -383,7 +383,7 @@ static int local_db_populate(pmdb_t *db) } /* 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; @@ -391,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; } @@ -403,13 +403,13 @@ static int local_db_populate(pmdb_t *db) /* 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++; @@ -419,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; @@ -448,12 +448,13 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) char *pkgpath = NULL; 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; @@ -468,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 */ @@ -478,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; } @@ -487,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)) { @@ -500,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) { @@ -508,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) { @@ -611,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)) { @@ -670,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)); } @@ -704,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; } @@ -805,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; } @@ -908,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; } @@ -922,7 +925,7 @@ pmdb_t *_alpm_db_register_local(pmhandle_t *handle) { pmdb_t *db; - _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) { diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index 20b9f52..a77e286 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -137,7 +137,7 @@ static struct pkg_operations *get_file_pkg_ops(void) * * @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; @@ -159,7 +159,7 @@ 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); @@ -207,14 +207,14 @@ 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(PM_LOG_DEBUG, "error parsing package descfile\n"); + _alpm_log(handle, PM_LOG_DEBUG, "error parsing package descfile\n"); return -1; } @@ -258,18 +258,18 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, } /* 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(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); + _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)) { @@ -292,7 +292,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, 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 @@ -302,17 +302,17 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, 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; @@ -328,7 +328,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, } 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)); handle->pm_errno = PM_ERR_LIBARCHIVE; goto error; @@ -341,14 +341,14 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, } 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)); 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; } @@ -362,7 +362,7 @@ pmpkg_t *_alpm_pkg_load_internal(pmhandle_t *handle, const char *pkgfile, 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; diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index ecef7a5..0469c63 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -103,14 +103,14 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) oldmask = umask(0022); if(stat(syncpath, &buf) != 0) { - _alpm_log(PM_LOG_DEBUG, "database dir '%s' does not exist, creating it\n", + _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, -1); } } else if(!S_ISDIR(buf.st_mode)) { - _alpm_log(PM_LOG_WARNING, _("removing invalid file: %s\n"), syncpath); + _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, -1); @@ -155,7 +155,8 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) 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_strerror(handle->pm_errno)); + _alpm_log(handle, PM_LOG_DEBUG, "failed to sync db: %s\n", + alpm_strerror(handle->pm_errno)); goto cleanup; } @@ -255,11 +256,11 @@ 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(db->handle, PM_ERR_DB_OPEN, -1); @@ -292,7 +293,7 @@ static int sync_db_populate(pmdb_t *db) 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; @@ -301,7 +302,7 @@ static int sync_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); pkg = NULL; continue; @@ -313,14 +314,14 @@ static int sync_db_populate(pmdb_t *db) 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 */ if(sync_db_read(db, archive, entry, pkg) != 0) { - _alpm_log(PM_LOG_ERROR, + _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); @@ -334,7 +335,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; @@ -368,11 +369,12 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, 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)); @@ -398,7 +400,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, 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; } @@ -412,13 +414,13 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, 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) { @@ -490,13 +492,13 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, /* 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); } return 0; error: - _alpm_log(PM_LOG_DEBUG, "error parsing database file: %s\n", filename); + _alpm_log(db->handle, PM_LOG_DEBUG, "error parsing database file: %s\n", filename); FREE(pkgname); return -1; } @@ -516,7 +518,7 @@ pmdb_t *_alpm_db_register_sync(pmhandle_t *handle, const char *treename) { pmdb_t *db; - _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) { diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 1d3f0e7..b64604f 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -93,19 +93,21 @@ 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 int 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 = conflict_new(pkg1, pkg2, reason); if(!conflict) { return -1; } - _alpm_log(PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n", + _alpm_log(handle, PM_LOG_DEBUG, "package %s conflicts with %s (by %s)\n", pkg1, pkg2, reason); if(!conflict_isin(conflict, *baddeps)) { *baddeps = alpm_list_add(*baddeps, conflict); @@ -121,14 +123,16 @@ static int 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); } } } @@ -168,8 +174,8 @@ alpm_list_t *_alpm_innerconflicts(pmhandle_t *handle, alpm_list_t *packages) { alpm_list_t *baddeps = NULL; - _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; } @@ -190,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; @@ -206,7 +212,8 @@ alpm_list_t *_alpm_outerconflicts(pmdb_t *db, alpm_list_t *packages) * @return an alpm_list_t of pmconflict_t */ alpm_list_t SYMEXPORT *alpm_checkconflicts(pmhandle_t *handle, - alpm_list_t *pkglist) { + alpm_list_t *pkglist) +{ return _alpm_innerconflicts(handle, pkglist); } @@ -272,9 +279,9 @@ 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), return NULL); @@ -289,7 +296,7 @@ static alpm_list_t *add_fileconflict(alpm_list_t *conflicts, } 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; @@ -381,7 +388,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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; @@ -394,7 +401,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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); @@ -411,7 +418,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, char *filestr = NULL; /* CHECK 2: check every target against the filesystem */ - _alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", 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, @@ -439,15 +446,15 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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? */ @@ -455,7 +462,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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; } } @@ -475,7 +482,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, * by its new owner (whether the file is in backup array or not */ handle->trans->skip_remove = alpm_list_add(handle->trans->skip_remove, strdup(filestr)); - _alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr); + _alpm_log(handle, PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr); resolved_conflict = 1; } } @@ -485,7 +492,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, 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(handle->root, filestr, dbpkg); } @@ -506,8 +513,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle, } 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); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 17dde95..b2f3762 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -64,7 +64,7 @@ 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); } @@ -128,18 +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) { - /* Sanity checks */ 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) { - /* Sanity checks */ ASSERT(db != NULL, return -1); - if(db->servers) FREELIST(db->servers); db->servers = servers; return 0; @@ -176,7 +172,7 @@ int SYMEXPORT alpm_db_add_server(pmdb_t *db, const char *url) 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; @@ -203,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; @@ -222,7 +218,7 @@ int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify) 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); @@ -302,7 +298,7 @@ int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t 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; @@ -354,7 +350,7 @@ const char *_alpm_db_path(pmdb_t *db) dbpath = alpm_option_get_dbpath(db->handle); if(!dbpath) { - _alpm_log(PM_LOG_ERROR, _("database path is undefined\n")); + _alpm_log(db->handle, PM_LOG_ERROR, _("database path is undefined\n")); RET_ERR(db->handle, PM_ERR_DB_OPEN, NULL); } @@ -368,7 +364,7 @@ const char *_alpm_db_path(pmdb_t *db) /* 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; @@ -405,7 +401,7 @@ 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(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) { RET_ERR(db->handle, PM_ERR_INVALID_REGEX, NULL); @@ -447,7 +443,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); } @@ -473,10 +469,10 @@ int _alpm_db_load_pkgcache(pmdb_t *db) } _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; } @@ -491,7 +487,7 @@ void _alpm_db_free_pkgcache(pmdb_t *db) 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), @@ -514,7 +510,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; @@ -545,7 +541,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); @@ -562,13 +558,13 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg) 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; } @@ -588,7 +584,7 @@ pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target) 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; } @@ -606,7 +602,7 @@ int _alpm_db_load_grpcache(pmdb_t *db) 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) { @@ -656,7 +652,7 @@ void _alpm_db_free_grpcache(pmdb_t *db) 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) { diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index ad2be77..aa76b49 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -235,14 +235,14 @@ off_t _alpm_shortest_delta_path(pmhandle_t *handle, alpm_list_t *deltas, 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(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); @@ -340,8 +340,6 @@ pmdelta_t *_alpm_delta_parse(char *line) tmp2 = tmp; STRDUP(delta->to, tmp2, return NULL); - _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%jd'\n", delta->from, delta->to, (intmax_t)delta->delta_size); - return delta; } diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index bcec8c7..2877640 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -126,7 +126,8 @@ 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; @@ -137,7 +138,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, int reverse) 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); @@ -160,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) { @@ -185,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 */ @@ -288,7 +289,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmhandle_t *handle, alpm_list_t *pkglist, /* 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) { @@ -301,7 +302,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmhandle_t *handle, alpm_list_t *pkglist, /* 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); @@ -328,7 +329,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmhandle_t *handle, alpm_list_t *pkglist, !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)); @@ -481,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; } @@ -529,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)); @@ -570,7 +571,7 @@ static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep, 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; @@ -592,14 +593,14 @@ static pmpkg_t *resolvedep(pmhandle_t *handle, pmdepend_t *dep, 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 */ @@ -706,7 +707,7 @@ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, 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); @@ -732,7 +733,7 @@ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, if(!spkg) { 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); @@ -741,7 +742,7 @@ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, } 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); @@ -756,55 +757,43 @@ int _alpm_resolvedeps(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, } 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) { - /* Sanity checks */ ASSERT(miss != NULL, return NULL); - return miss->target; } const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss) { - /* Sanity checks */ ASSERT(miss != NULL, return NULL); - return miss->causingpkg; } pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss) { - /* Sanity checks */ ASSERT(miss != NULL, return NULL); - return miss->depend; } pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep) { - /* Sanity checks */ ASSERT(dep != NULL, return -1); - return dep->mod; } const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep) { - /* Sanity checks */ ASSERT(dep != NULL, return NULL); - return dep->name; } const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep) { - /* Sanity checks */ ASSERT(dep != NULL, return NULL); - return dep->version; } @@ -819,7 +808,6 @@ char SYMEXPORT *alpm_dep_compute_string(const pmdepend_t *dep) char *str; size_t len; - /* Sanity checks */ ASSERT(dep != NULL, return NULL); if(dep->name) { diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index 2d61653..97c0918 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -45,7 +45,7 @@ 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(pmhandle_t *handle, alpm_list_t *localpkgs, pmpkg_t *pkg, alpm_list_t *preferred, alpm_list_t **packages, alpm_list_t *remove, diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index c24b65d..079e683 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -77,11 +77,11 @@ static alpm_list_t *mount_point_list(pmhandle_t *handle) 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; @@ -126,7 +126,7 @@ static alpm_list_t *mount_point_list(pmhandle_t *handle) 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; } @@ -171,7 +171,7 @@ static int calculate_removed_size(pmhandle_t *handle, 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; } @@ -233,7 +233,7 @@ static int calculate_installed_size(pmhandle_t *handle, 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,7 +244,7 @@ static int calculate_installed_size(pmhandle_t *handle, 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)); handle->pm_errno = PM_ERR_LIBARCHIVE; break; @@ -269,12 +269,12 @@ int _alpm_check_diskspace(pmhandle_t *handle) numtargs = alpm_list_count(trans->add); 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; } @@ -321,7 +321,7 @@ int _alpm_check_diskspace(pmhandle_t *handle) 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) { @@ -330,12 +330,12 @@ int _alpm_check_diskspace(pmhandle_t *handle) 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; diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index fee5a98..46925a9 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -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); @@ -172,7 +171,7 @@ static int curl_download_internal(pmhandle_t *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); + _alpm_log(handle, PM_LOG_ERROR, _("url '%s' is invalid\n"), url); RET_ERR(handle, PM_ERR_SERVER_BAD_URL, -1); } @@ -212,7 +211,7 @@ static int curl_download_internal(pmhandle_t *handle, /* 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; } @@ -250,10 +249,10 @@ static int curl_download_internal(pmhandle_t *handle, } else if(handle->curlerr != CURLE_OK) { if(!errors_ok) { handle->pm_errno = PM_ERR_LIBCURL; - _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"), + _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); @@ -280,7 +279,7 @@ static int curl_download_internal(pmhandle_t *handle, if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) && !DOUBLE_EQ(bytes_dl, remote_size)) { handle->pm_errno = PM_ERR_RETRIEVE; - _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), + _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; } @@ -346,10 +345,10 @@ char SYMEXPORT *alpm_fetch_pkgurl(pmhandle_t *handle, const char *url) /* download the file */ 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 || @@ -364,11 +363,11 @@ char SYMEXPORT *alpm_fetch_pkgurl(pmhandle_t *handle, const char *url) 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); } diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c index 1d77382..13a216e 100644 --- a/lib/libalpm/group.c +++ b/lib/libalpm/group.c @@ -54,17 +54,14 @@ void _alpm_grp_free(pmgrp_t *grp) const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp) { - /* Sanity checks */ ASSERT(grp != NULL, return NULL); - return grp->name; } alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp) { - /* 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 888eae8..c2bad4c 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -298,7 +298,7 @@ int SYMEXPORT alpm_option_add_cachedir(pmhandle_t *handle, const char *cachedir) newcachedir = canonicalize_path(cachedir); handle->cachedirs = alpm_list_add(handle->cachedirs, newcachedir); - _alpm_log(PM_LOG_DEBUG, "backend option 'cachedir' = %s\n", newcachedir); + _alpm_log(handle, PM_LOG_DEBUG, "option 'cachedir' = %s\n", newcachedir); return 0; } @@ -362,7 +362,7 @@ int SYMEXPORT alpm_option_set_logfile(pmhandle_t *handle, 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; } @@ -379,7 +379,7 @@ int SYMEXPORT alpm_option_set_signaturedir(pmhandle_t *handle, const char *signa } 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; } diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 2b6385b..34c9762 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -86,7 +86,7 @@ int SYMEXPORT alpm_logaction(pmhandle_t *handle, 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(handle); diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h index 1fd66a6..105430c 100644 --- a/lib/libalpm/log.h +++ b/lib/libalpm/log.h @@ -22,7 +22,8 @@ #include "alpm.h" -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/pkghash.c b/lib/libalpm/pkghash.c index a22e6b5..9e98fcd 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. * @@ -66,7 +67,7 @@ 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; } diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index e1c78c4..a0b6c41 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -46,15 +46,17 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg) { - pmtrans_t *trans; const char *pkgname; + pmhandle_t *handle; + pmtrans_t *trans; /* Sanity checks */ ASSERT(pkg != NULL, return -1); - trans = pkg->handle->trans; - ASSERT(trans != NULL, RET_ERR(pkg->handle, PM_ERR_TRANS_NULL, -1)); + handle = pkg->handle; + trans = handle->trans; + ASSERT(trans != NULL, RET_ERR(handle, PM_ERR_TRANS_NULL, -1)); ASSERT(trans->state == STATE_INITIALIZED, - RET_ERR(pkg->handle, PM_ERR_TRANS_NOT_INITIALIZED, -1)); + RET_ERR(handle, PM_ERR_TRANS_NOT_INITIALIZED, -1)); pkgname = pkg->name; @@ -62,7 +64,7 @@ int SYMEXPORT alpm_remove_pkg(pmpkg_t *pkg) RET_ERR(pkg->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; @@ -79,12 +81,12 @@ static void remove_prepare_cascade(pmhandle_t *handle, alpm_list_t *lp) 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); } } @@ -113,7 +115,7 @@ static void remove_prepare_keep_needed(pmhandle_t *handle, alpm_list_t *lp) &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); } @@ -139,7 +141,7 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) 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_log(handle, PM_LOG_DEBUG, "finding removable dependencies\n"); _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL); } @@ -147,7 +149,7 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) 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"); + _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) { @@ -170,15 +172,15 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) } /* 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); } @@ -189,12 +191,12 @@ int _alpm_remove_prepare(pmhandle_t *handle, alpm_list_t **data) return 0; } -static int can_remove_file(const char *root, const char *path, +static int can_remove_file(pmhandle_t *handle, const char *path, alpm_list_t *skip) { char file[PATH_MAX+1]; - snprintf(file, PATH_MAX, "%s%s", root, path); + snprintf(file, PATH_MAX, "%s%s", handle->root, path); if(alpm_list_find_str(skip, file)) { /* return success because we will never actually remove this file */ @@ -206,7 +208,7 @@ static int can_remove_file(const char *root, const char *path, 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; } @@ -229,7 +231,7 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename, * 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; } @@ -239,23 +241,23 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename, * 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); @@ -266,17 +268,17 @@ static void unlink_file(pmhandle_t *handle, pmpkg_t *info, char *filename, 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_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)); } } @@ -291,7 +293,7 @@ int _alpm_upgraderemove_package(pmhandle_t *handle, alpm_list_t *files = alpm_pkg_get_files(oldpkg); const char *pkgname = alpm_pkg_get_name(oldpkg); - _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(handle->trans->flags & PM_TRANS_FLAG_DBONLY) { @@ -313,20 +315,20 @@ int _alpm_upgraderemove_package(pmhandle_t *handle, 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(handle->root, 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(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); @@ -338,15 +340,15 @@ int _alpm_upgraderemove_package(pmhandle_t *handle, 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); } @@ -379,7 +381,7 @@ int _alpm_remove_packages(pmhandle_t *handle) _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 */ @@ -394,15 +396,15 @@ int _alpm_remove_packages(pmhandle_t *handle) size_t filenum; for(lp = files; lp; lp = lp->next) { - if(!can_remove_file(handle->root, 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(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, @@ -434,15 +436,15 @@ int _alpm_remove_packages(pmhandle_t *handle) } /* 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, info) == -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(info)); } /* remove the package from the cache */ if(_alpm_db_remove_pkgfromcache(handle->db_local, info) == -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); } diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index ec465e7..8124e67 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -124,7 +124,7 @@ static int gpgme_init(pmhandle_t *handle) /* 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)); @@ -147,14 +147,14 @@ static int gpgme_init(pmhandle_t *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)); + _alpm_log(handle, PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err)); RET_ERR(handle, PM_ERR_GPGME, 1); } @@ -234,7 +234,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, 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)); @@ -288,7 +288,7 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, 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; @@ -297,42 +297,42 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, { 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) { handle->pm_errno = PM_ERR_SIG_UNKNOWN; - _alpm_log(PM_LOG_WARNING, _("File %s has a signature from an unknown key.\n"), + _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 */ handle->pm_errno = PM_ERR_SIG_INVALID; - _alpm_log(PM_LOG_ERROR, _("File %s has an invalid signature.\n"), + _alpm_log(handle, PM_LOG_ERROR, _("File %s has an invalid signature.\n"), path); ret = 1; } @@ -350,7 +350,7 @@ error: FREE(sigpath); FREE(decoded_sigdata); if(err != GPG_ERR_NO_ERROR) { - _alpm_log(PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err)); + _alpm_log(handle, PM_LOG_ERROR, _("GPGME error: %s\n"), gpgme_strerror(err)); RET_ERR(handle, PM_ERR_GPGME, -1); } return ret; @@ -371,7 +371,6 @@ int _alpm_gpgme_checksig(pmhandle_t *handle, const char *path, */ pgp_verify_t _alpm_db_get_sigverify_level(pmdb_t *db) { - if(db->pgp_verify != PM_PGP_VERIFY_UNKNOWN) { return db->pgp_verify; } else { diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index f8b93f1..81d4de2 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; @@ -96,12 +96,12 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) 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; } @@ -115,15 +115,15 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, 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->handle, spkg) || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { - _alpm_log(PM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"), + _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); } @@ -132,15 +132,15 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) /* check IgnorePkg/IgnoreGroup */ if(_alpm_pkg_should_ignore(spkg->handle, spkg) || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { - _alpm_log(PM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"), + _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); } } @@ -156,7 +156,7 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, int enable_downgrade) /* check IgnorePkg/IgnoreGroup */ if(_alpm_pkg_should_ignore(spkg->handle, spkg) || _alpm_pkg_should_ignore(lpkg->handle, lpkg)) { - _alpm_log(PM_LOG_WARNING, _("ignoring package replacement (%s-%s => %s-%s)\n"), + _alpm_log(handle, PM_LOG_WARNING, _("ignoring package replacement (%s-%s => %s-%s)\n"), lpkg->name, lpkg->version, spkg->name, spkg->version); continue; } @@ -173,11 +173,11 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, 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 */ @@ -189,7 +189,7 @@ int SYMEXPORT alpm_sync_sysupgrade(pmhandle_t *handle, 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); } @@ -257,6 +257,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; @@ -265,13 +266,13 @@ static int compute_download_size(pmpkg_t *newpkg) } fname = alpm_pkg_get_filename(newpkg); - ASSERT(fname != NULL, RET_ERR(newpkg->handle, PM_ERR_PKG_INVALID_NAME, -1)); - fpath = _alpm_filecache_find(newpkg->handle, fname); + ASSERT(fname != NULL, RET_ERR(handle, PM_ERR_PKG_INVALID_NAME, -1)); + fpath = _alpm_filecache_find(handle, fname); if(fpath) { FREE(fpath); size = 0; - } else if(newpkg->handle->usedelta) { + } else if(handle->usedelta) { off_t dltsize; off_t pkgsize = alpm_pkg_get_size(newpkg); @@ -281,10 +282,10 @@ static int compute_download_size(pmpkg_t *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; @@ -293,7 +294,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; @@ -320,7 +321,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 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) { @@ -387,7 +388,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 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); @@ -397,10 +398,10 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) /* 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"); + _alpm_log(handle, PM_LOG_DEBUG, "check targets vs targets\n"); deps = _alpm_innerconflicts(handle, trans->add); for(i = deps; i; i = i->next) { @@ -414,7 +415,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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 */ @@ -427,7 +428,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) rsync = sync1; sync = sync2; } else { - _alpm_log(PM_LOG_ERROR, _("unresolvable package conflicts detected\n")); + _alpm_log(handle, PM_LOG_ERROR, _("unresolvable package conflicts detected\n")); handle->pm_errno = PM_ERR_CONFLICTING_DEPS; ret = -1; if(data) { @@ -446,7 +447,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) _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); @@ -459,7 +460,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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"); + _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) { @@ -478,7 +479,7 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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); @@ -488,10 +489,10 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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")); + _alpm_log(handle, PM_LOG_ERROR, _("unresolvable package conflicts detected\n")); handle->pm_errno = PM_ERR_CONFLICTING_DEPS; ret = -1; if(data) { @@ -516,14 +517,14 @@ int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data) 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"); + _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) { @@ -626,7 +627,7 @@ static int apply_deltas(pmhandle_t *handle) 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); @@ -811,7 +812,7 @@ static int download_files(pmhandle_t *handle, 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(handle->pm_errno == 0) { handle->pm_errno = PM_ERR_RETRIEVE; @@ -879,7 +880,9 @@ int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data) /* 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); + _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) { @@ -915,7 +918,7 @@ int _alpm_sync_commit(pmhandle_t *handle, 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_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) { @@ -935,9 +938,9 @@ int _alpm_sync_commit(pmhandle_t *handle, 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"); + _alpm_log(handle, PM_LOG_DEBUG, "checking available disk space\n"); if(_alpm_check_diskspace(handle) == -1) { - _alpm_log(PM_LOG_ERROR, "%s\n", _("not enough free disk space")); + _alpm_log(handle, PM_LOG_ERROR, "%s\n", _("not enough free disk space")); return -1; } @@ -946,18 +949,18 @@ int _alpm_sync_commit(pmhandle_t *handle, 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(handle) == -1) { - _alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n")); + _alpm_log(handle, PM_LOG_ERROR, _("could not commit removal transaction\n")); return -1; } } /* install targets */ - _alpm_log(PM_LOG_DEBUG, "installing packages\n"); + _alpm_log(handle, PM_LOG_DEBUG, "installing packages\n"); if(_alpm_upgrade_packages(handle) == -1) { - _alpm_log(PM_LOG_ERROR, _("could not commit transaction\n")); + _alpm_log(handle, PM_LOG_ERROR, _("could not commit transaction\n")); return -1; } diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 564b06e..a95280c 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -125,7 +125,7 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags, /* 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); _alpm_trans_free(trans); @@ -283,7 +283,7 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle) /* unlock db */ if(!nolock_flag) { if(remove_lock(handle)) { - _alpm_log(PM_LOG_WARNING, _("could not remove lock file %s\n"), + _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)); @@ -350,7 +350,7 @@ int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn, 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; } @@ -361,7 +361,7 @@ int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn, } 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; @@ -375,7 +375,7 @@ int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn, } } 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; } } @@ -399,13 +399,13 @@ int _alpm_runscriptlet(pmhandle_t *handle, 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(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; diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 2ad0833..9a8f06d 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -262,7 +262,7 @@ int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix, 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(handle, PM_ERR_PKG_OPEN, 1); } @@ -271,14 +271,14 @@ int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix, /* 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"), + _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), prefix, strerror(errno)); ret = 1; goto cleanup; @@ -313,7 +313,7 @@ int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix, } continue; } else { - _alpm_log(PM_LOG_DEBUG, "extracting: %s\n", entryname); + _alpm_log(handle, PM_LOG_DEBUG, "extracting: %s\n", entryname); } } @@ -321,10 +321,10 @@ int _alpm_unpack(pmhandle_t *handle, const char *archive, const char *prefix, 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; @@ -339,7 +339,7 @@ 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"), + _alpm_log(handle, PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno)); } return ret; @@ -429,26 +429,26 @@ int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[]) /* 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(handle->root) != 0) { - _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), + _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", + _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; } @@ -456,7 +456,7 @@ int _alpm_run_chroot(pmhandle_t *handle, 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; } @@ -507,7 +507,7 @@ int _alpm_run_chroot(pmhandle_t *handle, 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; } @@ -515,14 +515,14 @@ int _alpm_run_chroot(pmhandle_t *handle, 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; } } @@ -530,7 +530,7 @@ int _alpm_run_chroot(pmhandle_t *handle, 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; @@ -540,7 +540,7 @@ 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", handle->root); if(access(line, F_OK) == 0) { @@ -579,7 +579,7 @@ char *_alpm_filecache_find(pmhandle_t *handle, const char *filename) 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; } } @@ -603,17 +603,17 @@ const char *_alpm_filecache_setup(pmhandle_t *handle) 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(PM_LOG_DEBUG, "skipping cachedir: %s\n", cachedir); + _alpm_log(handle, PM_LOG_DEBUG, "skipping cachedir: %s\n", cachedir); } } @@ -621,8 +621,8 @@ const char *_alpm_filecache_setup(pmhandle_t *handle) tmp = alpm_list_add(NULL, "/tmp/"); alpm_option_set_cachedirs(handle, tmp); alpm_list_free(tmp); - _alpm_log(PM_LOG_DEBUG, "using cachedir: %s\n", "/tmp/"); - _alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n")); + _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/"; } @@ -715,7 +715,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; } diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index b289531..e5fefe9 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -49,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) @@ -62,11 +62,11 @@ #define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0) #define RET_ERR_VOID(handle, err) do { (handle)->pm_errno = (err); \ - _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(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(handle, err, ret) do { (handle)->pm_errno = (err); \ - _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(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) -- 1.7.5.2
Signed-off-by: Dan McGee <dan@archlinux.org> --- lib/libalpm/alpm.c | 8 -------- lib/libalpm/handle.c | 4 ---- lib/libalpm/log.c | 3 --- 3 files changed, 0 insertions(+), 15 deletions(-) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 86b1619..5d475ce 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -34,9 +34,6 @@ #include "log.h" #include "util.h" -/* Globals */ -extern pmhandle_t *handle; - /** \addtogroup alpm_interface Interface Functions * @brief Functions to initialize and release libalpm * @{ @@ -86,8 +83,6 @@ pmhandle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath, myhandle->curl = curl_easy_init(); #endif - /* TODO temporary until global var removed */ - handle = myhandle; return myhandle; cleanup: @@ -123,9 +118,6 @@ int SYMEXPORT alpm_release(pmhandle_t *myhandle) } _alpm_handle_free(myhandle); - myhandle = NULL; - /* TODO temporary until global var removed */ - handle = NULL; #ifdef HAVE_LIBCURL curl_global_cleanup(); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index c2bad4c..898ce41 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -37,9 +37,6 @@ #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; @@ -87,7 +84,6 @@ void _alpm_handle_free(pmhandle_t *handle) FREELIST(handle->ignorepkg); FREELIST(handle->ignoregrp); FREE(handle); - } alpm_cb_log SYMEXPORT alpm_option_get_logcb(pmhandle_t *handle) diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index 34c9762..91bcb82 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -30,9 +30,6 @@ #include "util.h" #include "alpm.h" -/* global handle variable */ -extern pmhandle_t *handle; - /** \addtogroup alpm_log Logging Functions * @brief Functions to log using libalpm * @{ -- 1.7.5.2
Even though we currently don't use it here in the backend, we might as well pass it in since we used it earlier. Signed-off-by: Dan McGee <dan@archlinux.org> --- src/pacman/remove.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 5993ab3..59698e7 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -121,11 +121,11 @@ int pacman_remove(alpm_list_t *targets) depstring); free(depstring); } - FREELIST(data); break; default: break; } + FREELIST(data); retval = 1; goto cleanup; } @@ -165,12 +165,14 @@ int pacman_remove(alpm_list_t *targets) goto cleanup; } - if(alpm_trans_commit(config->handle, NULL) == -1) { + if(alpm_trans_commit(config->handle, &data) == -1) { pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"), alpm_strerror(alpm_errno(config->handle))); retval = 1; } + FREELIST(data); + /* Step 4: release transaction resources */ cleanup: if(trans_release() == -1) { -- 1.7.5.2
On Tue, Jun 7, 2011 at 4:36 PM, Dan McGee <dan@archlinux.org> wrote:
This is a bitch of a diffstat, unfortunately, and the patches aren't all that fun to look through. I have it pushed to my repo as alpm-cleanups if you'd rather grab it there. The bright side is it should successfully build and test after each patch as long as they are applied in the order sent here (or in my repo).
Comments/suggestion/feedback welcome. Once these are applied, I think our API makes a lot more sense from a consumer standpoint as we have a single object, tracked by the "client", tracking all state in the library rather than the state being held in a global variable in the backend library.
This patch series (and the previous one sent and now applied) makes it *much* easier for the next few patches, which will ensure DBs are signature-checked and verified at the right time, and at a time all clients expect them to be checked so error codes can be checked.
Look at the bright side- the overall line differential is at least negative!
Obviously as I said tests did pass at all stages of this patch sequence, but if it makes people feel any better, it also did a successful update on my live system as follows, so rest assured if you want to take these for a test drive your data should be safe. The only "bug" I noticed was running --version spits out a "error: error releasing alpm library" line which I'm fixing now on my working branch. -Dan Targets (54): gcc-libs-4.6.0-6 icu-4.8-1 boost-libs-1.46.1-3 boost-1.46.1-3 chromium-12.0.742.91-1 gnutls-2.12.6.1-1 libcups-1.4.6-3 cups-1.4.6-3 hunspell-1.3.2-1 enchant-1.6.0-2 libpurple-2.8.0-1 finch-2.8.0-1 lib32-gcc-libs-4.6.0-6 nspluginwrapper-1.4.2-1 flashplugin-10.3.181.22-1 gcc-4.6.0-6 glib2-2.28.8-1 icon-naming-utils-0.8.90-2 gnome-icon-theme-3.0.0-2 gtk3-3.0.11-1 libdvbpsi-0.2.0-1 libreoffice-sdk-3.4.0-2 libwebkit-1.4.1-1 man-db-2.6.0.2-2 mercurial-1.8.4-1 php-5.3.6-4 php-apache-5.3.6-4 php-cgi-5.3.6-4 php-curl-5.3.6-4 php-gd-5.3.6-4 php-mcrypt-5.3.6-4 php-pear-5.3.6-4 pidgin-2.8.0-1 python-egenix-mx-base-3.2.0-1 python-sqlalchemy-0.7.1-1 qt-4.7.3-2 raptor-2.0.3-1 subversion-1.6.17-2 telepathy-glib-0.14.7-1 thunderbird-3.1.10-3 v4l-utils-0.8.4-1 vigra-1.7.1-2 vlc-1.1.10-1 vte-common-0.28.0-2 vte-0.28.0-2 wireshark-cli-1.4.7-2 wireshark-gtk-1.4.7-2 xfce4-dev-tools-4.8.0-2 xfce4-xkb-plugin-0.5.4.1-1 xorg-xlsclients-1.1.2-1 xterm-270-1 xulrunner-2.0.1-2 xvidcore-1.3.2-1 zope-interface-3.6.3-1 Total Download Size: 186.92 MiB Total Installed Size: 992.26 MiB Net Upgrade Size: -16.43 MiB
On Tue 07 June 2011 at 16:36 -0500, Dan McGee wrote:
This is a bitch of a diffstat, unfortunately, and the patches aren't all that fun to look through. I have it pushed to my repo as alpm-cleanups if you'd rather grab it there. The bright side is it should successfully build and test after each patch as long as they are applied in the order sent here (or in my repo).
Comments/suggestion/feedback welcome. Once these are applied, I think our API makes a lot more sense from a consumer standpoint as we have a single object, tracked by the "client", tracking all state in the library rather than the state being held in a global variable in the backend library.
This patch series (and the previous one sent and now applied) makes it *much* easier for the next few patches, which will ensure DBs are signature-checked and verified at the right time, and at a time all clients expect them to be checked so error codes can be checked.
It seems a bit odd to me that packages acquired a handle member in the process: databases are intrinsically stateful, or at least related to a state, since they have paths, locks, and are concerned by transactions. But packages are twofold: - sometimes they come from a database: they at least inherit a global state through alpm_pkg_get_db(pkg)->handle. - sometimes they come from a file: then things are very different: the user must free the structure when finished with alpm_pkg_free(), and the package itself is much more pure: it doesn't have a related DBPath, no associated root, no options, just a file path. I support the idea that if a package is loaded from a file, there is not really a reason why it should be linked to any handle. The downside of that is that catching error codes would need some modifications in related functions, but it doesn't look like package functions throw many error codes. Another reason why it bothers me is that all transaction functions need a handle: alpm_trans*, alpm_sync_sysupgrade, but not alpm_add_pkg nor alpm_remove_pkg. One may argue that having a handle argument would be redundant with the pkg->handle thing, but that's a case where it seems really logical to me, and more consistent with the rest of the API, to declare explicitly the handle with holds the transaction where a package is added/removed. The signature alpm_add_pkg(pmpkg_t *pkg) would require some introspection to detect where the package will be installed. And actually, it really seems like it is *impossible* to know where alpm_add_pkg() will install the package, since the current API does not provide the necessary alpm_pkg_get_handle() to do so (but we of course could provide such a function: do we need it?) -- Rémy.
On Wed, Jun 8, 2011 at 1:28 PM, Rémy Oudompheng <remyoudompheng@gmail.com> wrote:
On Tue 07 June 2011 at 16:36 -0500, Dan McGee wrote:
This is a bitch of a diffstat, unfortunately, and the patches aren't all that fun to look through. I have it pushed to my repo as alpm-cleanups if you'd rather grab it there. The bright side is it should successfully build and test after each patch as long as they are applied in the order sent here (or in my repo).
Comments/suggestion/feedback welcome. Once these are applied, I think our API makes a lot more sense from a consumer standpoint as we have a single object, tracked by the "client", tracking all state in the library rather than the state being held in a global variable in the backend library.
This patch series (and the previous one sent and now applied) makes it *much* easier for the next few patches, which will ensure DBs are signature-checked and verified at the right time, and at a time all clients expect them to be checked so error codes can be checked.
It seems a bit odd to me that packages acquired a handle member in the process: databases are intrinsically stateful, or at least related to a state, since they have paths, locks, and are concerned by transactions.
But packages are twofold: - sometimes they come from a database: they at least inherit a global state through alpm_pkg_get_db(pkg)->handle. - sometimes they come from a file: then things are very different: the user must free the structure when finished with alpm_pkg_free(), and the package itself is much more pure: it doesn't have a related DBPath, no associated root, no options, just a file path. This last point applies iff it is loaded from a file- you stated it but just need to make this point clear before the next bit.
I support the idea that if a package is loaded from a file, there is not really a reason why it should be linked to any handle. The downside of that is that catching error codes would need some modifications in related functions, but it doesn't look like package functions throw many error codes.
The following needs to be addressed, and I am in no rush to do so: * alpm_pkg_compute_requiredby() uses the local DB for PKG_FROM_FILE packages, calls find_requiredby(), which calls db_get_pkgcache()... you get the point, this one needs either a handle passed in, or we need to keep the handle off the package. * _alpm_pkg_should_ignore() * commit_single_pkg() was using newpkg->handle, where newpkg was the PKG_FROM_FILE being installed, but this is unnecessary as we have a handle anyway; fixed. * The _package_changelog_*() implementation sets PM_ERR_LIBARCHIVE. Without breaking the abstraction I'm not sure how this one can be fixed. * alpm_pkg_check_pgp_signature() - heavy errno/logging deps here. * alpm_sync_newversion() - errno/logging deps here. When loading a package, even from a file, we definitely use the handle a lot. * parse_descfile() uses handle for logging purposes. Looking at them, they are all DEBUG level now but several seem like they should be WARNING or even ERROR level messages. * _alpm_pkg_load_internal() and alpm_pkg_load(). Oh my. It looks like most usages here are pm_errno and logging. Even though we could add a *pm_errno arg, logging is a different story. And to me, saying "you need to provide a handle but the resulting pkg won't be linked to it" just makes this confusing. Can I turn your question around now that I've pointed out a few reasons why not having a handle attached to every package would be a P in the A? What benefit would having a package without a handle be?
Another reason why it bothers me is that all transaction functions need a handle: alpm_trans*, alpm_sync_sysupgrade, but not alpm_add_pkg nor alpm_remove_pkg. I have no problem with adding a handle to these two methods- I just didn't because it seemed prudent to only change the API signatures of methods if necessary. So I am fine with adding this, regardless of anything else. My original hackjob before I split it into a patch set did in fact add a handle parameter.
One may argue that having a handle argument would be redundant with the pkg->handle thing, but that's a case where it seems really logical to me, and more consistent with the rest of the API, to declare explicitly the handle with holds the transaction where a package is added/removed. The signature alpm_add_pkg(pmpkg_t *pkg) would require some introspection to detect where the package will be installed.
Even with this all said, you would run into some rather catastrophic failures if you starting mixing packages from different handles. We could definitely add a few more asserts() to prevent such problems.
And actually, it really seems like it is *impossible* to know where alpm_add_pkg() will install the package, since the current API does not provide the necessary alpm_pkg_get_handle() to do so (but we of course could provide such a function: do we need it?) It's not impossible, given that if a package was loaded using a specific handle, it will be installed using that handle. The only caveat is that the frontend application needs to keep track of this. Not sure if we need it.
-Dan
participants (4)
-
Allan McRae
-
Dan McGee
-
Dan McGee
-
Rémy Oudompheng