summaryrefslogtreecommitdiffstats
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-02-18 23:07:11 +0100
committerAaron Griffin <aaron@archlinux.org>2007-02-18 23:07:11 +0100
commit119b3ab0437d83a483d46e43ce3e330b49f05096 (patch)
treefd64a9f9bd10d58e3a9dbfed1605c698da51cffe /lib/libalpm
parent7b4e2cd25d20e331b66c5163e0d43fe7acd2a420 (diff)
downloadpacman-119b3ab0437d83a483d46e43ce3e330b49f05096.tar.gz
pacman-119b3ab0437d83a483d46e43ce3e330b49f05096.tar.xz
Moved the update_depends function to trans.c, as it depends on a transaction
object
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/add.c3
-rw-r--r--lib/libalpm/package.c87
-rw-r--r--lib/libalpm/package.h1
-rw-r--r--lib/libalpm/remove.c2
-rw-r--r--lib/libalpm/trans.c93
-rw-r--r--lib/libalpm/trans.h1
6 files changed, 96 insertions, 91 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index ac53ace9..b503323b 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -790,7 +790,6 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
* looking for packages depending on the package to add */
_alpm_pkg_update_requiredby(newpkg);
-
/* make an install date (in UTC) */
time_t t = time(NULL);
strncpy(newpkg->installdate, asctime(gmtime(&t)), PKG_DATE_LEN);
@@ -813,7 +812,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
}
/* update dependency packages' REQUIREDBY fields */
- _alpm_pkg_update_depends(newpkg, 0 /*is an add*/);
+ _alpm_trans_update_depends(trans, newpkg);
PROGRESS(trans, (is_upgrade ? PM_TRANS_PROGRESS_UPGRADE_START : PM_TRANS_PROGRESS_ADD_START),
newpkg->name, 100, pkg_count, (pkg_count - targ_count +1));
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index c921e3e4..93e3aa9c 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -551,93 +551,6 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg)
}
}
-void _alpm_pkg_update_depends(pmpkg_t *pkg, int remove)
-{
- alpm_list_t *i, *j;
- if(pkg->depends) {
- _alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields"));
- }
-
- pmdb_t *localdb = alpm_option_get_localdb();
- for(i = pkg->depends; i; i = i->next) {
- pmdepend_t dep;
- if(_alpm_splitdep(i->data, &dep) != 0) {
- continue;
- }
-
- /* XXX: this is a hack...if this dependency is in the transaction targets
- * of a remove transaction no need to update its requiredby info:
- * it is in the process of being removed (if not already done!) */
- /* TODO I wonder if we can just skip this, the few extra operations won't be
- * a huge deal either way */
- if(handle->trans && handle->trans->packages
- && handle->trans->type == PM_TRANS_TYPE_REMOVE) {
- if(_alpm_pkg_isin(dep.name, handle->trans->packages)) {
- continue;
- }
- }
-
- pmpkg_t *deppkg = _alpm_db_get_pkgfromcache(localdb, dep.name);
- if(!deppkg) {
- int found_provides = 0;
- /* look for a provides package */
- alpm_list_t *provides = _alpm_db_whatprovides(localdb, dep.name);
- for(j = provides; j; j = j->next) {
- if(!j->data) {
- continue;
- }
- pmpkg_t *provpkg = j->data;
- deppkg = _alpm_db_get_pkgfromcache(localdb, provpkg->name);
-
- if(!deppkg) {
- continue;
- }
-
- found_provides = 1;
-
- /* Ensure package has the right newpkg */
- _alpm_db_read(localdb, INFRQ_DEPENDS, deppkg);
-
- _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
- if(remove) {
- void *data = NULL;
- deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
- FREE(data);
- } else {
- deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
- }
-
- if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
- }
- }
- FREELISTPTR(provides);
-
- if(!found_provides) {
- _alpm_log(PM_LOG_DEBUG, _("could not find dependency '%s'"), dep.name);
- continue;
- }
- }
-
- /* Ensure package has the right newpkg */
- _alpm_db_read(localdb, INFRQ_DEPENDS, deppkg);
-
- _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
- if(remove) {
- void *data = NULL;
- deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
- FREE(data);
- } else {
- deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
- }
-
- if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
- }
- }
-
-}
-
const char *alpm_pkg_get_filename(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 98b8c992..6ef8a8a6 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -108,7 +108,6 @@ pmpkg_t *_alpm_pkg_isin(char *needle, alpm_list_t *haystack);
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
int _alpm_pkg_istoonew(pmpkg_t *pkg);
void _alpm_pkg_update_requiredby(pmpkg_t *pkg);
-void _alpm_pkg_update_depends(pmpkg_t *pkg, int remove);
#endif /* _ALPM_PACKAGE_H */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 64f0025e..e964df16 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -335,7 +335,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
}
/* update dependency packages' REQUIREDBY fields */
- _alpm_pkg_update_depends(info, 1 /*is a remove*/);
+ _alpm_trans_update_depends(trans, info);
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 100, alpm_list_count(trans->packages), (alpm_list_count(trans->packages) - alpm_list_count(targ) +1));
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 12035408..4969214f 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -38,6 +38,9 @@
#include "remove.h"
#include "sync.h"
#include "alpm.h"
+#include "deps.h"
+#include "cache.h"
+#include "provide.h"
pmtrans_t *_alpm_trans_new()
{
@@ -242,6 +245,96 @@ int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data)
return(0);
}
+int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
+{
+ alpm_list_t *i, *j;
+ pmdb_t *localdb;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
+
+ if(pkg->depends) {
+ _alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields"));
+ }
+
+ localdb = alpm_option_get_localdb();
+ for(i = pkg->depends; i; i = i->next) {
+ pmdepend_t dep;
+ if(_alpm_splitdep(i->data, &dep) != 0) {
+ continue;
+ }
+
+ if(trans->packages && trans->type == PM_TRANS_TYPE_REMOVE) {
+ if(_alpm_pkg_isin(dep.name, handle->trans->packages)) {
+ continue;
+ }
+ }
+
+ pmpkg_t *deppkg = _alpm_db_get_pkgfromcache(localdb, dep.name);
+ if(!deppkg) {
+ int found_provides = 0;
+ /* look for a provides package */
+ alpm_list_t *provides = _alpm_db_whatprovides(localdb, dep.name);
+ for(j = provides; j; j = j->next) {
+ if(!j->data) {
+ continue;
+ }
+ pmpkg_t *provpkg = j->data;
+ deppkg = _alpm_db_get_pkgfromcache(localdb, provpkg->name);
+
+ if(!deppkg) {
+ continue;
+ }
+
+ found_provides = 1;
+
+ /* Ensure package has the right newpkg */
+ _alpm_db_read(localdb, INFRQ_DEPENDS, deppkg);
+
+ _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
+ if(trans->type == PM_TRANS_TYPE_REMOVE) {
+ void *data = NULL;
+ deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
+ FREE(data);
+ } else {
+ deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
+ }
+
+ if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
+ _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
+ }
+ }
+ FREELISTPTR(provides);
+
+ if(!found_provides) {
+ _alpm_log(PM_LOG_DEBUG, _("could not find dependency '%s'"), dep.name);
+ continue;
+ }
+ }
+
+ /* Ensure package has the right newpkg */
+ _alpm_db_read(localdb, INFRQ_DEPENDS, deppkg);
+
+ _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
+ if(trans->type == PM_TRANS_TYPE_REMOVE) {
+ void *data = NULL;
+ deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
+ FREE(data);
+ } else {
+ deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
+ }
+
+ if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
+ _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
+ }
+ }
+ return(0);
+}
+
+
pmtranstype_t alpm_trans_get_type()
{
/* Sanity checks */
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 8d5c6362..f0fe1e57 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -84,6 +84,7 @@ int _alpm_trans_sysupgrade(pmtrans_t *trans);
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data);
int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data);
+int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg);
#endif /* _ALPM_TRANS_H */