diff options
author | Xavier Chantry <chantry.xavier@gmail.com> | 2010-10-17 00:57:37 +0200 |
---|---|---|
committer | Xavier Chantry <chantry.xavier@gmail.com> | 2011-01-29 19:33:15 +0100 |
commit | fb7e1b4b9bf7d2dbcd89a4832067d89a03d71056 (patch) | |
tree | b8ba767e44dc57b5b7e025697fd9a560e5c6a526 /lib | |
parent | b8590ed634babc060b35e2ad7a035347234d836a (diff) | |
download | pacman-fb7e1b4b9bf7d2dbcd89a4832067d89a03d71056.tar.gz pacman-fb7e1b4b9bf7d2dbcd89a4832067d89a03d71056.tar.xz |
alpm: new alpm_add_pkg interface
This new function is meant to deprecate all existing
sync/add target functions :
int alpm_sync_target(char *target);
int alpm_sync_dbtarget(char *db, char *target);
int alpm_add_target(char *target);
Rather than dropping these 3 interfaces, it might be better to rewrite
them using alpm_add_pkg for now.
Signed-off-by: Xavier Chantry <chantry.xavier@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/add.c | 64 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 2 |
2 files changed, 66 insertions, 0 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index d4c56def..a1216d9b 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -49,6 +49,70 @@ #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) + */ +int SYMEXPORT alpm_add_pkg(pmpkg_t *pkg) +{ + const char *pkgname, *pkgver; + pmtrans_t *trans; + pmdb_t *db_local; + pmpkg_t *local; + + ALPM_LOG_FUNC; + + /* Sanity checks */ + ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); + ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + 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(PM_ERR_TRANS_NULL, -1)); + db_local = handle->db_local; + + pkgname = alpm_pkg_get_name(pkg); + pkgver = alpm_pkg_get_version(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); + } + + local = _alpm_db_get_pkgfromcache(db_local, pkgname); + if(local) { + const char *localpkgname = alpm_pkg_get_name(local); + const char *localpkgver = alpm_pkg_get_version(local); + int cmp = _alpm_pkg_compare_versions(pkg, local); + + 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"), + localpkgname, localpkgver); + return(0); + } else { + _alpm_log(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"), + 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 targets\n", + pkgname, pkgver); + trans->add = alpm_list_add(trans->add, pkg); + + return(0); +} + + /** Add a file target to the transaction. * @param target the name of the file target to add * @return 0 on success, -1 on error (pm_errno is set accordingly) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e33aab24..2f52f075 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -423,6 +423,8 @@ int alpm_sync_dbtarget(const char *db, const char *target); int alpm_add_target(const char *target); int alpm_remove_target(const char *target); +int alpm_add_pkg(pmpkg_t *pkg); + /* * Dependencies and conflicts */ |