[pacman-dev] [PATCH] sync_addtarget rework
From 6541daa508b3f4d050db61f7212fcedf45ab0120 Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sat, 5 Jul 2008 12:53:55 +0200 Subject: [PATCH] sync_addtarget rework Now '-S provision' handling is done in the back-end. In case of multiple providers, the first one is selected (behavior change: deleted provision002.py). The old processing order was: literal, group, provision; the new one: literal, provision, group; this is more rational, but "pacman -S group" will be slower now. Now "pacman -S repo/provision" also works. Provision was generalized to dependencies, so "pacman -S 'bash>2.0'" or "pacman -S 'core/bash>2.0'" also works; this can be useful in makepkg dependency resolving. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 19 +++++++++-- lib/libalpm/sync.c | 68 +++++++++++++++-------------------------- pactest/tests/provision002.py | 15 --------- src/pacman/sync.c | 38 ++--------------------- 4 files changed, 43 insertions(+), 97 deletions(-) delete mode 100644 pactest/tests/provision002.py diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1a6da96..e042166 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -544,8 +544,14 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs, alpm_list_t *exclud if(pkg && alpm_depcmp(pkg, dep) && !_alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(pkg)) { int install; - QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, - pkg, NULL, &install); + /* wow, we have a very stupid callback API here */ + if(tpkg) { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, + pkg, NULL, &install); + } else { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, + NULL, NULL, &install); + } if(!install) { continue; } @@ -561,8 +567,13 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs, alpm_list_t *exclud !_alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(pkg)) { int install; - QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, - pkg, NULL, &install); + if(tpkg) { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, + pkg, NULL, &install); + } else { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, + NULL, NULL, &install); + } if(!install) { continue; } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 9336a2e..74fb7b1 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -272,65 +272,54 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy char *targline; char *targ; alpm_list_t *j; - pmpkg_t *local; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - int repo_found = 0; + pmpkg_t *local, *spkg; + pmdepend_t *dep; /* provisions and dependencies are also allowed */ ALPM_LOG_FUNC; ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - STRDUP(targline, name, RET_ERR(PM_ERR_MEMORY, -1)); + STRDUP(targline, name, RET_ERR(PM_ERR_MEMORY, -1)); targ = strchr(targline, '/'); if(targ) { /* we are looking for a package in a specific database */ + alpm_list_t *dbs = NULL; *targ = '\0'; targ++; - _alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo\n", targ); - for(j = dbs_sync; j && !spkg; j = j->next) { + _alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo '%s'\n", targ, targline); + for(j = dbs_sync; j; j = j->next) { pmdb_t *db = j->data; if(strcmp(db->treename, targline) == 0) { - repo_found = 1; - spkg = _alpm_db_get_pkgfromcache(db, targ); - if(spkg == NULL) { - pm_errno = PM_ERR_PKG_NOT_FOUND; - goto error; - } + dbs = alpm_list_add(NULL, db); + break; } } - if(!repo_found) { + if(dbs == NULL) { _alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), targline); - pm_errno = PM_ERR_PKG_REPO_NOT_FOUND; - goto error; + FREE(targline); + RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1); } + dep = _alpm_splitdep(targ); + spkg = _alpm_resolvedep(dep, dbs, NULL, NULL); + _alpm_dep_free(dep); + alpm_list_free(dbs); } else { - targ = targline; - for(j = dbs_sync; j && !spkg; j = j->next) { - pmdb_t *db = j->data; - spkg = _alpm_db_get_pkgfromcache(db, targ); - } - if(spkg == NULL) { - pm_errno = PM_ERR_PKG_NOT_FOUND; - goto error; - } + dep = _alpm_splitdep(targline); + spkg = _alpm_resolvedep(dep, dbs_sync, NULL, NULL); + _alpm_dep_free(dep); } + FREE(targline); + if(spkg == NULL) { + RET_ERR(PM_ERR_PKG_NOT_FOUND, -1); + } + if(_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - FREE(targline); RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1); } - if(_alpm_pkg_should_ignore(spkg)) { - int resp; - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, spkg, NULL, NULL, &resp); - if (!resp) { - return(0); - } - } - local = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(spkg)); if(local) { if(_alpm_pkg_compare_versions(local, spkg) == 0) { @@ -349,22 +338,15 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy } /* add the package to the transaction */ - sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL); + pmsyncpkg_t *sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL); if(sync == NULL) { - goto error; + return(-1); } _alpm_log(PM_LOG_DEBUG, "adding target '%s' to the transaction set\n", alpm_pkg_get_name(spkg)); trans->packages = alpm_list_add(trans->packages, sync); - FREE(targline); return(0); - -error: - if(targline) { - FREE(targline); - } - return(-1); } /* Helper functions for alpm_list_remove diff --git a/pactest/tests/provision002.py b/pactest/tests/provision002.py deleted file mode 100644 index 32bc4b8..0000000 --- a/pactest/tests/provision002.py +++ /dev/null @@ -1,15 +0,0 @@ -self.description = "-S provision" - -sp = pmpkg("pkg1") -sp.provides = ["provision=1.0-1"] -self.addpkg2db("sync", sp) - -sp = pmpkg("pkg2") -sp.provides = ["provision=1.0-1"] -self.addpkg2db("sync", sp) - -self.args = "-S provision" - -self.addrule("PACMAN_RETCODE=1") -self.addrule("!PKG_EXIST=pkg1") -self.addrule("!PKG_EXIST=pkg2") diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 47ab4eb..6877d85 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -617,41 +617,9 @@ static int sync_trans(alpm_list_t *targets) } } if(!found) { - /* targ not found in sync db, searching for providers... */ - alpm_list_t *prov = NULL; - for(j = sync_dbs; j; j = alpm_list_next(j)) { - pmdb_t *db = alpm_list_getdata(j); - alpm_list_t *dblist = alpm_db_getpkgcache(db); - alpm_list_t *satisfiers = alpm_find_pkg_satisfiers(dblist, targ); - prov = alpm_list_join(prov, satisfiers); - } - if(prov != NULL) { - if(alpm_list_count(prov) == 1) { - const char *pname = NULL; - pmpkg_t *pkg = alpm_list_getdata(prov); - pname = alpm_pkg_get_name(pkg); - alpm_list_free(prov); - printf(_("Warning: %s provides %s\n"), pname, targ); - targets = alpm_list_add(targets, strdup(pname)); - } else { - alpm_list_t *k; - pm_fprintf(stderr, PM_LOG_ERROR, - _("several packages provide %s, please specify one :\n"), targ); - for(k = prov; k; k = alpm_list_next(k)) { - pmpkg_t *pkg = alpm_list_getdata(k); - printf("%s ", alpm_pkg_get_name(pkg)); - } - printf("\n"); - alpm_list_free(prov); - retval = 1; - goto cleanup; - } - } else { - pm_fprintf(stderr, PM_LOG_ERROR, - _("'%s': not found in sync db\n"), targ); - retval = 1; - goto cleanup; - } + pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in sync db\n"), targ); + retval = 1; + goto cleanup; } } } -- 1.5.6.1
Nagy Gabor wrote:
From 6541daa508b3f4d050db61f7212fcedf45ab0120 Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sat, 5 Jul 2008 12:53:55 +0200 Subject: [PATCH] sync_addtarget rework
Now '-S provision' handling is done in the back-end. In case of multiple providers, the first one is selected (behavior change: deleted provision002.py). The old processing order was: literal, group, provision; the new one: literal, provision, group; this is more rational, but "pacman -S group" will be slower now. Now "pacman -S repo/provision" also works. Provision was generalized to dependencies, so "pacman -S 'bash>2.0'" or "pacman -S 'core/bash>2.0'" also works; this can be useful in makepkg dependency resolving.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> --- lib/libalpm/deps.c | 19 +++++++++-- lib/libalpm/sync.c | 68 +++++++++++++++-------------------------- pactest/tests/provision002.py | 15 --------- src/pacman/sync.c | 38 ++--------------------- 4 files changed, 43 insertions(+), 97 deletions(-) delete mode 100644 pactest/tests/provision002.py
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 1a6da96..e042166 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -544,8 +544,14 @@ pmpkg_t *_alpm_resolvedep(pmdepend_t *dep, alpm_list_t *dbs, alpm_list_t *exclud if(pkg && alpm_depcmp(pkg, dep) && !_alpm_pkg_find(excluding, pkg->name)) { if(_alpm_pkg_should_ignore(pkg)) { int install; - QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, - pkg, NULL, &install); + /* wow, we have a very stupid callback API here */ + if(tpkg) { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, tpkg, + pkg, NULL, &install); + } else { + QUESTION(handle->trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, pkg, + NULL, NULL, &install); + } if(!install) { continue; }
I already discussed this with Nagy on irc, but just a quick comment here for others : this part doesn't seem to fit well here, and could also be handled more nicely by simply using a smarter order of the optional data parameters (pkg,tpkg and pkg,NULL instead of tpkg,pkg and pkg,NULL).
On Sat, Jul 5, 2008 at 5:59 AM, Nagy Gabor <ngaba@bibl.u-szeged.hu> wrote:
From 6541daa508b3f4d050db61f7212fcedf45ab0120 Mon Sep 17 00:00:00 2001 From: Nagy Gabor <ngaba@bibl.u-szeged.hu> Date: Sat, 5 Jul 2008 12:53:55 +0200 Subject: [PATCH] sync_addtarget rework
Now '-S provision' handling is done in the back-end. In case of multiple providers, the first one is selected (behavior change: deleted provision002.py). The old processing order was: literal, group, provision; the new one: literal, provision, group; this is more rational, but "pacman -S group" will be slower now. Now "pacman -S repo/provision" also works. Provision was generalized to dependencies, so "pacman -S 'bash>2.0'" or "pacman -S 'core/bash>2.0'" also works; this can be useful in makepkg dependency resolving.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> ---
Just the printf() -> pm_printf() issue here again, and wrapping the commit message at 76 chars would be great. -Dan
participants (3)
-
Dan McGee
-
Nagy Gabor
-
Xavier