[pacman-dev] [PATCH 10/10] Remove global handle dependencies from sync/upgrade paths
Dan McGee
dan at archlinux.org
Fri Jun 3 14:21:48 EDT 2011
This kills a lot more global handle business off. sync.c still requires
the handle declaration for one reference that can't be changed yet; it
will be removed in a future patch which isolates all of the necesary API
changes.
Signed-off-by: Dan McGee <dan at archlinux.org>
---
lib/libalpm/add.c | 53 ++++++++++++++++++++---------------------------
lib/libalpm/add.h | 2 +-
lib/libalpm/conflict.c | 16 ++++++--------
lib/libalpm/conflict.h | 4 +-
lib/libalpm/sync.c | 38 ++++++++++++++++------------------
lib/libalpm/sync.h | 4 +-
lib/libalpm/trans.c | 4 +-
7 files changed, 55 insertions(+), 66 deletions(-)
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 500fbde..94ab112 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -47,9 +47,6 @@
#include "remove.h"
#include "handle.h"
-/* global handle variable */
-extern pmhandle_t *handle;
-
/** Add a package to the transaction. */
int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
{
@@ -60,11 +57,10 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
/* Sanity checks */
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- trans = handle->trans;
+ 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));
- db_local = handle->db_local;
+ db_local = pkg->handle->db_local;
pkgname = pkg->name;
pkgver = pkg->version;
@@ -132,9 +128,8 @@ static int perform_extraction(struct archive *archive,
return 0;
}
-static int extract_single_file(struct archive *archive,
- struct archive_entry *entry, pmpkg_t *newpkg, pmpkg_t *oldpkg,
- pmtrans_t *trans, pmdb_t *db)
+static int extract_single_file(pmhandle_t *handle, struct archive *archive,
+ struct archive_entry *entry, pmpkg_t *newpkg, pmpkg_t *oldpkg)
{
const char *entryname;
mode_t entrymode;
@@ -152,12 +147,12 @@ static int extract_single_file(struct archive *archive,
if(strcmp(entryname, ".INSTALL") == 0) {
/* the install script goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(strcmp(entryname, ".CHANGELOG") == 0) {
/* the changelog goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/changelog",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(*entryname == '.') {
/* for now, ignore all files starting with '.' that haven't
@@ -426,7 +421,7 @@ static int extract_single_file(struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "extracting %s\n", filename);
}
- if(trans->flags & PM_TRANS_FLAG_FORCE) {
+ if(handle->trans->flags & PM_TRANS_FLAG_FORCE) {
/* if FORCE was used, unlink() each file (whether it's there
* or not) before extracting. This prevents the old "Text file busy"
* error that crops up if forcing a glibc or pacman upgrade. */
@@ -467,15 +462,15 @@ static int extract_single_file(struct archive *archive,
return errors;
}
-static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
- size_t pkg_count, pmtrans_t *trans, pmdb_t *db)
+static int commit_single_pkg(pmhandle_t *handle, pmpkg_t *newpkg,
+ size_t pkg_current, size_t pkg_count)
{
int i, ret = 0, errors = 0;
char scriptlet[PATH_MAX+1];
int is_upgrade = 0;
pmpkg_t *oldpkg = NULL;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmdb_t *db = handle->db_local;
+ pmtrans_t *trans = handle->trans;
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
_alpm_db_path(db), alpm_pkg_get_name(newpkg),
@@ -501,7 +496,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle, newpkg->origin_data.file,
+ _alpm_runscriptlet(newpkg->handle, newpkg->origin_data.file,
"pre_upgrade", newpkg->version, oldpkg->version);
}
} else {
@@ -513,7 +508,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_install scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle, newpkg->origin_data.file,
+ _alpm_runscriptlet(newpkg->handle, newpkg->origin_data.file,
"pre_install", newpkg->version, NULL);
}
}
@@ -527,7 +522,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(oldpkg) {
/* set up fake remove transaction */
- if(_alpm_upgraderemove_package(handle, oldpkg, newpkg) == -1) {
+ if(_alpm_upgraderemove_package(newpkg->handle, oldpkg, newpkg) == -1) {
pm_errno = PM_ERR_TRANS_ABORT;
ret = -1;
goto cleanup;
@@ -577,8 +572,9 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
}
/* libarchive requires this for extracting hard links */
- if(chdir(handle->root) != 0) {
- _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), handle->root, strerror(errno));
+ if(chdir(newpkg->handle->root) != 0) {
+ _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
+ newpkg->handle->root, strerror(errno));
ret = -1;
goto cleanup;
}
@@ -622,8 +618,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
}
/* extract the next file from the archive */
- errors += extract_single_file(archive, entry, newpkg, oldpkg,
- trans, db);
+ errors += extract_single_file(newpkg->handle, archive, entry, newpkg, oldpkg);
}
archive_read_finish(archive);
@@ -681,11 +676,11 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(alpm_pkg_has_scriptlet(newpkg)
&& !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
if(is_upgrade) {
- _alpm_runscriptlet(handle, scriptlet, "post_upgrade",
+ _alpm_runscriptlet(newpkg->handle, scriptlet, "post_upgrade",
alpm_pkg_get_version(newpkg),
oldpkg ? alpm_pkg_get_version(oldpkg) : NULL);
} else {
- _alpm_runscriptlet(handle, scriptlet, "post_install",
+ _alpm_runscriptlet(newpkg->handle, scriptlet, "post_install",
alpm_pkg_get_version(newpkg), NULL);
}
}
@@ -701,14 +696,12 @@ cleanup:
return ret;
}
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
+int _alpm_upgrade_packages(pmhandle_t *handle)
{
size_t pkg_count, pkg_current;
int skip_ldconfig = 0, ret = 0;
alpm_list_t *targ;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ pmtrans_t *trans = handle->trans;
if(trans->add == NULL) {
return 0;
@@ -724,7 +717,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
}
pmpkg_t *newpkg = (pmpkg_t *)targ->data;
- if(commit_single_pkg(newpkg, pkg_current, pkg_count, trans, db)) {
+ if(commit_single_pkg(handle, newpkg, pkg_current, pkg_count)) {
/* something screwed up on the commit, abort the trans */
trans->state = STATE_INTERRUPTED;
pm_errno = PM_ERR_TRANS_ABORT;
diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h
index afc7be2..1baab8d 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/add.h
@@ -24,7 +24,7 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
+int _alpm_upgrade_packages(pmhandle_t *handle);
#endif /* _ALPM_ADD_H */
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index ae34785..8921470 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -40,9 +40,6 @@
#include "log.h"
#include "deps.h"
-/* global handle variable */
-extern pmhandle_t *handle;
-
pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2,
const char *reason)
{
@@ -308,7 +305,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
char abspath[PATH_MAX];
DIR *dir;
- snprintf(abspath, PATH_MAX, "%s%s", handle->root, dirpath);
+ snprintf(abspath, PATH_MAX, "%s%s", pkg->handle->root, dirpath);
dir = opendir(abspath);
if(dir == NULL) {
return 1;
@@ -320,7 +317,7 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
continue;
}
snprintf(path, PATH_MAX, "%s/%s", dirpath, name);
- snprintf(abspath, PATH_MAX, "%s%s", handle->root, path);
+ snprintf(abspath, PATH_MAX, "%s%s", pkg->handle->root, path);
if(stat(abspath, &sbuf) != 0) {
continue;
}
@@ -347,14 +344,15 @@ static int dir_belongsto_pkg(char *dirpath, pmpkg_t *pkg)
/* Find file conflicts that may occur during the transaction with two checks:
* 1: check every target against every target
* 2: check every target against the filesystem */
-alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
+alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
alpm_list_t *upgrade, alpm_list_t *remove)
{
alpm_list_t *i, *j, *conflicts = NULL;
size_t numtargs = alpm_list_count(upgrade);
size_t current;
+ pmtrans_t *trans = handle->trans;
- if(db == NULL || upgrade == NULL || trans == NULL) {
+ if(!upgrade) {
return NULL;
}
@@ -402,7 +400,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
/* CHECK 2: check every target against the filesystem */
_alpm_log(PM_LOG_DEBUG, "searching for filesystem conflicts: %s\n", p1->name);
- dbpkg = _alpm_db_get_pkgfromcache(db, p1->name);
+ dbpkg = _alpm_db_get_pkgfromcache(handle->db_local, p1->name);
/* Do two different checks here. If the package is currently installed,
* then only check files that are new in the new package. If the package
@@ -456,7 +454,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
if(!p2 || strcmp(p1->name, p2->name) == 0) {
continue;
}
- pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(db, p2->name);
+ pmpkg_t *localp2 = _alpm_db_get_pkgfromcache(handle->db_local, p2->name);
/* localp2->files will be removed (target conflicts are handled by CHECK 1) */
if(localp2 && alpm_list_find_str(alpm_pkg_get_files(localp2), filestr)) {
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 418d3f6..d00314d 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -42,8 +42,8 @@ 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_outerconflicts(pmdb_t *db, alpm_list_t *packages);
-alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
- alpm_list_t *upgrade, alpm_list_t *remove);
+alpm_list_t *_alpm_db_find_fileconflicts(pmhandle_t *handle,
+ alpm_list_t *upgrade, alpm_list_t *remove);
void _alpm_fileconflict_free(pmfileconflict_t *conflict);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index f0d9b91..7a33bc9 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -233,7 +233,7 @@ alpm_list_t SYMEXPORT *alpm_find_grp_pkgs(alpm_list_t *dbs,
if(_alpm_pkg_should_ignore(pkg)) {
ignorelist = alpm_list_add(ignorelist, pkg);
int install = 0;
- QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
+ QUESTION(db->handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg,
NULL, NULL, &install);
if(!install)
continue;
@@ -270,7 +270,7 @@ static int compute_download_size(pmpkg_t *newpkg)
if(fpath) {
FREE(fpath);
size = 0;
- } else if(handle->usedelta) {
+ } else if(newpkg->handle->usedelta) {
off_t dltsize;
off_t pkgsize = alpm_pkg_get_size(newpkg);
@@ -300,16 +300,15 @@ static int compute_download_size(pmpkg_t *newpkg)
return 0;
}
-int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data)
+int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data)
{
alpm_list_t *deps = NULL;
alpm_list_t *unresolvable = NULL;
alpm_list_t *i, *j;
alpm_list_t *remove = NULL;
int ret = 0;
-
- ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmtrans_t *trans = handle->trans;
+ pmdb_t *db_local = handle->db_local;
if(data) {
*data = NULL;
@@ -340,7 +339,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
building up a list of packages which could not be resolved. */
for(i = trans->add; i; i = i->next) {
pmpkg_t *pkg = i->data;
- if(_alpm_resolvedeps(localpkgs, dbs_sync, pkg, trans->add,
+ if(_alpm_resolvedeps(localpkgs, handle->dbs_sync, pkg, trans->add,
&resolved, remove, data) == -1) {
unresolvable = alpm_list_add(unresolvable, pkg);
}
@@ -725,7 +724,7 @@ static int validate_deltas(pmtrans_t *trans, alpm_list_t *deltas,
return ret;
}
-static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
+static int download_files(pmhandle_t *handle, alpm_list_t **deltas)
{
const char *cachedir;
alpm_list_t *i, *j;
@@ -733,7 +732,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
int errors = 0;
cachedir = _alpm_filecache_setup();
- trans->state = STATE_DOWNLOADING;
+ handle->trans->state = STATE_DOWNLOADING;
/* Total progress - figure out the total download size if required to
* pass to the callback. This function is called once, and it is up to the
@@ -741,7 +740,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
if(handle->totaldlcb) {
off_t total_size = (off_t)0;
/* sum up the download size for each package and store total */
- for(i = trans->add; i; i = i->next) {
+ for(i = handle->trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
total_size += spkg->download_size;
}
@@ -752,7 +751,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
for(i = handle->dbs_sync; i; i = i->next) {
pmdb_t *current = i->data;
- for(j = trans->add; j; j = j->next) {
+ for(j = handle->trans->add; j; j = j->next) {
pmpkg_t *spkg = j->data;
if(spkg->origin != PKG_FROM_FILE && current == spkg->origin_data.db) {
@@ -781,7 +780,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
}
if(files) {
- EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
+ EVENT(handle->trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
for(j = files; j; j = j->next) {
const char *filename = j->data;
alpm_list_t *server;
@@ -819,7 +818,7 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
}
}
- for(j = trans->add; j; j = j->next) {
+ for(j = handle->trans->add; j; j = j->next) {
pmpkg_t *pkg = j->data;
pkg->infolevel &= ~INFRQ_DSIZE;
pkg->download_size = 0;
@@ -832,16 +831,15 @@ static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
return 0;
}
-int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
+int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data)
{
alpm_list_t *i;
alpm_list_t *deltas = NULL;
size_t numtargs, current = 0, replaces = 0;
int errors;
+ pmtrans_t *trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
- if(download_files(trans, &deltas)) {
+ if(download_files(handle, &deltas)) {
alpm_list_free(deltas);
return -1;
}
@@ -915,8 +913,8 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for file conflicts\n");
- alpm_list_t *conflict = _alpm_db_find_fileconflicts(db_local, trans,
- trans->add, trans->remove);
+ alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle,
+ trans->add, trans->remove);
if(conflict) {
if(data) {
*data = conflict;
@@ -955,7 +953,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
/* install targets */
_alpm_log(PM_LOG_DEBUG, "installing packages\n");
- if(_alpm_upgrade_packages(trans, handle->db_local) == -1) {
+ if(_alpm_upgrade_packages(handle) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not commit transaction\n"));
return -1;
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index 90a2d40..3049dd2 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -24,8 +24,8 @@
#include "alpm.h"
-int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data);
-int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
+int _alpm_sync_prepare(pmhandle_t *handle, alpm_list_t **data);
+int _alpm_sync_commit(pmhandle_t *handle, alpm_list_t **data);
#endif /* _ALPM_SYNC_H */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 8e019cc..58bcc38 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -202,7 +202,7 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
return -1;
}
} else {
- if(_alpm_sync_prepare(trans, handle->db_local, handle->dbs_sync, data) == -1) {
+ if(_alpm_sync_prepare(handle, data) == -1) {
/* pm_errno is set by _alpm_sync_prepare() */
return -1;
}
@@ -241,7 +241,7 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
return -1;
}
} else {
- if(_alpm_sync_commit(trans, handle->db_local, data) == -1) {
+ if(_alpm_sync_commit(handle, data) == -1) {
/* pm_errno is set by _alpm_sync_commit() */
return -1;
}
--
1.7.5.2
More information about the pacman-dev
mailing list