Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=a71a0334b81c458e513808ea020f422d2c13bac4
commit a71a0334b81c458e513808ea020f422d2c13bac4 Author: Michel Hermier <[email protected]> Date: Thu May 15 08:43:37 2014 +0200 libpacman: Merge _pacman_remove_commit in Package::commit. diff --git a/lib/libpacman/trans.cpp b/lib/libpacman/trans.cpp index 0c74c33..235b450 100644 --- a/lib/libpacman/trans.cpp +++ b/lib/libpacman/trans.cpp @@ -1737,121 +1737,6 @@ static int str_cmp(const void *s1, const void *s2) return(strcmp(s1, s2)); } -static -int _pacman_remove_commit(pmtrans_t *trans, pmlist_t **data) -{ - Package *pkg_local; - pmlist_t *targ, *lp; - int howmany, remain; - Database *db_local = trans->handle->db_local; - - ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); - - howmany = _pacman_list_count(trans->packages); - - for(targ = trans->packages; targ; targ = targ->next) { - char pm_install[PATH_MAX]; - pkg_local = (Package*)targ->data; - - if(handle->trans->state == STATE_INTERRUPTED) { - break; - } - - remain = _pacman_list_count(targ); - - if(trans->type != PM_TRANS_TYPE_UPGRADE) { - EVENT(trans, PM_TRANS_EVT_REMOVE_START, pkg_local, NULL); - _pacman_log(PM_LOG_FLOW1, _("removing package %s-%s"), pkg_local->name(), pkg_local->version()); - - /* run the pre-remove scriptlet if it exists */ - if(pkg_local->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { - snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db_local->path, pkg_local->name(), pkg_local->version()); - _pacman_runscriptlet(handle->root, pm_install, "pre_remove", pkg_local->version(), NULL, trans); - } - } - - if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) { - _pacman_localpackage_remove(pkg_local, trans, howmany, remain); - } - - PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkg_local->name(), 100, howmany, howmany - remain + 1); - if(trans->type != PM_TRANS_TYPE_UPGRADE) { - /* run the post-remove script if it exists */ - if(pkg_local->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { - /* must run ldconfig here because some scriptlets fail due to missing libs otherwise */ - _pacman_ldconfig(handle->root); - snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db_local->path, pkg_local->name(), pkg_local->version()); - _pacman_runscriptlet(handle->root, pm_install, "post_remove", pkg_local->version(), NULL, trans); - } - } - - /* remove the package from the database */ - _pacman_log(PM_LOG_FLOW1, _("updating database")); - _pacman_log(PM_LOG_FLOW2, _("removing database entry '%s'"), pkg_local->name()); - if(pkg_local->remove() == -1) { - _pacman_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"), pkg_local->name(), pkg_local->version()); - } - if(_pacman_db_remove_pkgfromcache(db_local, pkg_local) == -1) { - _pacman_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"), pkg_local->name()); - } - - /* update dependency packages' REQUIREDBY fields */ - _pacman_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); - for(lp = pkg_local->depends(); lp; lp = lp->next) { - Package *depinfo = NULL; - pmdepend_t depend; - char *data; - if(_pacman_splitdep((char*)lp->data, &depend)) { - continue; - } - /* if this dependency is in the transaction targets, no need to update - * its requiredby info: it is in the process of being removed (if not - * already done!) - */ - if(_pacman_pkg_isin(depend.name, trans->packages)) { - continue; - } - depinfo = _pacman_db_get_pkgfromcache(db_local, depend.name); - if(depinfo == NULL) { - /* look for a provides package */ - pmlist_t *provides = _pacman_db_whatprovides(db_local, depend.name); - if(provides) { - /* TODO: should check _all_ packages listed in provides, not just - * the first one. - */ - /* use the first one */ - depinfo = _pacman_db_get_pkgfromcache(db_local, ((Package *)provides->data)->name()); - FREELISTPTR(provides); - } - if(depinfo == NULL) { - _pacman_log(PM_LOG_ERROR, _("could not find dependency '%s'"), depend.name); - /* wtf */ - continue; - } - } - /* splice out this entry from requiredby */ - depinfo->m_requiredby = _pacman_list_remove(depinfo->requiredby(), pkg_local->name(), str_cmp, (void **)&data); - FREE(data); - _pacman_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), depinfo->name()); - if(db_local->write(depinfo, INFRQ_DEPENDS)) { - _pacman_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), - depinfo->name(), depinfo->version()); - } - } - - if(trans->type != PM_TRANS_TYPE_UPGRADE) { - EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, pkg_local, NULL); - } - } - - /* run ldconfig if it exists */ - if((trans->type != PM_TRANS_TYPE_UPGRADE) && (handle->trans->state != STATE_INTERRUPTED)) { - _pacman_ldconfig(handle->root); - } - - return(0); -} - static const struct trans_event_table_item { struct { @@ -2089,9 +1974,114 @@ int __pmtrans_t::commit(pmtranstype_t type, pmlist_t **data) // return(ret); } if(type == PM_TRANS_TYPE_REMOVE) { - if(_pacman_remove_commit(this, data) == -1) { - return -1; + Package *pkg_local; + pmlist_t *targ, *lp; + int howmany, remain; + Database *db_local = handle->db_local; + + ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); + + howmany = _pacman_list_count(packages); + + for(targ = packages; targ; targ = targ->next) { + char pm_install[PATH_MAX]; + pkg_local = (Package*)targ->data; + + if(handle->trans->state == STATE_INTERRUPTED) { + break; + } + + remain = _pacman_list_count(targ); + + if(this->type != PM_TRANS_TYPE_UPGRADE) { + EVENT(this, PM_TRANS_EVT_REMOVE_START, pkg_local, NULL); + _pacman_log(PM_LOG_FLOW1, _("removing package %s-%s"), pkg_local->name(), pkg_local->version()); + + /* run the pre-remove scriptlet if it exists */ + if(pkg_local->scriptlet && !(flags & PM_TRANS_FLAG_NOSCRIPTLET)) { + snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db_local->path, pkg_local->name(), pkg_local->version()); + _pacman_runscriptlet(handle->root, pm_install, "pre_remove", pkg_local->version(), NULL, this); + } + } + + if(!(flags & PM_TRANS_FLAG_DBONLY)) { + _pacman_localpackage_remove(pkg_local, this, howmany, remain); + } + + PROGRESS(this, PM_TRANS_PROGRESS_REMOVE_START, pkg_local->name(), 100, howmany, howmany - remain + 1); + if(this->type != PM_TRANS_TYPE_UPGRADE) { + /* run the post-remove script if it exists */ + if(pkg_local->scriptlet && !(flags & PM_TRANS_FLAG_NOSCRIPTLET)) { + /* must run ldconfig here because some scriptlets fail due to missing libs otherwise */ + _pacman_ldconfig(handle->root); + snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db_local->path, pkg_local->name(), pkg_local->version()); + _pacman_runscriptlet(handle->root, pm_install, "post_remove", pkg_local->version(), NULL, this); + } + } + + /* remove the package from the database */ + _pacman_log(PM_LOG_FLOW1, _("updating database")); + _pacman_log(PM_LOG_FLOW2, _("removing database entry '%s'"), pkg_local->name()); + if(pkg_local->remove() == -1) { + _pacman_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"), pkg_local->name(), pkg_local->version()); } + if(_pacman_db_remove_pkgfromcache(db_local, pkg_local) == -1) { + _pacman_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"), pkg_local->name()); + } + + /* update dependency packages' REQUIREDBY fields */ + _pacman_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); + for(lp = pkg_local->depends(); lp; lp = lp->next) { + Package *depinfo = NULL; + pmdepend_t depend; + char *data; + if(_pacman_splitdep((char*)lp->data, &depend)) { + continue; + } + /* if this dependency is in the transaction targets, no need to update + * its requiredby info: it is in the process of being removed (if not + * already done!) + */ + if(_pacman_pkg_isin(depend.name, packages)) { + continue; + } + depinfo = _pacman_db_get_pkgfromcache(db_local, depend.name); + if(depinfo == NULL) { + /* look for a provides package */ + pmlist_t *provides = _pacman_db_whatprovides(db_local, depend.name); + if(provides) { + /* TODO: should check _all_ packages listed in provides, not just + * the first one. + */ + /* use the first one */ + depinfo = _pacman_db_get_pkgfromcache(db_local, ((Package *)provides->data)->name()); + FREELISTPTR(provides); + } + if(depinfo == NULL) { + _pacman_log(PM_LOG_ERROR, _("could not find dependency '%s'"), depend.name); + /* wtf */ + continue; + } + } + /* splice out this entry from requiredby */ + depinfo->m_requiredby = _pacman_list_remove(depinfo->requiredby(), pkg_local->name(), str_cmp, (void **)&data); + FREE(data); + _pacman_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), depinfo->name()); + if(db_local->write(depinfo, INFRQ_DEPENDS)) { + _pacman_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), + depinfo->name(), depinfo->version()); + } + } + + if(this->type != PM_TRANS_TYPE_UPGRADE) { + EVENT(this, PM_TRANS_EVT_REMOVE_DONE, pkg_local, NULL); + } + } + + /* run ldconfig if it exists */ + if((this->type != PM_TRANS_TYPE_UPGRADE) && (handle->trans->state != STATE_INTERRUPTED)) { + _pacman_ldconfig(handle->root); + } } } _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
