summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/add.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/add.c')
-rw-r--r--lib/libalpm/add.c116
1 files changed, 50 insertions, 66 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index ad6ef17e..59d539c6 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -44,15 +44,10 @@
#include "backup.h"
#include "package.h"
#include "db.h"
-#include "conflict.h"
-#include "deps.h"
#include "remove.h"
#include "handle.h"
-/** Add a package to the transaction.
- * @param pkg the package to add
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
+/** Add a package to the transaction. */
int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
{
const char *pkgname, *pkgver;
@@ -60,19 +55,15 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
pmdb_t *db_local;
pmpkg_t *local;
- ALPM_LOG_FUNC;
-
/* Sanity checks */
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- 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));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- db_local = handle->db_local;
+ db_local = pkg->handle->db_local;
- pkgname = alpm_pkg_get_name(pkg);
- pkgver = alpm_pkg_get_version(pkg);
+ pkgname = pkg->name;
+ pkgver = pkg->version;
_alpm_log(PM_LOG_DEBUG, "adding package '%s'\n", pkgname);
@@ -91,7 +82,7 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
/* with the NEEDED flag, packages up to date are not reinstalled */
_alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
localpkgname, localpkgver);
- return(0);
+ return 0;
} else if(!(trans->flags & PM_TRANS_FLAG_DOWNLOADONLY)) {
_alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- reinstalling\n"),
localpkgname, localpkgver);
@@ -105,11 +96,11 @@ int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg)
/* add the package to the transaction */
pkg->reason = PM_PKG_REASON_EXPLICIT;
- _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
+ _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction add list\n",
pkgname, pkgver);
trans->add = alpm_list_add(trans->add, pkg);
- return(0);
+ return 0;
}
static int perform_extraction(struct archive *archive,
@@ -132,14 +123,13 @@ static int perform_extraction(struct archive *archive,
origname, archive_error_string(archive));
alpm_logaction("error: could not extract %s (%s)\n",
origname, archive_error_string(archive));
- return(1);
+ return 1;
}
- return(0);
+ 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;
@@ -157,19 +147,19 @@ static int extract_single_file(struct archive *archive,
if(strcmp(entryname, ".INSTALL") == 0) {
/* the install script goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(strcmp(entryname, ".CHANGELOG") == 0) {
/* the changelog goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/changelog",
- _alpm_db_path(db), newpkg->name, newpkg->version);
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
archive_entry_set_perm(entry, 0644);
} else if(*entryname == '.') {
/* for now, ignore all files starting with '.' that haven't
* already been handled (for future possibilities) */
_alpm_log(PM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
} else {
/* build the new entryname relative to handle->root */
snprintf(filename, PATH_MAX, "%s%s", handle->root, entryname);
@@ -182,7 +172,7 @@ static int extract_single_file(struct archive *archive,
alpm_logaction("note: %s is in NoExtract, skipping extraction\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ return 0;
}
/* Check for file existence. This is one of the more crucial parts
@@ -226,13 +216,13 @@ static int extract_single_file(struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ 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"),
entryname);
archive_read_data_skip(archive);
- return(1);
+ return 1;
}
} else if(S_ISLNK(lsbuf.st_mode) && S_ISDIR(entrymode)) {
/* case 9: existing symlink, dir in package */
@@ -241,13 +231,13 @@ static int extract_single_file(struct archive *archive,
_alpm_log(PM_LOG_DEBUG, "extract: skipping symlink overwrite of %s\n",
entryname);
archive_read_data_skip(archive);
- return(0);
+ 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"),
entryname);
archive_read_data_skip(archive);
- return(1);
+ return 1;
}
} else if(S_ISREG(lsbuf.st_mode) && S_ISDIR(entrymode)) {
/* case 6: trying to overwrite file with dir */
@@ -299,7 +289,7 @@ static int extract_single_file(struct archive *archive,
/* error */
FREE(hash_orig);
FREE(entryname_orig);
- return(1);
+ return 1;
}
hash_local = alpm_compute_md5sum(filename);
@@ -431,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. */
@@ -442,7 +432,7 @@ static int extract_single_file(struct archive *archive,
if(ret == 1) {
/* error */
FREE(entryname_orig);
- return(1);
+ return 1;
}
/* calculate an hash if this is in newpkg's backup */
@@ -469,20 +459,18 @@ static int extract_single_file(struct archive *archive,
}
}
FREE(entryname_orig);
- return(errors);
+ 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;
-
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ pmdb_t *db = handle->db_local;
+ pmtrans_t *trans = handle->trans;
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
_alpm_db_path(db), alpm_pkg_get_name(newpkg),
@@ -508,8 +496,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, newpkg->origin_data.file,
- "pre_upgrade", newpkg->version, oldpkg->version, trans);
+ _alpm_runscriptlet(newpkg->handle, newpkg->origin_data.file,
+ "pre_upgrade", newpkg->version, oldpkg->version);
}
} else {
is_upgrade = 0;
@@ -520,8 +508,8 @@ 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->root, newpkg->origin_data.file,
- "pre_install", newpkg->version, NULL, trans);
+ _alpm_runscriptlet(newpkg->handle, newpkg->origin_data.file,
+ "pre_install", newpkg->version, NULL);
}
}
@@ -534,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(oldpkg, newpkg, trans) == -1) {
+ if(_alpm_upgraderemove_package(newpkg->handle, oldpkg, newpkg) == -1) {
pm_errno = PM_ERR_TRANS_ABORT;
ret = -1;
goto cleanup;
@@ -559,7 +547,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
_alpm_log(PM_LOG_DEBUG, "extracting files\n");
- if ((archive = archive_read_new()) == NULL) {
+ if((archive = archive_read_new()) == NULL) {
pm_errno = PM_ERR_LIBARCHIVE;
ret = -1;
goto cleanup;
@@ -584,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;
}
@@ -629,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);
@@ -688,12 +676,12 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(alpm_pkg_has_scriptlet(newpkg)
&& !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
if(is_upgrade) {
- _alpm_runscriptlet(handle->root, scriptlet, "post_upgrade",
+ _alpm_runscriptlet(newpkg->handle, scriptlet, "post_upgrade",
alpm_pkg_get_version(newpkg),
- oldpkg ? alpm_pkg_get_version(oldpkg) : NULL, trans);
+ oldpkg ? alpm_pkg_get_version(oldpkg) : NULL);
} else {
- _alpm_runscriptlet(handle->root, scriptlet, "post_install",
- alpm_pkg_get_version(newpkg), NULL, trans);
+ _alpm_runscriptlet(newpkg->handle, scriptlet, "post_install",
+ alpm_pkg_get_version(newpkg), NULL);
}
}
@@ -705,22 +693,18 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
cleanup:
_alpm_pkg_free(oldpkg);
- return(ret);
+ return ret;
}
-int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
+int _alpm_upgrade_packages(pmhandle_t *handle)
{
size_t pkg_count, pkg_current;
int skip_ldconfig = 0, ret = 0;
alpm_list_t *targ;
-
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ pmtrans_t *trans = handle->trans;
if(trans->add == NULL) {
- return(0);
+ return 0;
}
pkg_count = alpm_list_count(trans->add);
@@ -729,11 +713,11 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
/* loop through our package list adding/upgrading one at a time */
for(targ = trans->add; targ; targ = targ->next) {
if(handle->trans->state == STATE_INTERRUPTED) {
- return(ret);
+ return ret;
}
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;
@@ -747,10 +731,10 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
if(!skip_ldconfig) {
/* run ldconfig if it exists */
- _alpm_ldconfig(handle->root);
+ _alpm_ldconfig(handle);
}
- return(ret);
+ return ret;
}
/* vim: set ts=2 sw=2 noet: */