diff options
author | Nagy Gabor <ngaba@bibl.u-szeged.hu> | 2008-03-11 16:40:27 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-03-23 16:57:14 -0500 |
commit | d1ea16dfd0d497aff72d7a315890971e7f070786 (patch) | |
tree | 43734360565de9857431a0a66b31a1a358601e6e /lib/libalpm | |
parent | 6104f2e1fb872c32d3e6ed1823729592fc6245b9 (diff) | |
download | pacman-d1ea16dfd0d497aff72d7a315890971e7f070786.tar.xz |
Avoid duplicated target names.
This patch should avoid duplicated target names in the backend.
1. sync_loadtarget will return with PM_ERR_TRANS_DUP_TARGET when trying to
add a duplicated target
2. sysupgrade never pulls duplicated targets
3. resolvedeps won't pull duplicated targets anymore
A pulled list was introduced in sync_prepare to improve the
pmsyncpkg_t<->pmpkg_t list conversion by making it more direct.
Also replace sync1005 and sync1006 by the sync1008 pactest, which is
similar but more interesting (the provisions are dependencies instead of
explicit targets).
sync1005 didn't work as expected anyway. It was expecting that pacman
failed, and pacman indeed failed, but not for the good reason. It didn't
fail during the preparation step because of conflicting targets, but during
the commit step, because of a md5 error...
And sync1006 didn't pass and was not really worth fixing. We have already
enough failing pactests more important than these two.
sync1008 pass with this patch.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/deps.c | 6 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 45 |
2 files changed, 29 insertions, 22 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 180c46bf..1eebca3e 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -570,7 +570,8 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, if(!sync) { continue; } - found = alpm_depcmp(sync, missdep) && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove); + found = alpm_depcmp(sync, missdep) && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove) + && !_alpm_pkg_find(alpm_pkg_get_name(sync), *list); if(!found) { continue; } @@ -592,7 +593,8 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg, continue; } found = alpm_depcmp(sync, missdep) && strcmp(sync->name, missdep->name) - && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove); + && !_alpm_pkg_find(alpm_pkg_get_name(sync), remove) + && !_alpm_pkg_find(alpm_pkg_get_name(sync), *list); if(!found) { continue; } diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 9df59431..5b3087a3 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -128,6 +128,7 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, pmsyncpkg_t *sync; /* check if spkg->name is already in the packages list. */ + /* TODO: same package name doesn't mean same package */ sync = _alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg)); if(sync) { /* found it -- just append to the removes list */ @@ -246,7 +247,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, /* add the upgrade package to our pmsyncpkg_t list */ if(_alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg))) { - /* it is already there, done */ + /* avoid duplicated targets */ continue; } /* we can set any reason here, it will be overridden by add_commit */ @@ -317,6 +318,11 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy } } + 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); @@ -343,15 +349,13 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy } /* add the package to the transaction */ - if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL); - if(sync == NULL) { - goto error; - } - _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); + sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL); + if(sync == NULL) { + goto error; } + _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); @@ -399,6 +403,9 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync } if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { + /* store a pointer to the last original target so we can tell what was + * pulled by resolvedeps */ + alpm_list_t *pulled = alpm_list_last(list); /* Resolve targets dependencies */ EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL); _alpm_log(PM_LOG_DEBUG, "resolving target's dependencies\n"); @@ -421,19 +428,16 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync } } - for(i = list; i; i = i->next) { - /* add the dependencies found by resolvedeps to the transaction set */ + for(i = pulled->next; i; i = i->next) { pmpkg_t *spkg = i->data; - if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - pmsyncpkg_t *sync = _alpm_sync_new(PM_PKG_REASON_DEPEND, spkg, NULL); - if(sync == NULL) { - ret = -1; - goto cleanup; - } - trans->packages = alpm_list_add(trans->packages, sync); - _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n", - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + pmsyncpkg_t *sync = _alpm_sync_new(PM_PKG_REASON_DEPEND, spkg, NULL); + if(sync == NULL) { + ret = -1; + goto cleanup; } + trans->packages = alpm_list_add(trans->packages, sync); + _alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n", + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } /* re-order w.r.t. dependencies */ @@ -444,6 +448,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync pmsyncpkg_t *s = j->data; if(s->pkg == i->data) { newpkgs = alpm_list_add(newpkgs, s); + break; } } } |