Date: Monday, March 12, 2007 @ 00:47:58 Author: dan Path: /home/cvs-pacman/pacman-lib/lib/libalpm Modified: package.c (1.85 -> 1.86) trans.c (1.44 -> 1.45) * Fix an issue where the same dependency was recorded multiple times in the 'required by' field. -----------+ package.c | 27 ++++++++++++++++++--------- trans.c | 33 ++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 20 deletions(-) Index: pacman-lib/lib/libalpm/package.c diff -u pacman-lib/lib/libalpm/package.c:1.85 pacman-lib/lib/libalpm/package.c:1.86 --- pacman-lib/lib/libalpm/package.c:1.85 Wed Mar 7 02:45:30 2007 +++ pacman-lib/lib/libalpm/package.c Mon Mar 12 00:47:58 2007 @@ -540,6 +540,7 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg) { alpm_list_t *i, *j, *k; + const char *pkgname = alpm_pkg_get_name(pkg); pmdb_t *localdb = alpm_option_get_localdb(); for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) { @@ -547,6 +548,8 @@ continue; } pmpkg_t *cachepkg = i->data; + const char *cachepkgname = alpm_pkg_get_name(cachepkg); + for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) { pmdepend_t *dep; if(!j->data) { @@ -558,23 +561,29 @@ } /* check the actual package itself */ - if(strcmp(dep->name, alpm_pkg_get_name(pkg)) == 0) { - _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"), - cachepkg->name, pkg->name); + if(strcmp(dep->name, pkgname) == 0) { alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg); - reqs = alpm_list_add(reqs, strdup(alpm_pkg_get_name(cachepkg))); - pkg->requiredby = reqs; + + if(!alpm_list_find_str(reqs, cachepkgname)) { + _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"), + cachepkgname, pkg->name); + reqs = alpm_list_add(reqs, strdup(cachepkgname)); + pkg->requiredby = reqs; + } } /* check for provisions as well */ for(k = alpm_pkg_get_provides(pkg); k; k = k->next) { const char *provname = k->data; if(strcmp(dep->name, provname) == 0) { - _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s' (provides: %s)"), - alpm_pkg_get_name(cachepkg), alpm_pkg_get_name(pkg), provname); alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg); - reqs = alpm_list_add(reqs, strdup(alpm_pkg_get_name(cachepkg))); - pkg->requiredby = reqs; + + if(!alpm_list_find_str(reqs, cachepkgname)) { + _alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s' (provides: %s)"), + cachepkgname, pkgname, provname); + reqs = alpm_list_add(reqs, strdup(cachepkgname)); + pkg->requiredby = reqs; + } } } free(dep); Index: pacman-lib/lib/libalpm/trans.c diff -u pacman-lib/lib/libalpm/trans.c:1.44 pacman-lib/lib/libalpm/trans.c:1.45 --- pacman-lib/lib/libalpm/trans.c:1.44 Wed Mar 7 02:45:30 2007 +++ pacman-lib/lib/libalpm/trans.c Mon Mar 12 00:47:58 2007 @@ -254,6 +254,7 @@ { alpm_list_t *i, *j; alpm_list_t *depends = NULL; + const char *pkgname; pmdb_t *localdb; ALPM_LOG_FUNC; @@ -262,10 +263,12 @@ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1)); + pkgname = alpm_pkg_get_name(pkg); depends = alpm_pkg_get_depends(pkg); + if(depends) { _alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields for %s-%s"), - pkg->name, pkg->version); + pkgname, pkg->version); } else { _alpm_log(PM_LOG_DEBUG, _("package has no dependencies, no other packages to update")); } @@ -302,16 +305,20 @@ found_provides = 1; /* this is cheating... we call this function to populate the package */ - alpm_pkg_get_requiredby(deppkg); + alpm_list_t *rqdby = alpm_pkg_get_requiredby(deppkg); - _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), alpm_pkg_get_name(deppkg)); + _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), + alpm_pkg_get_name(deppkg)); if(trans->type == PM_TRANS_TYPE_REMOVE) { void *data = NULL; - deppkg->requiredby = alpm_list_remove(deppkg->requiredby, - alpm_pkg_get_name(pkg), _alpm_str_cmp, &data); + rqdby = alpm_list_remove(rqdby, pkgname, _alpm_str_cmp, &data); FREE(data); + deppkg->requiredby = rqdby; } else { - deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(alpm_pkg_get_name(pkg))); + if(!alpm_list_find_str(rqdby, pkgname)) { + rqdby = alpm_list_add(rqdby, strdup(pkgname)); + deppkg->requiredby = rqdby; + } } if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) { @@ -328,16 +335,20 @@ } /* this is cheating... we call this function to populate the package */ - alpm_pkg_get_requiredby(deppkg); + alpm_list_t *rqdby = alpm_pkg_get_requiredby(deppkg); - _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name); + _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), + alpm_pkg_get_name(deppkg)); if(trans->type == PM_TRANS_TYPE_REMOVE) { void *data = NULL; - deppkg->requiredby = alpm_list_remove(deppkg->requiredby, - alpm_pkg_get_name(pkg), _alpm_str_cmp, &data); + rqdby = alpm_list_remove(rqdby, pkgname, _alpm_str_cmp, &data); FREE(data); + deppkg->requiredby = rqdby; } else { - deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(alpm_pkg_get_name(pkg))); + if(!alpm_list_find_str(rqdby, pkgname)) { + rqdby = alpm_list_add(rqdby, strdup(pkgname)); + deppkg->requiredby = rqdby; + } } if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {